@@ -19,7 +19,7 @@ import {
1919} from '../../types' ;
2020import { getBrokkrClient } from '../brokkr' ;
2121import { opportunityCreateParseSchema } from '../schema/opportunities' ;
22- import { markdown } from '../markdown' ;
22+ import { markdown , sanitizeHtml } from '../markdown' ;
2323import { OpportunityJob } from '../../entity/opportunities/OpportunityJob' ;
2424import { OpportunityLocation } from '../../entity/opportunities/OpportunityLocation' ;
2525import { 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