developit / snarkdown

:smirk_cat: A snarky 1kb Markdown parser written in JavaScript
http://jsfiddle.net/developit/828w6t1x/
MIT License
2.28k stars 110 forks source link

Sharing Inspiration #66

Open mikesmullin opened 6 years ago

mikesmullin commented 6 years ago

Y'all may be able to appreciate the technique behind my parser which is also minimalist ~1.5KB minified.

It doesn't support all the cases (still need to add image, table, blockquote) but it supported enough to make this full set of documentation, lol:

https://mikesmullin.github.io/m-js/

the secret is between the regex and the reusable chunker() function, also how regex is used by the lexer with special 1-character symbols representing fully parsed tokens.

it parses to JXML instead of HTML but once you understand how simple it is you can see how it would be easy to adapt without adding extra lines.

that is all 🐱 feel free to assimilate any ideas on your quest for a sub-1k parser. thanks for your time.