import { ContentNode } from '../interface'; export interface ProblemSource { description?: string, input?: string, output?: string, samples?: [string, string][], hint?: string, source?: string, } export function buildContent(source: ProblemSource | ContentNode[], type: 'markdown' | 'html' = 'markdown', translate?: Function) { const _ = translate || ((s: string) => s); let cnt = 0; if (source instanceof Array) { return type === 'html' ? source.map((node) => [ node.type !== 'Plain' ? `
${node.payload[0]}`
+ `${node.payload[1]}`
: '',
node.text,
].join('\n')).join('\n')
: source.map((node) => [
node.type !== 'Plain' && (node.type !== 'Sample' || !cnt) ? `## ${node.sectionTitle}` : '',
...node.type === 'Sample'
? [
'',
`\`\`\`input${++cnt}`,
node.payload[0],
'```',
'',
`\`\`\`output${cnt}`,
node.payload[1],
'```',
'',
]
: [],
'',
node.text,
'',
].join('\n')).join('\n');
}
return type === 'html'
? [
...source.description ? [``,
sample[0],
``,
sample[1],
'',
].join('')),
...source.hint ? [`