Skip to content

estrattonbailey/snarkdown

 
 

Repository files navigation

Snarkdown

Snarkdown
npm travis

Snarkdown is a dead simple 1kb Markdown parser.

It's designed to be as minimal as possible, for constrained use-cases where a full Markdown parser would be inappropriate.

Features

  • Fast: since it's basically one regex and a huge if statement
  • Tiny: it's 1kb of gzipped ES3
  • Simple: pass a Markdown string, get back an HTML string

Notes: Tables are not yet supported. If you love impossible to read regular expressions, submit a PR!

Demos & Examples

Usage

Snarkdown exports a single function, which parses a string of Markdown and returns a String of HTML. Couldn't be simpler.

The snarkdown module is available in every module format you'd ever need: ES Modules, CommonJS, UMD...

import snarkdown from 'snarkdown';

let md = '_this_ is **easy** to `use`.';
let html = snarkdown(md);
console.log(html);
// <em>this</em> is <strong>easy</strong> to <code>use</code>.

Options

Snarkdown also accepts an optional options object.

options.highlight

Highlight code blocks when parsed. Accepts a function with the signature hightlight(code, language). Return a highlighted string using the library or your choice.

import snarkdown from 'snarkdown'
import prism from 'prismjs'

let md = '```javascript \n let md = "a javascript code block";```'
let html = snarkdown(md, {
  highlight: (code, language) => {
    return prism.highlight(code, prism.languages[language])
  }
});

License

MIT

About

😼 A snarky 1kb Markdown parser written in JavaScript

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • JavaScript 100.0%