Skip to content

benjycui/mark-twain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Parse Markdown into JavaScript object.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published