Closed doaortu closed 4 days ago
Hey! Good catch — it appears there was a bug in this template where code blocks with HTML code would render as HTML if no language was specified for the snippet.
The simple fix here is to add a language type to your snippet (ie. ```xml
), and then you get the benefit of nicer code highlighting as well:
That said, I do think that the Protocol template should handle this more gracefully if you do omit the language. I've just pushed an update to this template to fix this, so you can either download the latest version of the template from the Tailwind UI website, or you can apply this fix yourself in your own project by applying the following change to your ./src/mdx/rehype.mjs
file:
function rehypeParseCodeBlocks() {
return (tree) => {
visit(tree, 'element', (node, _nodeIndex, parentNode) => {
- if (node.tagName === 'code' && node.properties.className) {
- parentNode.properties.language = node.properties.className[0]?.replace(
- /^language-/,
- '',
- )
+ if (node.tagName === 'code') {
+ parentNode.properties.language = node.properties.className
+ ? node.properties?.className[0]?.replace(/^language-/, '')
+ : 'txt'
+ }
})
}
}
(Note, you'll need to restart your dev server when making changes to this file.)
I hope that helps! 💪
Hi, Thank you for spending time to fix this problem.
That is indeed solved the bug.
Describe the bug When I tried to define apache config example in a mdx page, something like this:
The VirtualHost tag and Location tag just didn't show up in page.
To Reproduce Steps to reproduce the behavior:
insert multiline triple backtick code block with this content, or any jsx like tag