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
|
markdown = if MODE == 'SERVER'
success, discount = pcall require, 'discount'
assert success, "couldn't require 'discount'"
(md) ->
res = assert discount.compile md, 'githubtags', 'fencedcode'
res.body
else
assert window and window.marked, "marked.js not found"
o = do
mkobj = window\eval "(function () { return {}; })"
(tbl) ->
with obj = mkobj!
for k,v in pairs(tbl)
obj[k] = v
trim = (str) -> str\match '^ *(..-) *$'
window.marked\setOptions o {
gfm: true
smartypants: true
langPrefix: 'lang-'
highlight: (code, lang) =>
code = trim code
result = if lang and #lang > 0
window.hljs\highlight lang, code, true
else
window.hljs\highlightAuto code
result.value
}
window\marked
assert markdown, "no markdown implementation found"
{
{
inp: 'text/markdown'
out: 'text/html+frag'
cost: 1
transform: (md) => "<div class=\"markdown\">#{markdown md}</div>"
}
{
inp: 'text/markdown%+sidenotes'
out: 'text/html+frag'
cost: 1
transform: (md) => "<div class=\"markdown sidenote-container\">#{markdown md}</div>"
}
{
inp: 'text/markdown%+wide'
out: 'text/html+frag'
cost: 1
transform: (md) => "<div class=\"markdown wide\">#{markdown md}</div>"
}
{
inp: 'text/markdown%+span'
out: 'text/html+frag'
cost: 1
transform: (source) =>
html = markdown source
html = html\gsub '^%s*<p>%s*', '<span>'
html = html\gsub '%s*</p>%s*$', '</span>'
html
}
}
|