mark-twain

2.0.3 • Public • Published

Mark Twain

npm package NPM downloads Dependency Status

It is not easy to process Markdown directly. However, we can use mark-twain to parse a Markdown file(and YAML/HTML which in it) into JsonML which is easier to process.

Installation

npm install mark-twain

Usage

const MT = require('mark-twain');
const fs = require('fs');
const jsonML = MT(fs.readFileSync('something.md').toString());

The returned value of MT would be JsonML, something looks like this:

{
  // YAML will be parsed as meta data.
  meta: {
    title: 'Title',
    ...
  },
 
  // Others will be parsed as JsonML.
  content:  [
    "article",
    ["h1", "Here is a heading"],
    [
      "ol",
      [
        "li",
        [
          "p",
          "First"
        ]
      ],
      ...
    ],
    [
      "p",
      "This is a paragraph, including ",
      [
        "em",
        "EM"
      ],
      " and ",
      [
        "strong",
        "STRONG"
      ],
      ". Any question? Oh, I almost forget ",
      [
        "code",
        "inline code"
      ],
      "."
    ],
    ...
  ]
}

Relative

Liscence

MIT

Package Sidebar

Install

npm i mark-twain

Weekly Downloads

3,896

Version

2.0.3

License

MIT

Unpacked Size

6.89 kB

Total Files

9

Last publish

Collaborators

  • benjycui
  • paranoidjk