Skip to content

Commit 0911450

Browse files
committed
Add static js and css for markdownit and plugins
- MFR uses the same markdown-it.js and its plugins as OSF for rendering MD. However, due to lack of package managing and Babel, all full scripts are manually eslinted and babeled if necessary. .min scripts are kept intact.
1 parent 681a0ce commit 0911450

File tree

8 files changed

+851
-0
lines changed

8 files changed

+851
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@charset "utf-8";
2+
3+
.mfrViewer {
4+
font-family: 'Open Sans';
5+
padding: 1em;
6+
background: #fefefe;
7+
height: auto;
8+
word-wrap: break-word;
9+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* Original highlight.js style (c) Ivan Sagalaev <[email protected]>
3+
*
4+
* https://github.com/isagalaev/highlight.js/blob/9.12.0/src/styles/default.css
5+
*/
6+
7+
.hljs {
8+
display: block;
9+
overflow-x: auto;
10+
padding: 0.5em;
11+
background: #F0F0F0;
12+
}
13+
14+
15+
/* Base color: saturation 0; */
16+
17+
.hljs,
18+
.hljs-subst {
19+
color: #444;
20+
}
21+
22+
.hljs-comment {
23+
color: #888888;
24+
}
25+
26+
.hljs-keyword,
27+
.hljs-attribute,
28+
.hljs-selector-tag,
29+
.hljs-meta-keyword,
30+
.hljs-doctag,
31+
.hljs-name {
32+
font-weight: bold;
33+
}
34+
35+
36+
/* User color: hue: 0 */
37+
38+
.hljs-type,
39+
.hljs-string,
40+
.hljs-number,
41+
.hljs-selector-id,
42+
.hljs-selector-class,
43+
.hljs-quote,
44+
.hljs-template-tag,
45+
.hljs-deletion {
46+
color: #880000;
47+
}
48+
49+
.hljs-title,
50+
.hljs-section {
51+
color: #880000;
52+
font-weight: bold;
53+
}
54+
55+
.hljs-regexp,
56+
.hljs-symbol,
57+
.hljs-variable,
58+
.hljs-template-variable,
59+
.hljs-link,
60+
.hljs-selector-attr,
61+
.hljs-selector-pseudo {
62+
color: #BC6060;
63+
}
64+
65+
66+
/* Language color: hue: 90; */
67+
68+
.hljs-literal {
69+
color: #78A960;
70+
}
71+
72+
.hljs-built_in,
73+
.hljs-bullet,
74+
.hljs-code,
75+
.hljs-addition {
76+
color: #397300;
77+
}
78+
79+
80+
/* Meta color: hue: 200 */
81+
82+
.hljs-meta {
83+
color: #1f7199;
84+
}
85+
86+
.hljs-meta-string {
87+
color: #4d99bf;
88+
}
89+
90+
91+
/* Misc effects */
92+
93+
.hljs-emphasis {
94+
font-style: italic;
95+
}
96+
97+
.hljs-strong {
98+
font-weight: bold;
99+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* Preset to use highlight.js with markdown-it.
3+
*
4+
* Origin: https://github.com/valeriangalliat/markdown-it-highlightjs/tree/v3.0.0/index.js
5+
* The above link gives a 404. Here is a 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+
*
9+
* Version: https://github.com/valeriangalliat/markdown-it-highlightjs/releases/tag/v3.0.0
10+
*/
11+
12+
(function (root, factory) {
13+
if (typeof exports === "object") {
14+
module.exports = factory();
15+
} else {
16+
root.markdownitHightlightjs = factory();
17+
}
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+
};
71+
72+
});

0 commit comments

Comments
 (0)