git.s-ol.nu mmm / a403851
cites plugin s-ol 1 year, 11 months ago
11 changed file(s) with 117 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
9898
9999 switch method
100100 when 'GET', 'HEAD'
101 fileder = Fileder @store, path
101 root = Fileder @store
102 export BROWSER
103 BROWSER = :root
104 fileder = root\walk path -- Fileder @store, path
105
102106 if not fileder
103107 -- fileder not found
104108 return 404, "fileder '#{path}' not found"
0 import div, i from require 'mmm.dom'
1
2 {
3 converts: {
4 {
5 inp: 'URL -> cite/acm'
6 out: 'URL -> text/bibtex'
7 cost: 0.5
8 transform: (url) =>
9 id = assert (url\match '//dl%.acm%.org/citation%.cfm%?id=(%d+)'), "couldn't parse cite/acm URL: '#{url}'"
10 "https://cors-anywhere.herokuapp.com/https://dl.acm.org/exportformats.cfm?id=#{id}&expformat=bibtex"
11 }
12 {
13 inp: 'text/bibtex'
14 out: 'mmm/dom'
15 cost: 1
16 transform: (src) =>
17 type, key, kv = src\match '@(%w+){(.-),(.*)}'
18 info = {}
19 for key, val in kv\gmatch '([a-z]-)%s*=%s*{(.-)}'
20 info[key] = val
21
22 div "#{info.author} (#{info.year}),", (i info.title), ". #{info.publisher}"
23 }
24 }
25 }
9494 when 'facet' then facet = val
9595 when 'nolink' then opts.nolink = true
9696 when 'inline' then opts.inline = true
97 when 'raw' then opts.raw = true
9798 else warn "unkown attribute '#{key}=\"#{val}\"' in <mmm-embed>"
9899
99100 embed path, facet, fileder, opts
112113 facet = js_fix element\getAttribute 'facet'
113114 nolink = js_fix element\getAttribute 'nolink'
114115 inline = js_fix element\getAttribute 'inline'
116 raw = js_fix element\getAttribute 'raw'
115117 desc = js_fix element.innerText
116118 desc = nil if desc == ''
117119
118 element\replaceWith embed path or '', facet or '', fileder, { :nolink, :inline, :desc }
120 opts = :nolink, :inline, :raw, :desc
121 element\replaceWith embed path or '', facet or '', fileder, opts
119122
120123 embeds = \getElementsByTagName 'mmm-link'
121124 embeds = [embeds[i] for i=0, embeds.length - 1]
181184 -- transform: single code
182185 -- }
183186 {
187 inp: 'URL -> (.+)',
188 out: '%1',
189 cost: 4,
190 transform: do
191 if MODE == 'CLIENT'
192 (uri) =>
193 request = js.new js.global.XMLHttpRequest
194 request\open 'GET', uri, false
195 request\send js.null
196
197 assert request.status == 200, "unexpected status code: #{request.status}"
198 request.responseText
199 else
200 (uri) =>
201 request = require 'http.request'
202 req = request.new_from_uri uri
203 headers, stream = req\go 8
204 assert stream\get_body_as_string!
205 }
206 {
184207 inp: '(.+)',
185208 out: 'URL -> %1',
186209 cost: 5
237260 add_converts 'mermaid'
238261 add_converts 'twitter'
239262 add_converts 'youtube'
263 add_converts 'cites'
240264
241265 if MODE == 'SERVER'
242266 ok, moon = pcall require, 'moonscript.base'
1111 (elements) ->
1212 import a, div, span, pre from elements
1313
14 find_fileder = (fileder, origin) ->
14 find_fileder = (fileder, origin) ->
1515 if 'string' == type fileder
16 if '/' == fileder\sub 1, 1
16 if '/' ~= fileder\sub 1, 1
17 assert origin, "cannot resolve relative path '#{fileder}' without origin!"
18 fileder = "#{origin.path}/#{fileder}"
19
20 fileder = fileder\gsub '/([^/]-)/%.%./', '/'
21 if origin.path == fileder\sub 1, #origin.path
22 assert (origin\walk fileder), "couldn't resolve path '#{fileder}' from #{origin}"
23 else
1724 assert BROWSER and BROWSER.root, "cannot resolve absolute path '#{fileder}' without BROWSER and root set!"
1825 assert (BROWSER.root\walk fileder), "couldn't resolve path '#{fileder}'"
19 else
20 assert origin, "cannot resolve relative path '#{fileder}' without origin!"
21 assert (origin\walk fileder), "couldn't resolve path '#{fileder}' from #{origin}"
26
27 -- if 'string' == type fileder
28 -- if '/' == fileder\sub 1, 1
29 -- fileder = fileder\gsub '/([^/]-)/%.%./', '/'
30 -- assert BROWSER and BROWSER.root, "cannot resolve absolute path '#{fileder}' without BROWSER and root set!"
31 -- assert (BROWSER.root\walk fileder), "couldn't resolve path '#{fileder}'"
32 -- else
33 -- assert origin, "cannot resolve relative path '#{fileder}' without origin!"
34 -- fileder = "#{origin.path}/#{fileder}"
35 -- fileder = fileder\gsub '/([^/]-)/%.%./', '/'
36 -- if origin.path == fileder\sub 1, #origin.path
37 -- assert (origin\walk fileder), "couldn't resolve path '#{fileder}' from #{origin}"
38 -- else
39 -- assert BROWSER and BROWSER.root, "cannot resolve absolute path '#{fileder}' without BROWSER and root set!"
40 -- assert (BROWSER.root\walk fileder), "couldn't resolve path '#{fileder}'"
41
2242 else
2343 assert fileder, "no fileder passed."
2444
5272 ok, node = pcall fileder.gett, fileder, name, 'mmm/dom'
5373
5474 if not ok
55 return span "couldn't embed #{fileder} #{name}",
56 (pre node),
57 class: 'embed'
58 style: {
59 background: 'var(--gray-fail)',
60 padding: '1em',
61 }
75 warn "couldn't embed #{fileder} #{name}: #{node}"
76 return span {
77 class: 'embed'
78 style:
79 background: 'var(--gray-fail)'
80 padding: '1em'
81
82 "couldn't embed #{fileder} #{name}"
83 (pre node)
84 }
85
86 return node if opts.raw
6287
6388 klass = 'embed'
6489 klass ..= ' desc' if opts.desc
22 framework
33 mmmfs
44 evaluation
5 references
65 ba_log
76 examples
7 references
+0
-0
root/articles/mmmfs/references/text$markdown.md less more
(Empty file)
0 =>
1 html = require 'mmm.dom'
2 import ol, li from html
3
4 ol for ref in *@children
5 li ref\gett 'mmm/dom'
0 https://dl.acm.org/citation.cfm?id=577766
0 https://dl.acm.org/citation.cfm?id=66894
66 .markdown {
77 max-width: 640px;
88 position: relative;
9
10 &.wide {
11 max-width: max-content;
12 }
13
14 > blockquote {
15 @include left-border;
16
17 margin: 1rem var(--margin-wide);
18 padding: 1rem;
19 background: $gray-bright;
20 border-color: $gray-neutral;
21 }
922 }
1023
1124 .markdown,
5669 border-color: $gray-dark;
5770
5871 display: block;
59 border-radius: 6px;
6072 margin: 0 var(--margin-wide);
6173 padding: 1em;
6274 white-space: pre-wrap;