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

Request more control over escaping #35

Closed
4 tasks done
johnhooks opened this issue Jan 2, 2023 · 6 comments
Closed
4 tasks done

Request more control over escaping #35

johnhooks opened this issue Jan 2, 2023 · 6 comments
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on

Comments

@johnhooks
Copy link

Initial checklist

Problem

I'm using toHtml to stringify highlighted code elements and then use them in MDsveX, a Svelte version of MDX. Though I need to escape [{}`] because those are special characters in Svelte. I was attempting to escape them at the base of the AST on the text values. But I they were getting double escaped. I then figured out toHtml escapes &.

Currently, I'm running the hast through toHTML and then escaping the other characters I need. Though this seems brittle and also much less targeted than having control at the Text.value level.

Solution

  • make it possible to disable escaping in toHtml
  • expose a escape option that allows overriding the default.

Alternatives

  • add the ability to add characters to subset

what do you think?

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Jan 2, 2023
@wooorm
Copy link
Member

wooorm commented Jan 2, 2023

This project focusses on standards, not on custom non-standard needs.

Disabling escaping would break everything. Allowing to override escape would break everything.

I don’t think this feature would be enough for you to generate a string for Svelte.
Also sounds like you don’t generate things for Svelte, but for MDsveX. Which is even more different.

What do you want to generate? Why use this project for that? Why not build your own project for Svelte/MDsveX’s format?
Why not use MDX itself, which also works with Svelte?

@johnhooks
Copy link
Author

johnhooks commented Jan 2, 2023

I am using this library to generate strings of highlighted code elements from MDSveX fenced code blocks. I'm using hastscript to build the hast AST from Shiki generated tokens. It's not necessarily generating anything MDsveX or Svelte specific, but since its processed by MDsveX after being generated, braces need to be escaped.

Everything is currently working beautifully, but I would like more control over escaping special characters. Like I said I thought adding subset would be better and wasn't sure why the option was disabled. I didn't believe I was inquiring on something that was non-standard, the ability to control which characters of a text value in HTML to escape seemed like it would be a common need.

@ChristianMurphy
Copy link
Member

ChristianMurphy commented Jan 3, 2023

HTML and Svelte templates are related but different, I'd agree with @wooorm that this project focuses HTML, adding Svelte specific escapes doesn't make sense.
A pipeline which would likely make more sense for your use case.

Or alternatively:

In both cases, using svast-stringify should guarantee compatibly with MDsveX, since it is designed/built to implement MDsveX's own internal AST representation and will include escapes expected by MDsveX.

@johnhooks
Copy link
Author

@ChristianMurphy and @wooorm thanks for the advice. I'll take a look at building a svast tree, rather than hast.

@github-actions

This comment has been minimized.

@wooorm wooorm added the 👀 no/external This makes more sense somewhere else label Jan 3, 2023
@github-actions

This comment was marked as resolved.

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

3 participants