diff --git a/packages/hydrooj/src/lib/content.ts b/packages/hydrooj/src/lib/content.ts index f09d94b95..3337be70d 100644 --- a/packages/hydrooj/src/lib/content.ts +++ b/packages/hydrooj/src/lib/content.ts @@ -15,15 +15,15 @@ export function buildContent(source: ProblemSource, type: 'markdown' | 'html' = // required by upgrade 90_91 if (source instanceof Array) { return type === 'html' - ? source.map((node) => [ + ? source.flatMap((node) => [ node.type !== 'Plain' ? `

${node.sectionTitle}

` : '', node.type === 'Sample' ? `
${node.payload[0]}
` + `
${node.payload[1]}
` : '', node.text, - ].join('\n')).join('\n') - : source.map((node) => [ + ]).join('\n') + : source.flatMap((node) => [ node.type !== 'Plain' && (node.type !== 'Sample' || !cnt) ? `## ${node.sectionTitle}` : '', ...node.type === 'Sample' ? [ @@ -41,7 +41,7 @@ export function buildContent(source: ProblemSource, type: 'markdown' | 'html' = '', node.text, '', - ].join('\n')).join('\n'); + ]).join('\n'); } return type === 'html' ? [ @@ -60,9 +60,9 @@ export function buildContent(source: ProblemSource, type: 'markdown' | 'html' = ...source.source ? [`

${_('Source')}

`, source.source] : [], ].join('\n') : [ - ...source.description ? [`## ${_('Description')}`, source.description] : [], - ...source.input ? [`## ${_('Input Format')}`, source.input] : [], - ...source.output ? [`## ${_('Output Format')}`, source.output] : [], + ...source.description ? [`## ${_('Description')}`, '', source.description, ''] : [], + ...source.input ? [`## ${_('Input Format')}`, '', source.input, ''] : [], + ...source.output ? [`## ${_('Output Format')}`, '', source.output, ''] : [], ...(source.samples).map((sample, i) => [ `\`\`\`input${i + 1}`, sample[0], @@ -72,8 +72,8 @@ export function buildContent(source: ProblemSource, type: 'markdown' | 'html' = '```', ].join('\n')), ...source.samplesRaw ? [source.samplesRaw] : [], - ...source.hint ? [`## ${_('Hint')}`, source.hint] : [], - ...source.source ? [`## ${_('Source')}`, source.source] : [], + ...source.hint ? [`## ${_('Hint')}`, '', source.hint, ''] : [], + ...source.source ? [`## ${_('Source')}`, '', source.source, ''] : [], ].join('\n'); }