1 | var markit = require('markit');
|
2 | var colors = require('ansicolors');
|
3 | var styles = require('ansistyles');
|
4 |
|
5 | var allElements = [
|
6 | 'blockcode', 'blockhtml', 'blockquote', 'codespan', 'emphasis',
|
7 | 'header', 'hrule', 'image', 'linebreak', 'link', 'list', 'listitem',
|
8 | 'paragraph', 'strikethrough', 'strong', 'table', 'tablecell', 'tablerow'];
|
9 |
|
10 | exports.fromMarkdown = function(markdown) {
|
11 |
|
12 | var r = new markit.Renderer();
|
13 |
|
14 |
|
15 | allElements.forEach(function(e) {
|
16 | r[e] = function() { return ''; }
|
17 | });
|
18 |
|
19 |
|
20 | r.paragraph = function(text) {
|
21 | return text;
|
22 | };
|
23 |
|
24 |
|
25 | r.list = function(body, ordered) {
|
26 | return body + '\n';
|
27 | }
|
28 |
|
29 | r.listitem = function(text) {
|
30 | return ' ' + styles.italic(styles.bright(text)) + '\n';
|
31 | };
|
32 |
|
33 |
|
34 | r.header = function(text, level) {
|
35 | if (level == 2) {
|
36 | return colors.green(' - ' + text) + '\n';
|
37 | } else {
|
38 | return '';
|
39 | }
|
40 | };
|
41 |
|
42 |
|
43 | r.codespan = function(code, lang) {
|
44 | return ' ' + colors.white(' ' + colors.bgBlack(code)) + '\n\n';
|
45 | };
|
46 |
|
47 | return markit(markdown, {renderer: r});
|
48 | };
|