Skip to content

Commit 57fbf9b

Browse files
authored
fix: store HTML in content field when parsing opportunity with Brokkr (#3448)
1 parent 5420c2b commit 57fbf9b

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

__tests__/workers/opportunity/parseOpportunity.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,17 @@ describe('parseOpportunity worker', () => {
192192
// Verify content
193193
expect(opportunity!.content).toMatchObject({
194194
overview: {
195-
content: 'This is the overview of the mocked opportunity.',
195+
content: '<p>This is the overview of the mocked opportunity.</p>\n',
196196
html: '<p>This is the overview of the mocked opportunity.</p>\n',
197197
},
198198
responsibilities: {
199-
content: 'These are the responsibilities of the mocked opportunity.',
199+
content:
200+
'<p>These are the responsibilities of the mocked opportunity.</p>\n',
200201
html: '<p>These are the responsibilities of the mocked opportunity.</p>\n',
201202
},
202203
requirements: {
203-
content: 'These are the requirements of the mocked opportunity.',
204+
content:
205+
'<p>These are the requirements of the mocked opportunity.</p>\n',
204206
html: '<p>These are the requirements of the mocked opportunity.</p>\n',
205207
},
206208
});

src/common/opportunity/parse.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from '../../types';
2020
import { getBrokkrClient } from '../brokkr';
2121
import { opportunityCreateParseSchema } from '../schema/opportunities';
22-
import { markdown } from '../markdown';
22+
import { markdown, sanitizeHtml } from '../markdown';
2323
import { OpportunityJob } from '../../entity/opportunities/OpportunityJob';
2424
import { OpportunityLocation } from '../../entity/opportunities/OpportunityLocation';
2525
import { OpportunityKeyword } from '../../entity/OpportunityKeyword';
@@ -139,25 +139,29 @@ export async function validateOpportunityFileType(
139139

140140
/**
141141
* Renders markdown content for opportunity fields
142+
* Converts markdown to HTML and stores HTML in both content and html fields
142143
*/
143-
function renderOpportunityMarkdownContent(
144+
const renderOpportunityMarkdownContent = async (
144145
content: Record<string, { content?: string }> | undefined,
145-
): OpportunityContent {
146+
): Promise<OpportunityContent> => {
146147
const renderedContent: Record<string, { content: string; html: string }> = {};
147148

148-
Object.entries(content || {}).forEach(([key, value]) => {
149+
for (const [key, value] of Object.entries(content || {})) {
149150
if (typeof value?.content !== 'string') {
150-
return;
151+
continue;
151152
}
152153

154+
const html = markdown.render(value.content);
155+
const sanitizedHtml = await sanitizeHtml(html);
156+
153157
renderedContent[key] = {
154-
content: value.content,
155-
html: markdown.render(value.content),
158+
content: sanitizedHtml,
159+
html: sanitizedHtml,
156160
};
157-
});
161+
}
158162

159163
return new OpportunityContent(renderedContent);
160-
}
164+
};
161165

162166
/**
163167
* Parses an opportunity file using the Brokkr service
@@ -259,7 +263,9 @@ export async function parseOpportunityWithBrokkr({
259263
const parsedOpportunity =
260264
await opportunityCreateParseSchema.parseAsync(sanitizedOpportunity);
261265

262-
const content = renderOpportunityMarkdownContent(parsedOpportunity.content);
266+
const content = await renderOpportunityMarkdownContent(
267+
parsedOpportunity.content,
268+
);
263269

264270
return {
265271
opportunity: parsedOpportunity,

0 commit comments

Comments
 (0)