Custom highlight function doesn't handle ${VAR}
See original GitHub issueHere’s an example with a shell script its quite common to use ${VAR}
syntax inside a bash/shell script e.g:
```bash
VAR="MY_VAR"
echo "${MY_VAR}"
```
It looks like this conflicts with MDsveX/Svelte template syntax and never loads for me. This also affects javascript code blocks. Maybe making a note in the docs would make sense in https://github.com/pngwn/MDsveX/issues/210.
@pngwn noted a workaround by using a custom escaping function:
const shiki = require("shiki");
const escape_svelty = (str) =>
str
.replace(
/[{}`]/g,
(c) => ({ "{": "{", "}": "}", "`": "`" }[c])
)
.replace(/\\([trn])/g, "\$1");
async function highlighter(code, lang) {
const highlighter = await shiki.getHighlighter({ theme: "github-dark" });
return escape_svelty(highlighter.codeToHtml(code, lang || "text"));
}
module.exports = {
extensions: [".svx", ".md"],
highlight: {
highlighter: highlighter,
},
};
_Originally posted by @michael0liver in https://github.com/pngwn/MDsveX/issues/205#issuecomment-803667947_
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to enable element highlighting for handlebars in Sublime ...
I have selected the Handlebars option in the footer in Sublime Text 3, but when I click on an element, it isn't highlighted...
Read more >CSS Custom Highlight API Module Level 1
The Custom Highlight API provides a programmatic way of adding and removing highlights that do not affect the underlying DOM structure, ...
Read more >Syntax Highlight Guide | Visual Studio Code Extension API
Syntax Highlight Guide. Syntax highlighting determines the color and style of source code displayed in the Visual Studio Code editor. It is responsible...
Read more >Highlight patterns and trends with conditional formatting
You can use conditional formatting to highlight cells that contain values that meet a certain condition, or format a whole cell range and...
Read more >Straightforward way to highlight a single bar in a BarChart
A colour function will do that but easier simply to use a wrapper ... As a not-so-straightforward-yet-fun alternative, you can use a custom...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Released in 0.9.1.
I don’t think an
escape
boolean option will work because we don’t want to escape all of the code that is returned from the custom highlight function.In this case:
We want to keep the
pre
tag intact and unescaped (we want them to be interpreted as HTML). I think the solution to this is to export a utility function that people can use to escape the svelte syntax.