Skip to content

Is it Appropriate for @shikijs/rehype to Output a HAST Root Node? #1033

@shunnNet

Description

@shunnNet

🖐️ Hello, I'm currently working on vue-markdown, which uses Unified to convert Markdown into HAST before rendering it as Vue components.

While trying to support @shikijs/rehype, I noticed that the HAST it produces includes a Root node as the outermost element, followed by the highlighted content. According to the HAST specification, the Root node should “never be a child” (source). Because of this, I initially didn’t handle the Root node, which resulted in Shiki-highlighted content not being rendered correctly.

Shiki adds a Root node as a base when converting to HAST (code reference).

Here’s a reproduction of the issue:
https://stackblitz.com/edit/stackblitz-starters-eddwspb8?file=index.js

Since this Root node becomes a child during the Markdown rendering process, it violates the HAST specification. I’m wondering: is this output appropriate? Would you consider removing the Root node from the output?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions