New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow markup in highlighted code block #59
Comments
Possible syntax:
The way markdown-it hands off rendering to the fenced code block, it will parse any information that occurs after the initial langName = info.split(/\s+/g)[0]; Which means we cannot add spaces before any potential additional parameters - which breaks most language recognition in markdown rendering for github and vscode If we do have to delimit with a character, I tried following the language tag with each of the following special chars
Which returns this: CONST token = "<mark>your_token</mark>" So we either need the resolution of #626 Pass additional context to highlight option from fence renderer or need to extend fenced code block handler Prior Art (Possible Syntaxes)Python - Fenced Code Blocks
or
Eleventy - Syntax Highlighting Plugin
Pandoc - Fenced Code Attributes
JIRA Advanced Formatting
|
How to allow markup in pre-escaped code block in node.jsOut-of-the-box, highlight.js needs to be run in browser in order to preserve HTML markup within a code block Here are a couple reference issues submitted to highlightjs:
All of which rely on using
Here's an example of highlighting pre-escaped code using the browser API (live demo): <pre><code class="language-html" id="block">
<a href="<mark>url</mark>"> Link </a>
</code></pre>
<script>
hljs.highlightBlock(document.getElementById('block'));
</script> Option A - WrapperThe implementation of
If we can stub 1 & 3 in node, we can call Parsing HTML TextHere are some strategies for extracting the text from an html block (live demo)
However, most suggestions rely on having access to the browser by using There are a couple regex options, but they feel brittle Merging both html streams also feels non-trivial, so I stopped here Option B - Add Window to NodeWe can install const hljs = require("highlight.js")
let lang = "html"
let htmlRaw = `<a href="<mark>url</mark>"> Link </a>`
// create window
const Window = require('window');
const window = new Window();
// make document available globally w/o let
document = window.document
// create text as node
let pre = window.document.createElement('pre');
pre.innerHTML = `<code class="language-${lang}">${htmlRaw}</code>`
let node = pre.childNodes[0]
// highlight node
hljs.highlightBlock(node)
console.log(node.innerHTML); The biggest tradeoff here is that you need to make I added a minimal, complete verifiable example using node.js in KyleMit/highlightjs-markup |
Follow up to #15 add syntax highlighting
Allow pre-escaped code to include markup that will be preserved when adding syntax highlighting
For example, in github and stackoverflow, you can include html tags in pre-escaped code blocks:
Which renders like this (with a bold tag around "url")
So ideally, this markdown code sandbox would work
This might not be well equipped for markdown-it
References:
Maybe markdown-it-highlightjs will work with raw code blocks
The text was updated successfully, but these errors were encountered: