aboutsummaryrefslogtreecommitdiffstats
path: root/root/$mmm/plugins/mermaid/converts: text$moonscript -> table.moon
blob: 1eb695ea279bd21239a4af54f48453a3f40811e8 (plain)
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
-- assert window and window.mermaid, "mermaid.js not found"
if not (window and window.mermaid)
  return

window.mermaid\initialize {
  startOnLoad: false
  fontFamily: 'monospace'
}

id_counter = 1

{
  {
    inp: 'text/mermaid-graph'
    out: 'mmm/dom'
    cost: 1
    transform: (source, fileder, key) =>
      id_counter += 1
      id = "mermaid-#{id_counter}"
      with container = document\createElement 'div'
        cb = (svg) =>
          .innerHTML = svg
          .firstElementChild.style.width = '100%'
          .firstElementChild.style.height = 'auto'

        window\setImmediate (_) ->
          window.mermaid\render id, source, cb, container
  }
}