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

Parse HTML markup #37

Open
sidvishnoi opened this issue Sep 26, 2024 · 0 comments
Open

Parse HTML markup #37

sidvishnoi opened this issue Sep 26, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@sidvishnoi
Copy link

✨ Feature request

Parse inline HTML markup also, for things that cant' be defined in markdown directly, such as <time>, <span class="some-class">.

Motivation

Sometimes we want support raw-markup inline in markdown string, for things that can't be represented in markdown.
My use case is browser extension's localization messages, where I had to include a <time> element in a string.

Example

const html = render(markdown, {
  // bold: (node) => `<b>${node.children}</b>`,
  // ...
  raw: (node) => {
    if (node.tag !== 'time') return null;
    return `<${node.tag} datetime="${node.attrs.datetime}">${node.children}</${node.tag}>`, // ignore all attributes except `datetime`
  }
})
<!-- input -->
hello <time datetime="foo" style="ignored">foo</time> world <img src="oh no" />

<!-- output -->
hello <time datetime="foo">foo</time> world

Alternatives

Some other much heavier library

Additional context

For simplicity, I think we can require well-formed XML, and leave rendering to users. As long as parsing is light (and told explicitly that it's unsafe), I think this can be a good addition.

@sidvishnoi sidvishnoi added the enhancement New feature or request label Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant