Skip to content
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

Force svelte not to interpret some classes #677

Open
tobiasBora opened this issue Dec 13, 2024 · 2 comments
Open

Force svelte not to interpret some classes #677

tobiasBora opened this issue Dec 13, 2024 · 2 comments

Comments

@tobiasBora
Copy link

tobiasBora commented Dec 13, 2024

When using rehype-katex, it generates text like:

<div class="math math-inline">
 … some stuff involving {x} that is interpreted by svelte
</div>

and it produces error as {x} usually comes from a math expression like \sqrt{x} and is not meant to be replaced as a svelte variable. People created a rehype-katex-svelte (as recommended in #302) to solve this issue and this seems to work reasonably well, but I don't know how well maintained this is (e.g. it requires a quite old remark-math, but so do rehype-katex so it might be unrelated) and the author mention some potential security flows. As such, it seems not at battle-tested as rehype-katex.

As such, I was wondering if would instead directly allow users to add in MDsveX (via the options) a list of classes that should be wrapped around {@html } appropriately (with escaping etc) in order not to be interpreted by svelte later in the process. As rehype-katex does not want to do it on their side (see remarkjs/remark-math#104), I see not much other solution, and this might anyway be useful in other scenarios.

@github-project-automation github-project-automation bot moved this to Triage + Refine in mdsvex Dec 13, 2024
@PeppeL-G
Copy link

Haven't thought much about this, but for a general functionality of "escaping" Svelte code, wouldn't a custom remark-directive named notSvelte or similar be a good solution? Where theContent in the directive is replaced with @html{`theContent`}, and that can be used like this:

Between the square brackets :notSvelte[in here using { and } works].

::notSvelte[In here using { and } works.]

:::notSvelte

In here, using { and } works.

:::

In VuePress, they do something like that:

https://vuepress.vuejs.org/guide/using-vue.html#escaping

::: v-pre
`{{ This will be displayed as-is }}`
:::

@tobiasBora
Copy link
Author

Hum, that is also an interesting option (we can even nest ::notSvelte and ::svelte), but I'd say that both would be interesting: what you describe is cool to escape any code easily with no configuration, but is quite verbose and error-prone when used for math: I don't want to type in the markdown directly ::notSvelte[$a+b$] everytime I write some math as this is just too verbose. The class-based approach is useful when we don't want/can't change the markdown itself as the code is generated from an external library like Katex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Triage + Refine
Development

No branches or pull requests

2 participants