Skip to content

(rehype-highlight) How to programmatically ignore certain code blocks? #154

Discussion options

You must be logged in to vote

Welcome @HerbCaudill! 👋
Sorry you ran into a spot of trouble.

According to the rehype-highlight docs, you can add a no-highlight class to a <code> block to have the highlighter ignore it.

Note that it expects no-highlight/nohighlight to be the first, or the only class on the <code> tag.
Your plugin is adding it as the second and final.
Which means the language detector will choose the language you selected https://github.com/rehypejs/rehype-highlight/blob/81f7dd1c383ffe0d5432584c3a66d281bbe9aa84/lib/index.js#L157-L179

This can be resolved by prepending the class with unshift.
Working example: https://codesandbox.io/p/sandbox/sandpack-vs-remark-rehype-forked-v6f7tr?file=%2Flib%2FloadMdx.…

Replies: 2 comments 6 replies

Comment options

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

You must be logged in to vote
6 replies
@ChristianMurphy
Comment options

@HerbCaudill
Comment options

@wooorm
Comment options

@HerbCaudill
Comment options

@wooorm
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants