Skip to content

Commit 38bda44

Browse files
committed
Update .js files for markdown rendering:
- Add comments in each file indicatint where the original copy come frome, what is the version, our customizations, etc. - Use eslint with es5 plugin and update: markdown-it-toc.js markdown-it-mathjax.js markdown-it-ins-del.js md.js - Use Babel to convert ES6 scirpts to ES5: markdown-it-highlightjs.js - Add `.eslintrc.js`.
1 parent 05be3b3 commit 38bda44

File tree

9 files changed

+655
-597
lines changed

9 files changed

+655
-597
lines changed

.eslintrc.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
"plugins" : ["es5"],
3+
"extends" : "eslint:recommended",
4+
"rules": {
5+
"indent": ["error", 4],
6+
"linebreak-style": ["error", "unix"],
7+
"quotes": ["error", "double"],
8+
"semi": ["error", "always"],
9+
"no-undef": 1,
10+
"no-useless-escape": 1,
11+
"no-unused-vars": 1,
12+
"no-redeclare": 1
13+
},
14+
"env": {
15+
"browser": true,
16+
},
17+
}
18+
Lines changed: 69 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,72 @@
1-
;(function (root, factory) {
2-
if (typeof exports === 'object') {
3-
module.exports = factory()
4-
} else {
5-
root.markdownitHightlightjs = factory()
6-
}
7-
})(this, function () {
1+
/**
2+
* Preset to use highlight.js with markdown-it.
3+
*
4+
* Original Copy: https://github.com/valeriangalliat/markdown-it-highlightjs/tree/v3.0.0/index.js
5+
* The above link gives a 404. Here is my forked copy and Babel-converted ES5 version:
6+
* (ES6) https://github.com/cslzchen/markdown-it-highlightjs/blob/release/3.0.0/index.js
7+
* (ES5) https://github.com/cslzchen/markdown-it-highlightjs/blob/release/3.0.0/index.es5.js
8+
* Version: https://github.com/valeriangalliat/markdown-it-highlightjs/releases/tag/v3.0.0
9+
* Changes: 1. Use https://babeljs.io/repl/ to convert ES6 to ES5, 2. Use `window` instead of `require`
10+
*/
811

9-
const maybe = f => {
10-
try {
11-
return f()
12-
} catch (e) {
13-
return false
14-
}
15-
}
16-
17-
// Highlight with given language.
18-
const highlight = (code, lang) =>
19-
maybe(() => hljs.highlight(lang, code, true).value) || ''
20-
21-
// Highlight with given language or automatically.
22-
const highlightAuto = (code, lang) =>
23-
lang
24-
? highlight(code, lang)
25-
: maybe(() => hljs.highlightAuto(code).value) || ''
26-
27-
// Wrap a render function to add `hljs` class to code blocks.
28-
const wrap = render =>
29-
function (...args) {
30-
return render.apply(this, args)
31-
.replace('<code class="', '<code class="hljs ')
32-
.replace('<code>', '<code class="hljs">')
33-
}
34-
var defaults = {
35-
auto: true,
36-
code: true
37-
}
38-
39-
return function(md, opts){
40-
opts = Object.assign({}, defaults, opts)
41-
42-
md.options.highlight = opts.auto ? highlightAuto : highlight
43-
md.renderer.rules.fence = wrap(md.renderer.rules.fence)
44-
45-
if (opts.code) {
46-
md.renderer.rules.code_block = wrap(md.renderer.rules.code_block)
12+
(function (root, factory) {
13+
if (typeof exports === "object") {
14+
module.exports = factory();
15+
} else {
16+
root.markdownitHightlightjs = factory();
4717
}
48-
}
18+
})(this, function () {
19+
20+
"use strict";
21+
22+
var maybe = function maybe(f) {
23+
try {
24+
return f();
25+
} catch (e) {
26+
return false;
27+
}
28+
};
29+
30+
// Highlight with given language.
31+
var highlight = function highlight(code, lang) {
32+
return maybe(function () {
33+
return hljs.highlight(lang, code, true).value;
34+
}) || "";
35+
};
36+
37+
// Highlight with given language or automatically.
38+
var highlightAuto = function highlightAuto(code, lang) {
39+
return lang ? highlight(code, lang) : maybe(function () {
40+
return hljs.highlightAuto(code).value;
41+
}) || "";
42+
};
43+
44+
// Wrap a render function to add `hljs` class to code blocks.
45+
var wrap = function wrap(render) {
46+
return function () {
47+
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
48+
args[_key] = arguments[_key];
49+
}
50+
51+
return render.apply(this, args).replace("<code class=\"", "<code class=\"hljs ").replace("<code>", "<code class=\"hljs\">");
52+
};
53+
};
54+
55+
var defaults = {
56+
auto: true,
57+
code: true
58+
};
59+
60+
return function(md, opts) {
61+
62+
opts = Object.assign({}, defaults, opts);
63+
64+
md.options.highlight = opts.auto ? highlightAuto : highlight;
65+
md.renderer.rules.fence = wrap(md.renderer.rules.fence);
66+
67+
if (opts.code) {
68+
md.renderer.rules.code_block = wrap(md.renderer.rules.code_block);
69+
}
70+
};
4971

50-
})
72+
});

0 commit comments

Comments
 (0)