import { Marked } from 'marked'
import { markedHighlight } from 'marked-highlight' // Code highlighting
import markedFootnote from 'marked-footnote' // Footnotes
import hljs from 'highlight.js'
import type { SynchronousOptions } from 'marked-highlight' // Code highlighting options
const optionHighlight: SynchronousOptions = {
langPrefix: 'hljs language-',
highlight(code, lang) {
const language = hljs.getLanguage(lang) ? lang : 'plaintext'
return hljs.highlight(code, { language }).value
},
}
const marked = new Marked()
marked.use(
markedFootnote(),
markedHighlight(optionHighlight),
)
console.log("has content====>", marked.parse(`
# heading1
\`\`\`javascript
const highlight = "code";
\`\`\`
`))
console.log("no cotent ====>", marked.parse(`
\`\`\`javascript
const highlight = "code";
\`\`\`
`))
/*
You update the plugins very timely. I discovered an issue while using it.
1. When there is no content before a block of code, marked parsing causes the code highlighting plugin highlight.js to fail.
2. When there is content before a block of code, marked parsing works fine and the code highlighting plugin highlight.js works normally.
3. When there is no content before inline code, comment out line 18 markedFootnote plugin, marked parsing works fine, and the code highlighting plugin highlight.js works normally.
Why does the markedFootnote plugin affect the highlight.js plugin? Could you please take a look for me? Thank you.
I've also tried to replace the order of the plugins in the use method but still couldn't solve the problem.
When there is content before a code block, correct parsing result
has content====> <h1>heading1</h1>
<pre><code class="hljs language-javascript"><span class="hljs-keyword">const</span> highlight = <span class="hljs-string">"code"</span>;
</code></pre>
When there is no content before a code block, incorrect parsing result.
no cotent ====> <pre><code class="hljs language-javascript">const highlight = "code";
</code></pre>
When the markedFootnote plugin is commented out, all results are parsed correctly.
When there is content before a code block, correct parsing result
has content====> <h1>heading1</h1>
<pre><code class="hljs language-javascript"><span class="hljs-keyword">const</span> highlight = <span class="hljs-string">"code"</span>;
</code></pre>
When there is no content before a code block, correct parsing result
cotent ====> <pre><code class="hljs language-javascript"><span class="hljs-keyword">const</span> highlight = <span class="hljs-string">"code"</span>;
</code></pre>
*/
bug description
version
marked:11.0.1
marked-footnote:1.2.0
marked-highlight:2.0.9
highlight.js: 11.9.0
You update the plugins very timely. I discovered an issue while using it.
When there is no content before a block of code, marked parsing causes the code highlighting plugin highlight.js to fail.
When there is content before a block of code, marked parsing works fine and the code highlighting plugin highlight.js works normally.
When there is no content before inline code, comment out line 18 markedFootnote plugin, marked parsing works fine, and the code highlighting plugin highlight.js works normally.
The above TypeScript code can directly reproduce the bug.
Why does the markedFootnote plugin affect the highlight.js plugin? Could you please take a look for me? Thank you.
I've also tried to replace the order of the plugins in the use method but still couldn't solve the problem.
When there is content before a code block, correct parsing result
bug description
version
You update the plugins very timely. I discovered an issue while using it.
Why does the markedFootnote plugin affect the highlight.js plugin? Could you please take a look for me? Thank you. I've also tried to replace the order of the plugins in the use method but still couldn't solve the problem.
When the markedFootnote plugin is commented out, all results are parsed correctly.