diff --git a/src/app/plugins/markdown/block/rules.ts b/src/app/plugins/markdown/block/rules.ts index f598ee63..44cb85dd 100644 --- a/src/app/plugins/markdown/block/rules.ts +++ b/src/app/plugins/markdown/block/rules.ts @@ -11,13 +11,13 @@ export const HeadingRule: BlockMDRule = { }; const CODEBLOCK_MD_1 = '```'; -const CODEBLOCK_REG_1 = /^`{3}(\S*)\n((?:.*\n)+?)`{3} *(?!.)\n?/m; +const CODEBLOCK_REG_1 = /^(`{3,}|~{3,})(?:[ \t]*(\S+))?\n([\s\S]*?)\1 *(?!.)\n?/m; export const CodeBlockRule: BlockMDRule = { match: (text) => text.match(CODEBLOCK_REG_1), html: (match) => { - const [, g1, g2] = match; - const classNameAtt = g1 ? ` class="language-${g1}"` : ''; - return `
${g2}
`; + const [ , fence, lang, code ] = match; + const classNameAtt = lang ? ` class="language-${lang}"` : ''; + return `
${code}
`; }, }; @@ -44,11 +44,11 @@ export const BlockQuoteRule: BlockMDRule = { }; const ORDERED_LIST_MD_1 = '-'; -const O_LIST_ITEM_PREFIX = /^(-|[\da-zA-Z]\.) */; +const O_LIST_ITEM_PREFIX = /^([\da-zA-Z]\.) */; const O_LIST_START = /^([\d])\./; const O_LIST_TYPE = /^([aAiI])\./; const O_LIST_TRAILING_NEWLINE = /\n$/; -const ORDERED_LIST_REG_1 = /(^(?:-|[\da-zA-Z]\.) +.+\n?)+/m; +const ORDERED_LIST_REG_1 = /(^(?:[\da-zA-Z]\.) +.+\n?)+/m; export const OrderedListRule: BlockMDRule = { match: (text) => text.match(ORDERED_LIST_REG_1), html: (match, parseInline) => { @@ -74,9 +74,9 @@ export const OrderedListRule: BlockMDRule = { }; const UNORDERED_LIST_MD_1 = '*'; -const U_LIST_ITEM_PREFIX = /^\* */; +const U_LIST_ITEM_PREFIX = /^([-*+]) */; const U_LIST_TRAILING_NEWLINE = /\n$/; -const UNORDERED_LIST_REG_1 = /(^\* +.+\n?)+/m; +const UNORDERED_LIST_REG_1 = /(^([-*+]) +.+\n?)+/m; export const UnorderedListRule: BlockMDRule = { match: (text) => text.match(UNORDERED_LIST_REG_1), html: (match, parseInline) => {