diff options
| author | s-ol <s+removethis@s-ol.nu> | 2022-03-28 13:58:08 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2022-03-28 14:24:26 +0000 |
| commit | 269d9986c12e277eb6fd5241f34c027c439f84ae (patch) | |
| tree | 748f965272ada1293b5d5f12420f9f7cb069c0fa /root | |
| parent | move layout into user content (diff) | |
| download | mmm-269d9986c12e277eb6fd5241f34c027c439f84ae.tar.gz mmm-269d9986c12e277eb6fd5241f34c027c439f84ae.zip | |
fix plugins in example root
Diffstat (limited to 'root')
11 files changed, 560 insertions, 0 deletions
diff --git a/root/$mmm/plugins/cites/converts: text$lua -> table.lua b/root/$mmm/plugins/cites/converts: text$lua -> table.lua new file mode 100644 index 0000000..78dadfc --- /dev/null +++ b/root/$mmm/plugins/cites/converts: text$lua -> table.lua @@ -0,0 +1,142 @@ +local div, span, sup, a, i, b +do + local _obj_0 = require('mmm.dom') + div, span, sup, a, i, b = _obj_0.div, _obj_0.span, _obj_0.sup, _obj_0.a, _obj_0.i, _obj_0.b +end +local parse_bibtex +parse_bibtex = function(src) + local type, key, kv = src:match('@(%w+){(.-),(.*)}') + do + local info = { + _type = type, + _key = key + } + for key, val in kv:gmatch('([a-z]-)%s*=%s*(%b{})') do + val:sub(2, -2) + info[key] = val:gsub('[{}]', '') + end + for key, val in kv:gmatch('([a-z]-)%s*=%s*(%d+)') do + info[key] = val + end + return info + end +end +local title +title = function(self) + assert(self.title, "cite doesn't have title") + local inner = i(self.title) + if self.url then + return a(inner, { + href = self.url, + style = { + display = 'inline' + } + }) + else + return b(inner) + end +end +local format_full +format_full = function(self) + local tt = title(self) + local dot, com + if self.title:match('[.?!]$') then + dot, com = '', '' + else + dot, com = '.', ',' + end + self.author = self.author or 'N. N.' + local _exp_0 = self._type + if 'book' == _exp_0 or 'article' == _exp_0 then + return span((function() + do + local _with_0 = setmetatable({ }, { + __index = table + }) + _with_0:insert(tostring(self.author) .. " (" .. tostring(self.year) .. "), ") + _with_0:insert(tt) + if self.journal then + _with_0:insert(tostring(dot) .. " ") + _with_0:insert(i(self.journal)) + if self.volume then + _with_0:insert(", volume " .. tostring(self.volume)) + end + else + if self.series then + _with_0:insert(tostring(dot) .. " ") + _with_0:insert(i(self.series)) + if self.number then + _with_0:insert(", No. " .. tostring(self.number)) + end + end + end + if self.pages then + _with_0:insert(", pages " .. tostring(self.pages)) + end + if self.publisher then + _with_0:insert(tostring(dot) .. " " .. tostring(self.publisher)) + end + if self.doi then + _with_0:insert(tostring(dot) .. " ") + _with_0:insert(a("doi:" .. tostring(self.doi), { + href = "https://doi.org/" .. tostring(self.doi) + })) + end + return _with_0 + end + end)()) + elseif 'web' == _exp_0 or 'online' == _exp_0 then + return span((function() + do + local _with_0 = setmetatable({ }, { + __index = table + }) + _with_0:insert(tostring(self.author)) + if self.year then + _with_0:insert(" (" .. tostring(self.year) .. ")") + end + _with_0:insert(", ") + _with_0:insert(tt) + _with_0:insert(tostring(com) .. " " .. tostring(self.url)) + if self.visited then + _with_0:insert(" from " .. tostring(self.visited)) + end + return _with_0 + end + end)()) + else + span((function() + do + local _with_0 = setmetatable({ }, { + __index = table + }) + _with_0:insert(tostring(self.author) .. " (" .. tostring(self.year) .. "), ") + _with_0:insert(tt) + if self.publisher then + _with_0:insert(tostring(dot) .. " " .. tostring(self.publisher)) + end + return _with_0 + end + end)()) + return span(tbl) + end +end +return { + { + inp = 'cite/doi', + out = 'URL -> text/bibtex', + cost = 0.1, + transform = function(self, doi) + doi = doi:match('(10%.%d%d%d%d%d?%d?%d?%d?%d?/[%d%w%.%-_:;%(%)]+)') + return "http://api.crossref.org/works/" .. tostring(doi) .. "/transform/application/x-bibtex" + end + }, + { + inp = 'text/bibtex', + out = 'mmm/dom', + cost = 1, + transform = function(self, bib) + return format_full(parse_bibtex(bib)) + end + } +} diff --git a/root/$mmm/plugins/code/converts: text$lua -> table.lua b/root/$mmm/plugins/code/converts: text$lua -> table.lua new file mode 100644 index 0000000..c578a69 --- /dev/null +++ b/root/$mmm/plugins/code/converts: text$lua -> table.lua @@ -0,0 +1,121 @@ +local pre, div, button +do + local _obj_0 = require('mmm.dom') + pre, div, button = _obj_0.pre, _obj_0.div, _obj_0.button +end +local languages +languages = require('mmm.highlighting').languages +local Editor +do + local _class_0 + local o + local _base_0 = { + EDITOR = true, + change = function(self) + self.timeout = nil + local doc = self.cm:getDoc() + if self.lastPreview and doc:isClean(self.lastPreview) then + return + end + self.lastPreview = doc:changeGeneration() + local value = doc:getValue() + self.fileder.facets[self.key] = value + return BROWSER:refresh() + end, + save = function(self, e) + e:preventDefault() + local doc = self.cm:getDoc() + self.fileder:set(self.key, doc:getValue()) + self.lastSave = doc:changeGeneration(true) + end + } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function(self, value, mode, fileder, key) + self.fileder, self.key = fileder, key + self.node = div({ + class = 'editor' + }) + do + local _with_0 = button('save') + _with_0.disabled = true + _with_0.onclick = function(_, e) + return self:save(e) + end + self.saveBtn = _with_0 + end + self.cm = window:CodeMirror(self.node, o({ + value = value, + mode = mode, + lineNumber = true, + lineWrapping = true, + autoRefresh = true, + theme = 'hybrid' + })) + self.lastSave = self.cm:getDoc():changeGeneration(true) + return self.cm:on('changes', function(_, mirr) + local doc = self.cm:getDoc() + self.saveBtn.disabled = doc:isClean(self.lastSave) + if self.timeout then + window:clearTimeout(self.timeout) + end + self.timeout = window:setTimeout((function() + return self:change() + end), 300) + end) + end, + __base = _base_0, + __name = "Editor" + }, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({}, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end + }) + _base_0.__class = _class_0 + local self = _class_0 + if MODE == 'CLIENT' then + 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 + Editor = _class_0 +end +local _ = [[ editors: if MODE == 'CLIENT' then { + { + inp: 'text/([^ ]*).*' + out: 'mmm/dom' + cost: 0 + transform: (value, fileder, key) => + mode = @from\match @convert.inp + Editor value, mode, fileder, key + } + { + inp: 'URL.*' + out: 'mmm/dom' + cost: 0 + transform: (value, fileder, key) => + Editor value, nil, fileder, key + } + } +]] +return { + { + inp = 'text/([^ ]*).*', + out = 'mmm/dom', + cost = 5, + transform = function(self, val) + local lang = self.from:match(self.convert.inp) + return pre(languages[lang](val)) + end + } +} diff --git a/root/$mmm/plugins/code/scripts: text$lua -> fn -> text$html+frag.lua b/root/$mmm/plugins/code/scripts: text$lua -> fn -> text$html+frag.lua new file mode 100644 index 0000000..87a182f --- /dev/null +++ b/root/$mmm/plugins/code/scripts: text$lua -> fn -> text$html+frag.lua @@ -0,0 +1,12 @@ +local tourl +tourl = (require('mmm.mmmfs.util'))({ }).tourl +return function(self) + return "\n <link rel=\"stylesheet\" type=\"text/css\" href=\"" .. tostring(self:gett('style: URL -> text/css')) .. "\" />" .. [[<!-- + <link rel="stylesheet" type="text/css" href="//unpkg.com/codemirror@5.49.2/lib/codemirror.css" /> + <script type="text/javascript" src="//unpkg.com/codemirror@5.49.2/lib/codemirror.js"></script> + <script type="text/javascript" src="//unpkg.com/codemirror@5.49.2/mode/lua/lua.js"></script> + <script type="text/javascript" src="//unpkg.com/codemirror@5.49.2/mode/markdown/markdown.js"></script> + <script type="text/javascript" src="//unpkg.com/codemirror@5.49.2/addon/display/autorefresh.js"></script> +--> + ]] +end diff --git a/root/$mmm/plugins/gltf/converts: text$lua -> table.lua b/root/$mmm/plugins/gltf/converts: text$lua -> table.lua new file mode 100644 index 0000000..5a7869f --- /dev/null +++ b/root/$mmm/plugins/gltf/converts: text$lua -> table.lua @@ -0,0 +1,16 @@ +local dom = require('mmm.dom') +return { + { + inp = 'URL -> model/gltf-binary', + out = 'mmm/dom', + cost = 1, + transform = function(self, href) + return dom['model-viewer']({ + src = href, + ['auto-rotate'] = true, + ['camera-controls'] = true, + ['camera-orbit'] = "548.2deg 117deg 282.4m" + }) + end + } +} 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 "<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/root/$mmm/plugins/mermaid/converts: text$lua -> table.lua b/root/$mmm/plugins/mermaid/converts: text$lua -> table.lua new file mode 100644 index 0000000..1ed7787 --- /dev/null +++ b/root/$mmm/plugins/mermaid/converts: text$lua -> table.lua @@ -0,0 +1,32 @@ +if not (window and window.mermaid) then + return +end +window.mermaid:initialize({ + startOnLoad = false, + fontFamily = 'monospace' +}) +local id_counter = 1 +return { + { + inp = 'text/mermaid-graph', + out = 'mmm/dom', + cost = 1, + transform = function(self, source, fileder, key) + id_counter = id_counter + 1 + local id = "mermaid-" .. tostring(id_counter) + do + local container = document:createElement('div') + local cb + cb = function(self, svg) + container.innerHTML = svg + container.firstElementChild.style.width = '100%' + container.firstElementChild.style.height = 'auto' + end + window:setImmediate(function(_) + return window.mermaid:render(id, source, cb, container) + end) + return container + end + end + } +} diff --git a/root/$mmm/plugins/moonscript/converts: text$lua -> table.lua b/root/$mmm/plugins/moonscript/converts: text$lua -> table.lua new file mode 100644 index 0000000..1ac91b4 --- /dev/null +++ b/root/$mmm/plugins/moonscript/converts: text$lua -> table.lua @@ -0,0 +1,24 @@ +if MODE == 'CLIENT' then + return { } +end +local _, moon = assert(pcall(require, 'moonscript.base')) +local _load = moon.load or moon.loadstring +return { + { + inp = 'text/moonscript -> (.+)', + out = '%1', + cost = 1, + transform = function(self, val, fileder, key) + local func = _load(val, tostring(fileder) .. "#" .. tostring(key)) + return func() + end + }, + { + inp = 'text/moonscript -> (.+)', + out = 'text/lua -> %1', + cost = 2, + transform = function(self, val) + return moon.to_lua(val) + end + } +} diff --git a/root/$mmm/plugins/moonscript/converts: text$moonscript -> table.moon b/root/$mmm/plugins/moonscript/converts: text$moonscript -> table.moon new file mode 100644 index 0000000..2e5652c --- /dev/null +++ b/root/$mmm/plugins/moonscript/converts: text$moonscript -> table.moon @@ -0,0 +1,22 @@ +if MODE == 'CLIENT' + return {} + +_, moon = assert pcall require, 'moonscript.base' +_load = moon.load or moon.loadstring + +{ + { + inp: 'text/moonscript -> (.+)', + out: '%1', + cost: 1 + transform: (val, fileder, key) => + func = _load val, "#{fileder}##{key}" + func! + }, + { + inp: 'text/moonscript -> (.+)', + out: 'text/lua -> %1', + cost: 2 + transform: (val) => moon.to_lua val + }, +} diff --git a/root/$mmm/plugins/sass/converts: text$lua -> table.lua b/root/$mmm/plugins/sass/converts: text$lua -> table.lua new file mode 100644 index 0000000..f2887e3 --- /dev/null +++ b/root/$mmm/plugins/sass/converts: text$lua -> table.lua @@ -0,0 +1,54 @@ +if MODE == 'CLIENT' then + return { } +end +local posix = require('posix') +return { + { + inp = 'text/x-scss', + out = 'text/css', + cost = 1, + transform = function(self, content) + local r0, w0 = posix.pipe() + local r1, w1 = posix.pipe() + local r2, w2 = posix.pipe() + local pid = assert(posix.fork()) + if pid == 0 then + posix.close(w0) + posix.close(r1) + posix.close(r2) + posix.dup2(r0, posix.fileno(io.stdin)) + posix.dup2(w1, posix.fileno(io.stdout)) + posix.dup2(w2, posix.fileno(io.stderr)) + posix.close(r0) + posix.close(w1) + posix.close(w2) + local err = assert(posix.execp('sassc', '-s')) + posix._exit(err) + return + else + posix.close(r0) + posix.close(w1) + posix.close(w2) + posix.write(w0, content) + posix.close(w0) + local _, status + _, _, status = posix.wait(pid) + local out + if status == 0 then + out = r1 + else + out = r2 + end + out = assert(posix.fdopen(out, 'r')) + out = out:read('a') + posix.close(r1) + posix.close(r2) + if status == 0 then + return out + else + return error(out) + end + end + end + } +} diff --git a/root/$mmm/plugins/twitter/converts: text$lua -> table.lua b/root/$mmm/plugins/twitter/converts: text$lua -> table.lua new file mode 100644 index 0000000..58ce663 --- /dev/null +++ b/root/$mmm/plugins/twitter/converts: text$lua -> table.lua @@ -0,0 +1,25 @@ +local div, blockquote, a +do + local _obj_0 = require('mmm.dom') + div, blockquote, a = _obj_0.div, _obj_0.blockquote, _obj_0.a +end +local iframe +iframe = require('mmm.dom').iframe +return { + { + inp = 'URL -> twitter/tweet', + out = 'mmm/dom', + cost = -4, + transform = function(self, href) + local user, id = assert((href:match('twitter.com/([^/]-)/status/(%d*)')), "couldn't parse twitter/tweet URL: '" .. tostring(href) .. "'") + return iframe({ + width = 550, + height = 560, + border = 0, + frameBorder = 0, + allowfullscreen = true, + src = "//twitframe.com/show?url=https%3A%2F%2Ftwitter.com%2F" .. tostring(user) .. "%2F" .. tostring(id) + }) + end + } +} diff --git a/root/$mmm/plugins/youtube/converts: text$lua -> table.lua b/root/$mmm/plugins/youtube/converts: text$lua -> table.lua new file mode 100644 index 0000000..de5b8a8 --- /dev/null +++ b/root/$mmm/plugins/youtube/converts: text$lua -> table.lua @@ -0,0 +1,24 @@ +local iframe +iframe = require('mmm.dom').iframe +return { + { + inp = 'URL -> youtube/video', + out = 'mmm/dom', + cost = -4, + transform = function(self, link) + local id = link:match('youtu%.be/([^/]+)') + id = id or link:match('youtube.com/watch.*[?&]v=([^&]+)') + id = id or link:match('youtube.com/[ev]/([^/]+)') + id = id or link:match('youtube.com/embed/([^/]+)') + assert(id, "couldn't parse youtube URL: '" .. tostring(link) .. "'") + return iframe({ + width = 560, + height = 315, + border = 0, + frameborder = 0, + allowfullscreen = true, + src = "//www.youtube.com/embed/" .. tostring(id) + }) + end + } +} |
