JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 67
  • Score
    100M100P100Q73861F
  • License MIT

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mdast-util-to-vnode) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    mdast-util-to-vnode

    mdast utility to get the vue vnode

    What is this?

    This package is a utility that takes mdast input and turns it into an Vue.js VNode.

    When should I use this?

    [!TIP] Vue Markdown: the vue component for render markdown string, and support streaming for AI. Learn more 👉

    If you want to use Vue.js to render mdast, use it. It is especially useful when you want to render streamed MarkDown strings in AI application development.

    Install

    npm install mdast-util-to-vnode

    Use

    Say we have the following markdown file example.md:

    # Heading
    
    `mdast-util-to-vnode` is a mdast utility to get the vue vnode.

    And our module example.js looks as follows:

    import fs from 'node:fs/promises'
    import { fromMarkdown } from 'mdast-util-from-markdown'
    import { toVNode } from 'mdast-util-to-vnode'
    
    const doc = await fs.readFile('example.md')
    const vnode = toVNode(fromMarkdown(doc))
    
    console.log(vnode)

    Now running node example.js yields (some info removed for brevity):

    {
      "type": "div",
      "props": null,
      "key": null,
      "children": [
        {
          "type": "h1",
          "props": null,
          "key": null,
          "children": [
            {
              "props": null,
              "key": null,
              "children": "Heading"
            }
          ]
        },
        {
          "type": "p",
          "props": null,
          "key": null,
          "children": [
            {
              "type": "code",
              "props": null,
              "key": null,
              "children": "mdast-util-to-vnode"
            },
            {
              "props": null,
              "key": null,
              "children": " is a mdast utility to get the vue vnode."
            }
          ]
        }
      ]
    }

    API

    This package exports the identifier toVNode. There is no default export.

    toVNode(mdast[, options])

    options

    Support passing in custom Vue components to override mdast nodes.

    export type ComponentReturn = Component | [Component, Record<string, any> | undefined]
    
    export interface ToVNodeOptions {
      components?: Partial<Record<Nodes['type'], ComponentReturn |
      ((node: Node) => ComponentReturn)>>
    }