Skip to content

Add highlight and line number for the code block #518

Closed Answered by yhatt
johnny12150 asked this question in Q&A
Discussion options

You must be logged in to vote

The markdown-it-highlight-lines markdown-it plugin seems to target the code block for the general Markdown document. If the rendering of code blocks is customized by Marp (Marpit) plugins to render the list items instead of plain codes, that plugin would become incompatible.

Instead, you have to implement the logic of line highlights by your own. Fortunately that is not that difficult.

// engine.js
module.exports = ({ marp }) =>
  marp.use(({ marpit }) => {
    const { highlighter } = marpit

    marpit.highlighter = function (code, lang, attrs) {
      const original = highlighter.call(this, code, lang, attrs)

      // Parse code highlight
      const matched = attrs.toString().match(/{…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by johnny12150
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants