We're evolving to serve you better! This current forum has transitioned to read-only mode. For new discussions, support, and engagement, we've moved to GitHub Discussions.

Markdown editor and line-numbers

  • #5265
    Avatar photo[anonymous]

    Hi there,

    One of the built-in features that I really like for Publii is the Markdown editor. I ended up purchasing the ProDocs theme because it seemed especially suited for code-type blogging.

    I noticed that you can enable line numbers, but when using the MD editor, it seems those stay absent and the `line-numbers` class doesn’t get added to the `pre`

    Is there a workaround for this, even if a bit hackish?


    Avatar photo[anonymous]

    I got it… I guess.

    I had to modify the `footer.hbs` file where the `syntaxHighlighterLineNumbers` is checked. I ended up adding this so that it searches for any code tags, grabs the parent tag, and appends the `line-numbers` class before prism line-numbers initializes:

    {{#checkIfAll @config.custom.syntaxHighlighter @config.custom.syntaxHighlighterLineNumbers}}
    var code_snippets = document.querySelectorAll('code');
    for (var i = 0; i < code_snippets.length; i++) {
    <script defer src="{{js "prism-line-numbers.min.js"}}"></script>

    This could be specific to the ProDocs theme. I’ve only used that one so far. But for now it works. Your mileage my vary…