diff --git a/src/node/markdown/plugins/highlightLines.ts b/src/node/markdown/plugins/highlightLines.ts index 5938f8b5..f7e5293a 100644 --- a/src/node/markdown/plugins/highlightLines.ts +++ b/src/node/markdown/plugins/highlightLines.ts @@ -10,20 +10,23 @@ export const highlightLinePlugin = (md: MarkdownIt) => { const [tokens, idx, options] = args const token = tokens[idx] - // due to use of markdown-it-attrs, the {0} syntax would have been converted - // to attrs on the token + // due to use of markdown-it-attrs, the {0} syntax would have been + // converted to attrs on the token const attr = token.attrs && token.attrs[0] + let lines = null + if (!attr) { // markdown-it-attrs maybe disabled - const rawInfo = token.info + if (!rawInfo || !RE.test(rawInfo)) { return fence(...args) } const langName = rawInfo.replace(RE, '').trim() - // ensure the next plugin get the correct lang. + + // ensure the next plugin get the correct lang token.info = langName lines = RE.exec(rawInfo)![1] @@ -31,6 +34,7 @@ export const highlightLinePlugin = (md: MarkdownIt) => { if (!lines) { lines = attr![0] + if (!lines || !/[\d,-]+/.test(lines)) { return fence(...args) } @@ -45,6 +49,7 @@ export const highlightLinePlugin = (md: MarkdownIt) => { : token.content const rawCode = code.replace(wrapperRE, '') + const highlightLinesCode = rawCode .split('\n') .map((split, index) => {