smarked
I really just wanted a few simple markdown rendering features and at
same time feel uncomfortable and frankly somewhat stupid trying to
render HTML via innerHTML. Instead I just create elements with
document.createElement
calls while recursively walking the
tree of tokens given by marked. I don’t support tables (right now).
The default export you’re looking for is called
mdToElements
.
The first argument, a markdown formatted string, is required.
The second argument is optional, and should be a
languageRenderer
function; it should be able to take a
language name string as first arg to indicate the programming language
of the second string, and it should return an array of elements to be
appended to a div. This latter languageRenderer feature is like for
syntax highlighting code within fenced code blocks.
If you require 100% standards-compliance probably this isn’t what you’re looking for. Mainly this is like if you need a quick and dirty markdown renderer with the essential features that works in the browser.
Example:
# Hello World
## Hello World
### Hello World
#### Hello World
##### Hello World
* Hello World
* Hello World2
* snajsns
* oh wow
1. Oosa
2. TwOsa
3. Three
Hello thete, World! *Glad* to see **you**!
> Quote this, eggman
~~~javascript
function fakeCode(arg){
return "wrong answer"
}~~~
`function`'s name is freddy
My favorite
***
~~stricken down~~
## halp
* hello
* dubious news
* huffulous clues
Hi, mya hihi
Produces: