-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmercer.hs
110 lines (95 loc) · 2.98 KB
/
mercer.hs
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
module Main where
import Base
import System
beginAdoc = [r|<div class="cell" data-type="AsciiDoc"><div style="display:flex;">
<span class="inlabel"></span>
<pre class="incode" spellcheck="false" contenteditable="" style="display: inline-block;">|]
beginCode = [r|<div class="cell" data-type="Code"><div style="display:flex;">
<span class="inlabel">[<span class="runcounter"> </span>]:</span>
<pre class="incode" spellcheck="false" contenteditable="" style="display: inline-block;">|]
endCell = "</div></div>"
header = [r|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<div id="topmenu" style="border-bottom: solid 1px black;">
<dialog id="importdialog" class="topdialog">Import:
<input id="importfile" type="file" /><button id="importOKButton">OK</button>
</dialog>
</div>
<div id="convo" class="convo">|]
footer = [r|</div>
<div style="display:none;" id="cellmenuclipboard">
<!-- https://stackoverflow.com/questions/6040005/relatively-position-an-element-without-it-taking-up-space-in-document-flow -->
<div style="float:right;height:0;" id="cellmenu">
<div style="position:relative;right:0.5em;bottom:1.5em;
background-color:white;padding:2px;
border:1px solid lightgrey;border-radius:4px;
font-family:'Open Sans',sans-serif;
">
<div id="cellmenubuttons"></div>
<div id="popuptypemenu" class="popup">
Select type:
<hr>
</div>
</div>
</div>
</div>
<script src="../asciidoctor.min.js"></script>
<script src="../compiler/merc-main.js"></script>
<script>
include::../compiler/reply.js[]
async function init() {
/*
await mercInit
( ev => { loadConvo(localStorage.getItem("content")); }
, ev => { localStorage.setItem("content", saveConvo()); }
);
*/
await mercInitLite();
// Remove text nodes.
[...convo.childNodes].forEach(c => c.nodeType != 1 && c.remove());
for (const c of convo.childNodes) {
c.addEventListener('click', ev => {
const ae = document.activeElement;
if (ae && (ae.matches('input') || ae.matches('button'))) return;
select(c);
});
cursor = c;
runOnly();
}
cursor = undefined;
}
window.MathJax = {
startup: {
ready: () => {
MathJax.startup.defaultReady();
init();
}
}
};
</script>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|]
main = do
interact $ unlines . merc . lines
putStr footer
merc ls@(h:_) = duph1 h $ (header:) $ go beginAdoc ls
duph1 = \case
h@('=':' ':_) -> (h:)
_ -> id
go opener = \case
[] -> [endCell]
h : t
| h == "[cloak]" -> dashesOpen (endCell ++ beginCode) t
| h == "\\begin{code}" -> go (endCell ++ beginCode) t
| h == "\\end{code}" -> go (endCell ++ beginAdoc) t
| opener == "" -> h : go opener t
| h == "" -> go opener t
| otherwise -> (opener ++ h) : go "" t
dashesOpen opener = \case
h : t | all (== '-') h -> opener : dashesClose (length h) t
s -> go (endCell ++ beginAdoc) s
dashesClose n = \case
h : t
| length h == n, all (== '-') h -> go (endCell ++ beginAdoc) t
| otherwise -> h : dashesClose n t
[] -> [endCell]