Skip to content

Parse HTML markup #37

Description

@sidvishnoi

✨ 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovement of existing features

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions