tinymd
v1.0.1
Published
Tiny markdown processor
Downloads
821
Maintainers
Readme
tinymd 💃
Why
All other solutions were either too large to be used in webapps where bundle size is important or too constraint (like missing support for paragraphs or nested lists).
Tinymd tries to strike a good balance between size and features. It's fully tested and works in browsers as well as in Node.
The underlying parsing alorithm is heavily based on Vladimir Antonov's nano-markdown implementation.
Basic Usage
import tinymd from 'tinymd';
const opts = {};
const html = tinymd('', opts);
Supported markdown syntax
# tinymd
supports ...
* lists
- nested lists
1. ordered
2. with [links](http://example.com)
- ![images](/cat.jpg)
- rulers
----
All ~~common~~ **inline** _styles_
code blocks
rulers
And \[escaping]\(of special chars).
Options
Target _blank
By default all links starting with +
will get target="_blank"
attribute. You can customize this behavior by providing an isBlank
function:
tinynmd('[link](http://example.com)', {
isBlank: ref => ~ref.indexOf('://')
}
};
Rewriting URLs
You can rewrite all links and image sources by providing a rewrite
function:
tinynmd('[Issue 42](#42)', {
rewrite: s => {
const m = /^#(\d+)/.exec(s);
return m ? `/issue${m[1]}` : s;
}
};
Adding headline anchors
tinynmd('# hello world', { addIds: true });
// <h1 id="hello_world">hello world</h1>
License
MIT