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
Pass additional context to highlight option from fence renderer #626
Comments
Suggestion sounds reasonable, but i'm very conservative about api changes. I see no strong reasons to decline immediately, but i don't like to make this change too :). I'd stay this open for a while. |
Seems reasonable - i was able to locally override the fence handler in my own project, so that workaround handles my own workflow. Only needs to be pulled into core if it helps other folks too. Thanks |
Fixed, remainder of fence params is now passed through to highlighter as 3rd option. |
…only keep `@types/highlight.js`) to resolve vulnerability GHSA-7wwv-vh3v-89cq by @UNIDY2002 * Bump dependency `highlight.js` of `types/markdown-it` from 9.7.0 to 10.4.1 * Add support for changed API of `markdown-it` (markdown-it/markdown-it#626) at 12.0.0 * Revert dependency `highlight.js` to ^9.7.0 (So that the TypeScript version can remain 2.0, and will not break the requirements of the dependents of this library.) * Adjust test code for types/markdown-it
@rlidwka will this fix only work if the additional attributes are whitespace-delimited, or will it also work if they're comma-separated? As in-
|
This is not allowed by CM spec. |
This is similar to #456 (Access to the render function from a custom highlight function) but much more limited in scope.
In some markdown flavors like python, you can pass additional parameters at the head of a fenced code block like this:
Currently, the
options.highlight
callback passes two parameters:Where
langName
is created by taking all the info available at the head of the fenced code block and splitting on the first whitespace characterThe only requested delta is to leave the first two parameters exactly as they are and just pass in the rest of the available context as a third so the highlight function can make use of it:
Possible workarounds
The same workaround to #456 is available here to override the
default_rules.fence
implementation, but that leaves a lot of work in the client's flowAnother available workaround is to delimit by a non-space character when shoving extra info to fenced code blocks like this
python,hl_lines="1"
, and then splitting out the language definition inside the highlight function, but this breaks the language detection for other engines where the raw md might live, like in your editor or github.The text was updated successfully, but these errors were encountered: