@slite/unified-mdast-to-delta

    1.7.3 • Public • Published

    unified-delta

    A unified plugin that is able to compile a Markdown Ast to Delta.

    Usage

    const toDelta = require("unified-delta")
    
    const markdown = `# Hello & World
    
    > A block quote.
    
    * Some _emphasis_, **importance**, and \`code\`.`
    
    toDelta()
      .process(markdown)
      .then(({ contents }) => console.log(JSON.stringify(contents)))
      .catch(e => console.log(e))

    This will output the following:

    [
      { "insert": "Hello & World" },
      {
        "insert": "\n",
        "attributes": { "type": "header-one", "data": { "depth": 0 } }
      },
      { "insert": "A block quote." },
      { "insert": "\n", "attributes": { "type": "unstyled" } },
      { "insert": "\n", "attributes": { "type": "quote-block" } },
      { "insert": "Some " },
      { "insert": "emphasis", "attributes": { "italic": true } },
      { "insert": ", " },
      { "insert": "importance", "attributes": { "bold": true } },
      { "insert": ", and " },
      { "insert": "code", "attributes": { "code": true } },
      { "insert": "." },
      { "insert": "\n", "attributes": { "type": "unstyled" } },
      {
        "insert": "\n",
        "attributes": { "type": "unordered-list-item", "data": { "depth": 0 } }
      },
      { "insert": "\n", "attributes": { "type": "unstyled" } }
    ]

    API

    [...].use(toDelta[, options])

    options
    options.endWithNewline (default true)

    Wether to finish the Delta inserts with a newline. This is mandatory per Delta's spec, but the option is here for testing purposes.

    Todo:

    [] Make the visitors system extensible

    Since each client will implement its own set of attributes for their delta format we can't cover everything here.

    Install

    npm i @slite/unified-mdast-to-delta

    DownloadsWeekly Downloads

    22

    Version

    1.7.3

    License

    MIT

    Unpacked Size

    39.4 kB

    Total Files

    44

    Last publish

    Collaborators

    • ptaylour
    • dqms
    • accounts-dev-slite
    • calyhre
    • arnaudrinquin
    • prenaudin
    • shahor
    • antoineduban
    • julienr2
    • guillaumemorin
    • christophepas
    • antoinelyset
    • d34thwings
    • jasonphillips
    • bitphinix
    • agix
    • alisonsayarath