Skip to content

Commit add9bbd

Browse files
Removing bundle and reworking
Instead of bundling up assets, serve the smaller ones. Larger ones can be loaded from cdn.
1 parent c5adba2 commit add9bbd

File tree

12 files changed

+8695
-25753
lines changed

12 files changed

+8695
-25753
lines changed

mfr/extensions/md/render.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
import os
22

33
import bleach
4-
# import markdown
5-
# from markdown.extensions import Extension
6-
74
from mako.lookup import TemplateLookup
85

96
from mfr.core import extension
107

118

12-
# class EscapeHtml(Extension):
13-
# def extendMarkdown(self, md, md_globals):
14-
# del md.preprocessors['html_block']
15-
# del md.inlinePatterns['html']
16-
17-
189
class MdRenderer(extension.BaseRenderer):
1910

2011
TEMPLATE = TemplateLookup(
@@ -24,7 +15,6 @@ class MdRenderer(extension.BaseRenderer):
2415

2516
def __init__(self, *args, **kwargs):
2617
super().__init__(*args, **kwargs)
27-
# self.metrics.add('markdown_version', markdown.version)
2818

2919
def render(self):
3020
"""Render a markdown file to html."""
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
;(function (root, factory) {
2+
if (typeof exports === 'object') {
3+
module.exports = factory()
4+
} else {
5+
root.markdownitHightlightjs = factory()
6+
}
7+
})(this, function () {
8+
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)
47+
}
48+
}
49+
50+
})

0 commit comments

Comments
 (0)