/miniMarkdown

An easy to extend parser for a subset of markdown

Primary LanguageJavaScriptMIT LicenseMIT

miniMarkdown

^ Markdown

An easy to extend parser for a subset of markdown.

travis js-standard-style

Markdown support

miniMarkdown supports:

  • ```pre```
  • `code`
  • _Italics_
  • *Bold*
  • ~Strike~

You can easily add more grammar to make your own extensions

API

To run with the default grammar:

let miniMarkdown = require('miniMarkdown');
let text = 'this *is* an _example_';
let grammar = miniMarkdown.DEFAULT_GRAMMAR;
let tokenizer = new miniMarkdown.Tokenizer(text, grammar);

tokenizer.run();
=> [
     {type: 'word', text: 'this '}
   , {type: 'bold', children: [{type: 'word', text: 'is'}]}
   , {type: 'word', text: ' an '}
   , {type: 'italic', children: [{type: 'word', text: 'example'}]}
   ]

If you are interested into adding more grammar you can also do so!

TokenType offers you an API to define grammar:

  • start: The string that defines the beggining of a token.
  • end: The string that defines the ending of a token.
  • surround: When both start and end delimiters are the same you can use this instead.
  • grammar: If you want a different grammar for a given token.
  • constraint: If you want to validate whether the token is valid before pushing it to the tree.

You can see grammar examples on the spec/grammar_spec.js test file.

TEST

To test just run npm test