1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
local markdown
if MODE == 'SERVER' then
local success, discount = pcall(require, 'discount')
assert(success, "couldn't require 'discount'")
markdown = function(md)
local res = assert(discount.compile(md, 'githubtags', 'fencedcode'))
return res.body
end
else
assert(window and window.marked, "marked.js not found")
local o
do
local mkobj = window:eval("(function () { return {}; })")
o = function(tbl)
do
local obj = mkobj()
for k, v in pairs(tbl) do
obj[k] = v
end
return obj
end
end
end
local trim
trim = function(str)
return str:match('^ *(..-) *$')
end
window.marked:setOptions(o({
gfm = true,
smartypants = true,
langPrefix = 'lang-',
highlight = function(self, code, lang)
code = trim(code)
local result
if lang and #lang > 0 then
result = window.hljs:highlight(lang, code, true)
else
result = window.hljs:highlightAuto(code)
end
return result.value
end
}))
do
local _base_0 = window
local _fn_0 = _base_0.marked
markdown = function(...)
return _fn_0(_base_0, ...)
end
end
end
assert(markdown, "no markdown implementation found")
return {
{
inp = 'text/markdown',
out = 'text/html+frag',
cost = 1,
transform = function(self, md)
return "<div class=\"markdown\">" .. tostring(markdown(md)) .. "</div>"
end
},
{
inp = 'text/markdown%+sidenotes',
out = 'text/html+frag',
cost = 1,
transform = function(self, md)
return "<div class=\"markdown sidenote-container\">" .. tostring(markdown(md)) .. "</div>"
end
},
{
inp = 'text/markdown%+wide',
out = 'text/html+frag',
cost = 1,
transform = function(self, md)
return "<div class=\"markdown wide\">" .. tostring(markdown(md)) .. "</div>"
end
},
{
inp = 'text/markdown%+span',
out = 'text/html+frag',
cost = 1,
transform = function(self, source)
local html = markdown(source)
html = html:gsub('^%s*<p>%s*', '<span>')
html = html:gsub('%s*</p>%s*$', '</span>')
return html
end
}
}
|