md-to-html
unified processor to parse and serialize Markdown to HTML. Powered by my favorite plugins.
Install
> yarn add @rqbazan/md-to-html
Usage
Say we have the following file, doc.md
---
title: This personal site
date: 2020-12-25
author: Santiago Q. Bazan
---
# Sample note :tada:
Here's a quick _sample note_
And our script, index.js
, looks as follows:
import path from 'path'
import fs from 'fs'
import mdToHtml from '@rqbazan/md-to-html'
function main() {
const pathfile = path.join(__dirname, 'doc.md')
const doc = fs.readFileSync(pathfile)
const vfile = mdToHtml.processSync(doc)
console.log(vfile.data) // yaml metadata
console.log(vfile.toString()) // html
}
main()
Now, running node index.js
yields:
λ node index.js
{
title: 'This personal site',
date: '2020-12-25',
author: 'Santiago Q. Bazan'
}
<h1>Sample note <img class="emoji" draggable="false" alt="🎉" src="https://twemoji.maxcdn.com/v/13.0.1/72x72/1f389.png" title="🎉"/></h1>
<p>Here's a quick <em>sample note</em></p>
Here is the generated HTML:
<h1>
Sample note
<img
class="emoji"
draggable="false"
alt="🎉"
src="https://twemoji.maxcdn.com/v/13.0.1/72x72/1f389.png"
title="🎉"
/>
</h1>
<p>Here's a quick <em>sample note</em></p>