A functional library that takes a markdown body; and tries to create a JSON representation of the document.
- Headings
- Lists
- Paragraphs
Install:
npm install @connected-web/md2json
const md2json = require('@connected-web/md2json')
const fs = require('fs')
const filename = 'README.md'
const md = fs.readFileSync(filename, 'utf8')
const json = md2json(filename, md)
console.log('Markdown to Json:', json)- Example Output:
examples/example-output.json - Test Output:
examples/test-output.json
md2json(markdown)md2json(title, markdown)md2json({
title: 'README.md',
markdown: '# Heading\n\nContent'
})The top level section of the JSON output.
The text string representing the markdown to be converted to JSON
const tokens = md2json.tokens('# Heading\n\nContent\n\n##Heading 1.1')
console.log(tokens)Output:
[
{ "name": "h1", "text": "Heading" },
{ "name": "p", "text": "Content"},
{ "name": "h2", "text": "Heading 1.1"}
]- Format parameters
- Render Markdown as HTML
- Create DOM from Markdown
- Create Tokens in the form:
{ name: el.tagName, text: el.text } - Parse Tokens into Hierarchy
- Return JSON hierarchy
Released under ISC.
- marked
- cheerio
- mocha
- chai
- standard
- Add
.tokens(markdown)method to API
- First version ready for release
- Not perfect, but hopefully something people can work with