All Projects → nanaian → mrk

nanaian / mrk

Licence: MIT license
🗒️ Tiny extendable markdown parser / tokenizer

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to mrk

Westwind.aspnetcore.markdown
An ASP.NET Core Markdown support library that provides Markdown parsing, a Markdown TagHelper and Markdown Page Handler Middleware
Stars: ✭ 148 (+1038.46%)
Mutual labels:  markdown-parser
ModooCode
Repo for the Modoocode.
Stars: ✭ 42 (+223.08%)
Mutual labels:  markdown-parser
MarknoteParser
A high performance markdown parser in Swift.
Stars: ✭ 29 (+123.08%)
Mutual labels:  markdown-parser
Showdown
A bidirectional Markdown to HTML to Markdown converter written in Javascript
Stars: ✭ 12,137 (+93261.54%)
Mutual labels:  markdown-parser
Markdown
A Python implementation of John Gruber’s Markdown with Extension support.
Stars: ✭ 2,725 (+20861.54%)
Mutual labels:  markdown-parser
blackfriday-confluence
🛠 Blackfriday-Confluence is confluence wiki renderer for the Blackfriday v2 markdown processor.
Stars: ✭ 20 (+53.85%)
Mutual labels:  markdown-parser
Mdtool
A tool which can process markdown to HTML
Stars: ✭ 136 (+946.15%)
Mutual labels:  markdown-parser
swift-markdownkit
A framework for parsing and transforming text in Markdown format written in Swift 5 for macOS, iOS, and Linux. The supported syntax is based on the CommonMark specification. The framework defines an abstract syntax for Markdown, provides a parser for parsing strings into abstract syntax trees, and comes with generators for creating HTML and attr…
Stars: ✭ 64 (+392.31%)
Mutual labels:  markdown-parser
Frontyaml
YAML Front matter parser
Stars: ✭ 248 (+1807.69%)
Mutual labels:  markdown-parser
htmlup
light and fast markdown parser
Stars: ✭ 48 (+269.23%)
Mutual labels:  markdown-parser
Myst Parser
An extended commonmark compliant parser, with bridges to docutils/sphinx
Stars: ✭ 157 (+1107.69%)
Mutual labels:  markdown-parser
Markdig
A fast, powerful, CommonMark compliant, extensible Markdown processor for .NET
Stars: ✭ 2,730 (+20900%)
Mutual labels:  markdown-parser
html2text
Convert HTML to Markdown-formatted text.
Stars: ✭ 1,351 (+10292.31%)
Mutual labels:  markdown-parser
Markdown It Py
Markdown parser, done right. 100% CommonMark support, extensions, syntax plugins & high speed. Now in Python!
Stars: ✭ 156 (+1100%)
Mutual labels:  markdown-parser
checkyoself
Markdown Grammar Checker for blog posts, etc.
Stars: ✭ 38 (+192.31%)
Mutual labels:  markdown-parser
Proton
A stand-alone application to quickly preview and edit Markdown files using Electron.
Stars: ✭ 140 (+976.92%)
Mutual labels:  markdown-parser
SwiftMark
[⚠️Not a complete implementation] A Markdown renderer written in Swift.
Stars: ✭ 77 (+492.31%)
Mutual labels:  markdown-parser
markright
A customizable markdown parser in Elixir: pure pattern matching.
Stars: ✭ 14 (+7.69%)
Mutual labels:  markdown-parser
MarkyMark-Android
Markdown parser for Android
Stars: ✭ 24 (+84.62%)
Mutual labels:  markdown-parser
readmesfix
Because I'm tired of running into broken READMEs!
Stars: ✭ 63 (+384.62%)
Mutual labels:  markdown-parser

🗒️ 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:

// require('mrk.js') or <script src='mrk.js'></script>

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() // Visit <a href='http://google.com'>http://google.com</a>

delete mark.patterns.autolink // See mrk.js for other patterns/features you can remove

mark('Visit http://google.com').html() // Visit http://google.com

Adding a new parse rule

Say we wanted to add ~~strikethrough~~ text, GFM-style:

// Pass `mrk()` extensions to patterns, pairs, or htmlify
const markWithStrikethrough = mrk({
  extendPatterns: {
    strikethroughStart: ({ read, has }) => {
      // If this function returns a truthy value, it will be parsed as a strikethroughStart token
      // See mrk.js for how `read` and `has` work, plus other functions you get access to.

      return read(2) === '~~' // Next 2 characters should be `~~`
        && !has('strikethroughStart', 'strikethroughEnd') // Not already strikethrough!
    },

    strikethroughEnd: ({ read, has }) => {
      return read(2) === '~~' // Next 2 characters should be `~~`
        && has('strikethroughStart', 'strikethroughEnd') // Must have a strikethroughStart before this token
    },
  },

  extendPairs: {
    // If there is a strikethroughStart token on its own without a strikethroughEnd token to be paired
    // to, it will be discarded and parsed as text.
    strikethroughStart: 'strikethroughEnd'
  },

  extendHtmlify: {
    // Declares how to convert these tokens into HTML strings.
    strikethroughStart = () => '<s>',
    strikethroughEnd = () => '</s>'
  }
})

// :tada:
mrk('~~hello~~').html() // => <s>hello</s>

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 🎉

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].