diff --git a/src/app/components/editor/input.ts b/src/app/components/editor/input.ts index ad314add..4b6df40f 100644 --- a/src/app/components/editor/input.ts +++ b/src/app/components/editor/input.ts @@ -228,9 +228,13 @@ const parseCodeBlockNode = (node: Element): CodeBlockElement[] | ParagraphElemen children: [{ text }], })); const childCode = node.children[0]; - const className = - isTag(childCode) && childCode.tagName === 'code' ? childCode.attribs.class ?? '' : ''; - const prefix = { text: `${mdSequence}${className.replace('language-', '')}` }; + const attribs = + isTag(childCode) && childCode.tagName === 'code' ? childCode.attribs : undefined; + const languageClass = attribs?.class; + const customLabel = attribs?.['data-label']; + const prefix = { + text: `${mdSequence}${customLabel ?? languageClass?.replace('language-', '') ?? ''}`, + }; const suffix = { text: mdSequence }; return [ { type: BlockType.Paragraph, children: [prefix] }, diff --git a/src/app/plugins/markdown/block/rules.ts b/src/app/plugins/markdown/block/rules.ts index e0a727ee..ad1af37e 100644 --- a/src/app/plugins/markdown/block/rules.ts +++ b/src/app/plugins/markdown/block/rules.ts @@ -18,7 +18,7 @@ export const CodeBlockRule: BlockMDRule = { const [, g1, g2] = match; // use last identifier after dot, e.g. for "example.json" gets us "json" as language code. const langCode = g1 ? g1.substring(g1.lastIndexOf('.') + 1) : null; - const filename = g1 != langCode ? g1 : null; + const filename = g1 !== langCode ? g1 : null; const classNameAtt = langCode ? ` class="language-${langCode}"` : ''; const filenameAtt = filename ? ` data-label="${filename}"` : ''; return `
${g2}`;