From 269d9986c12e277eb6fd5241f34c027c439f84ae Mon Sep 17 00:00:00 2001 From: s-ol Date: Mon, 28 Mar 2022 15:58:08 +0200 Subject: fix plugins in example root --- .../markdown/converts: text$lua -> table.lua | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 root/$mmm/plugins/markdown/converts: text$lua -> table.lua (limited to 'root/$mmm/plugins/markdown') diff --git a/root/$mmm/plugins/markdown/converts: text$lua -> table.lua b/root/$mmm/plugins/markdown/converts: text$lua -> table.lua new file mode 100644 index 0000000..5d33b62 --- /dev/null +++ b/root/$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 "
" .. tostring(markdown(md)) .. "
" + end + }, + { + inp = 'text/markdown%+sidenotes', + out = 'text/html+frag', + cost = 1, + transform = function(self, md) + return "
" .. tostring(markdown(md)) .. "
" + end + }, + { + inp = 'text/markdown%+wide', + out = 'text/html+frag', + cost = 1, + transform = function(self, md) + return "
" .. tostring(markdown(md)) .. "
" + end + }, + { + inp = 'text/markdown%+span', + out = 'text/html+frag', + cost = 1, + transform = function(self, source) + local html = markdown(source) + html = html:gsub('^%s*

%s*', '') + html = html:gsub('%s*

%s*$', '') + return html + end + } +} -- cgit v1.2.3