https://github.com/benjycui/mark-twain
Parse Markdown into JavaScript object.
https://github.com/benjycui/mark-twain
Last synced: 25 days ago
JSON representation
Parse Markdown into JavaScript object.
- Host: GitHub
- URL: https://github.com/benjycui/mark-twain
- Owner: benjycui
- Created: 2015-12-01T07:38:18.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-11-06T18:42:06.000Z (over 5 years ago)
- Last Synced: 2025-04-02T11:06:39.892Z (about 1 month ago)
- Language: JavaScript
- Size: 27.3 KB
- Stars: 89
- Watchers: 4
- Forks: 18
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-nodejs - mark-twain - 将 Markdown 解析为 JavaScript 对象 (Uncategorized / Uncategorized)
README
# Mark Twain
[](https://travis-ci.org/benjycui/mark-twain)
[](https://www.npmjs.org/package/mark-twain)
[](https://npmjs.org/package/mark-twain)
[](https://david-dm.org/benjycui/mark-twain)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](http://www.jsonml.org/) which is easier to process.
## Installation
```bash
npm install mark-twain
```## Usage
```js
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:
```js
{
// 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
* [jsonml-to-react-component](https://github.com/benjycui/jsonml-to-react-component) To convert JsonML to React Component.
* [jsonml.js](https://github.com/benjycui/jsonml.js) A collection of JsonML tools.## Liscence
MIT