🗒️ mrk
The happy little extendable markdown parser
mrk is an easily extendable markdown parser created for Decent. We needed it
for a few reasons:
- We didn't want to have to bring in an npm module or do anything fancy to use it
- We needed to be able to disable features and add new ones easily
- We wanted access to the parsed token stream
- We wanted something small, simple, and easy to extend
How do I use it?
Include mrk.js in your page, or npm install mrkjs
:
Usage is as follows:
let mark = mrk()
let html = mark('Some _markdown_').html()
console.log(html)
That's it! You can also directly access the parsed token stream by looking at mark(...).tokens
, if you're so inclined.
Can I haz Promise
?
Yes!!
const mrk = require('mrk.js/async')
const mark = mrk()
mark('Awesome!').then(parsed => {
console.log('tokens:', parsed.tokens)
return parsed.html()
}).then(html => {
console.log('HTML:', html)
})
I want/to remove Feature X!
You can implement/remove it yourself. mrk was designed to be easily extendable:
Removing a feature
mark('Visit http://google.com').html()
delete mark.patterns.autolink
mark('Visit http://google.com').html()
Adding a new parse rule
Say we wanted to add ~~strikethrough~~
text, GFM-style:
const markWithStrikethrough = mrk({
extendPatterns: {
strikethroughStart: ({ read, has }) => {
return read(2) === '~~'
&& !has('strikethroughStart', 'strikethroughEnd')
},
strikethroughEnd: ({ read, has }) => {
return read(2) === '~~'
&& has('strikethroughStart', 'strikethroughEnd')
},
},
extendPairs: {
strikethroughStart: 'strikethroughEnd'
},
extendHtmlify: {
strikethroughStart = () => '<s>',
strikethroughEnd = () => '</s>'
}
})
mrk('~~hello~~').html()
If you end up creating an extension for mrk for your project and it's generic enough,
please consider adding it to the list of
community extensions for mrk. I'd appreciate it!
License
MIT :tada: