summaryrefslogtreecommitdiffstats
path: root/$mmm/plugins/markdown
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2022-05-08 19:14:58 +0000
committers-ol <s+removethis@s-ol.nu>2022-05-20 08:38:41 +0000
commitb615a7cf0fc9d81b4b905a9d4e1db0beebdebd3d (patch)
tree2bf24f2da1aa80df2534637de10e0fe45aeb80f0 /$mmm/plugins/markdown
downloadhw.s-ol.nu-b615a7cf0fc9d81b4b905a9d4e1db0beebdebd3d.tar.gz
hw.s-ol.nu-b615a7cf0fc9d81b4b905a9d4e1db0beebdebd3d.zip
initial commit
Diffstat (limited to '$mmm/plugins/markdown')
-rw-r--r--$mmm/plugins/markdown/converts: text$lua -> table.lua88
-rw-r--r--$mmm/plugins/markdown/converts: text$moonscript -> table.moon67
-rw-r--r--$mmm/plugins/markdown/scripts: text$html+frag.html1
3 files changed, 156 insertions, 0 deletions
diff --git a/$mmm/plugins/markdown/converts: text$lua -> table.lua b/$mmm/plugins/markdown/converts: text$lua -> table.lua
new file mode 100644
index 0000000..5d33b62
--- /dev/null
+++ b/$mmm/plugins/markdown/converts: text$lua -> table.lua
@@ -0,0 +1,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
+ }
+}
diff --git a/$mmm/plugins/markdown/converts: text$moonscript -> table.moon b/$mmm/plugins/markdown/converts: text$moonscript -> table.moon
new file mode 100644
index 0000000..4e0da31
--- /dev/null
+++ b/$mmm/plugins/markdown/converts: text$moonscript -> table.moon
@@ -0,0 +1,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
+ }
+}
diff --git a/$mmm/plugins/markdown/scripts: text$html+frag.html b/$mmm/plugins/markdown/scripts: text$html+frag.html
new file mode 100644
index 0000000..5bfb275
--- /dev/null
+++ b/$mmm/plugins/markdown/scripts: text$html+frag.html
@@ -0,0 +1 @@
+ <script type="text/javascript" src="//unpkg.com/marked@0.7.0/marked.min.js"></script>