Spaces:
Running
Running
File size: 799 Bytes
b39afbe |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
/**
* Copyright (c) 2023 MERCENARIES.AI PTE. LTD.
* All rights reserved.
*/
import MarkdownRenderer from './MarkdownRenderer';
import { type MarkedOptions } from 'marked';
class CodeRenderer extends MarkdownRenderer {
constructor(
id?: string,
opts?: { marked?: MarkedOptions; markedEmoji?: { emojis: NonNullable<object>; unicode?: boolean } }
) {
id ??= 'text/markdown-code';
super(id, opts);
}
render(content: { type: string; value: any }): string {
const wrapCode = (str: string) => `<pre><code>${str}</code></pre>`;
const text = Array.isArray(content.value)
? content.value.map(wrapCode).join('')
: wrapCode(content.value?.toString() || '');
return super.render({ type: 'text/markdown', value: text });
}
}
export default CodeRenderer;
|