1 | var marked = require('./marked');
|
2 | var babel = require('babel-core');
|
3 | var renderer = new marked.Renderer();
|
4 | var yamlFront = require('yaml-front-matter');
|
5 |
|
6 | var highlightjs = require('highlight.js');
|
7 |
|
8 | var res = void 0;
|
9 | var id = void 0;
|
10 |
|
11 | function escape(html, encode) {
|
12 | return html.replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
13 | }
|
14 |
|
15 | function unescape(html) {
|
16 |
|
17 | return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function (_, n) {
|
18 | n = n.toLowerCase();
|
19 | if (n === 'colon') return ':';
|
20 | if (n.charAt(0) === '#') {
|
21 | return n.charAt(1) === 'x' ? String.fromCharCode(parseInt(n.substring(2), 16)) : String.fromCharCode(+n.substring(1));
|
22 | }
|
23 | return '';
|
24 | });
|
25 | }
|
26 |
|
27 | renderer.code = function (code, language, escaped) {
|
28 | res = code;
|
29 |
|
30 | var validLang = !!(language && highlightjs.getLanguage(language));
|
31 |
|
32 | var highlighted = validLang ? highlightjs.highlight(language, code).value : code;
|
33 |
|
34 | return '<div> <div id=' + id + '></div><pre><code class="hljs ' + language + '">' + highlighted + '</code></pre></div>';
|
35 | };
|
36 |
|
37 | renderer.table = function (header, body) {
|
38 | return '<table class="table table-striped">' + header + body + '</table>';
|
39 | };
|
40 |
|
41 | renderer.list = function (body, ordered) {
|
42 | var type = ordered ? 'ol' : 'ul';
|
43 | var styles = ordered ? 'upper-roman' : 'disc';
|
44 | return '<' + type + ' style="padding-left:40px; list-style-type:' + styles + ';" >\n' + body + '</' + type + '>\n';
|
45 | };
|
46 |
|
47 | function process(source) {
|
48 | source = marked(source, {
|
49 | renderer: renderer,
|
50 | gfm: true,
|
51 | tables: true,
|
52 | breaks: true,
|
53 | pedantic: false,
|
54 | sanitize: true,
|
55 | smartLists: true,
|
56 | smartypants: false
|
57 | });
|
58 |
|
59 | var res = JSON.stringify(source);
|
60 | return res;
|
61 | }
|
62 |
|
63 | module.exports = function (source, map) {
|
64 | this.cacheable && this.cacheable();
|
65 |
|
66 | res = '';
|
67 | id = 'comp' + Math.random();
|
68 | var yaml = yamlFront.loadFront(source, 'content');
|
69 |
|
70 | var md = process(yaml.content);
|
71 | res += '\n export const md=' + md + '; \n export const id="' + id + '";';
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | this.callback(null, res, map);
|
77 | };
|
78 | ;
|
79 |
|
80 | var _temp = function () {
|
81 | if (typeof __REACT_HOT_LOADER__ === 'undefined') {
|
82 | return;
|
83 | }
|
84 |
|
85 | __REACT_HOT_LOADER__.register(renderer, 'renderer', 'src/md-loader.js');
|
86 |
|
87 | __REACT_HOT_LOADER__.register(res, 'res', 'src/md-loader.js');
|
88 |
|
89 | __REACT_HOT_LOADER__.register(id, 'id', 'src/md-loader.js');
|
90 |
|
91 | __REACT_HOT_LOADER__.register(escape, 'escape', 'src/md-loader.js');
|
92 |
|
93 | __REACT_HOT_LOADER__.register(unescape, 'unescape', 'src/md-loader.js');
|
94 |
|
95 | __REACT_HOT_LOADER__.register(process, 'process', 'src/md-loader.js');
|
96 | }();
|
97 |
|
98 | ; |
\ | No newline at end of file |