Syntax highlighting <pre> blocks #8024
-
Howdy! I feel daft asking, but after a lot of searching and experimenting I still haven't turned up the answer. How do I turn on syntax highlighting for HTML
Why pre instead of Markdown code fences? I'd like to add links to code blocks, with the aim of linking specific code symbols to their definitions further down the page. Adding links to Markdown fences (syntax highlighted through SuperFences) seems to not be a thing, even when attempting to cheat the rendering pipeline order with various Jinja2 incantations. So it looks like I need to revert to good old HTML |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
If that is the route you want to go, a postprocessor that scans the finished HTML for blocks you want to process would be the easier route. The alternative would be to use fenced code and then postprocess for things you want to linkify. Now, if you are asking if there is already a canned package that can do that and honor your links and such 🤷🏻. You may have to look into that. |
Beta Was this translation helpful? Give feedback.
-
Ah, so I couldn't find the answer because the support doesn't exist out of the box for syntax highlighted Thanks for the very rapid response, I'll see what I can come up with :) |
Beta Was this translation helpful? Give feedback.
-
There are JavaScript highlighters out there, but Material supports highlighting via Pygments during document generation. You could turn it off and use something like Highlight.js or Prism.js. I don't know how they play with links or if they have features that can add them, but something you could look into. |
Beta Was this translation helpful? Give feedback.
If that is the route you want to go, a postprocessor that scans the finished HTML for blocks you want to process would be the easier route. The alternative would be to use fenced code and then postprocess for things you want to linkify.
Now, if you are asking if there is already a canned package that can do that and honor your links and such 🤷🏻. You may have to look into that.