-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex-one.html
336 lines (282 loc) · 16.2 KB
/
index-one.html
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<!DOCTYPE html>
<title>All-in-One</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body { font-family:Verdana,sans-serif; font-size:14px; line-height:1.5; margin:auto; display:none; }
a { background:transparent; text-decoration:none; color:navy } a:active, a:hover { outline-width:0; background:#ffd700 }
#header { background:#0057b7; color:white; width:100%; height:50px; }
#title { float:left; font-size:18px; font-weight:700; padding:8px }
#menu button, #menu a { font-family:Verdana,Arial; border:none; padding:4px 8px; color:inherit; background:inherit; }
#menu button:hover, #menu a:hover { color:#000; background:#ffd700 }
#menu button:disabled {cursor:not-allowed; opacity:0.5}: disabled *{pointer-events:none}
#left-panel { position:absolute; left:0; bottom:0; width:380px; top:48px; border:1px solid grey; overflow:auto; padding:8px }
#right-panel { position:absolute; right:0; bottom:0; left:400px; top:48px; border:1px solid grey; overflow:auto; padding:8px 16px }
/***** css copy from casual-markdown.css ******/
.markdown code { background:#f0f0f0; color:navy; border-radius:2px; padding:2px; }
.markdown pre { background:#f0f0f0; margin:16px; border:1px solid #ddd; padding:8px; }
.markdown blockquote { background:#f0f0f0; border-left:6px solid grey; padding:8px }
.markdown table { margin:12px; border-collapse: collapse; }
.markdown th { border:1px solid grey; background:lightgrey; padding:6px; }
.markdown td { border:1px solid grey; padding:6px; }
.markdown tr:nth-child(even) { background:#f0f0f0; }
.markdown ins { color:#890604 }
.markdown rem { color:#198964 }
.toc ul { padding: 0 12px; }
.toc h3 { color:#0057b7; border-bottom:1px dotted grey }
.toc .H1 { list-style-type:none; font-weight:600; margin:4px; background:#eee }
.toc .H2 { list-style-type:none; font-weight:600; margin:4px; }
.toc .H3 { margin-left:2em }
.toc .H4 { margin-left:4em }
.toc .active { color:#0057b7 }
.toc li:hover { background:#f0f0f0 }
@media print{
#header, #left-panel { display:none!important }
#right-panel { position:relative; width:100%; left:0px; top:0px; border:none; height:auto; overflow:hidden }
}
@media screen and (min-width: 600px) and (max-width: 900px){
#header { width:100%; height:80px; }
#left-panel { display:none; position:absolute; left:0px; width:100%; top:80px; border:1px solid grey; overflow:auto; padding:4px 8px }
#right-panel { position:absolute; left:0px; width:100%;; top:80px; border:1px solid grey; overflow:auto; padding:4px 8px }
}
@media screen and (max-width: 600px) {
#header { width:100%; height:100px; }
#left-panel { display:none; position:absolute; left:0px; width:100%; top:100px; border:1px solid grey; overflow:auto; padding:4px 8px }
#right-panel { position:absolute; left:0px; width:100%;; top:100px; border:1px solid grey; overflow:auto; padding:4px 8px }
}
</style>
<script>
/*****************************************************************************
* casual-markdown - a lightweight regexp-base markdown parser with TOC support
* last updated on 2022/07/31, v0.90, refine frontmatter (simple yaml)
*
* Copyright (c) 2022, Casualwriter (MIT Licensed)
* https://github.com/casualwriter/casual-markdown
*****************************************************************************/
// define md object, and extent function (which is a dummy function)
var md = { yaml:{}, before: function (str) {return str}, after: function (str) {return str} }
// function for REGEXP to convert html tag. ie. <TAG> => <TAG*gt;
md.formatTag = function (html) { return html.replace(/</g,'<').replace(/\>/g,'>'); }
// frontmatter for simple YAML (support multi-level, but string value only)
md.formatYAML = function (front, matter) {
var level = {}, latest = md.yaml;
matter.replace( /^\s*#(.*)$/gm, '' ).replace( /^( *)([^:^\n]+):(.*)$/gm, function(m, sp, key,val) {
level[sp] = level[sp] || latest
latest = level[sp][key.trim()] = val.trim() || {}
for (e in level) if(e>sp) level[e]=null;
} );
return ''
}
//===== format code-block, highlight remarks/keywords for code/sql
md.formatCode = function (match, title, block) {
// convert tag <> to < > tab to 3 space, support marker using ^^^
block = block.replace(/</g,'<').replace(/\>/g,'>')
block = block.replace(/\t/g,' ').replace(/\^\^\^(.+?)\^\^\^/g, '<mark>$1</mark>')
// highlight comment and keyword based on title := none | sql | code
if (title.toLowerCase(title) == 'sql') {
block = block.replace(/^\-\-(.*)/gm,'<rem>--$1</rem>').replace(/\s\-\-(.*)/gm,' <rem>--$1</rem>')
block = block.replace(/(\s)(function|procedure|return|if|then|else|end|loop|while|or|and|case|when)(\s)/gim,'$1<b>$2</b>$3')
block = block.replace(/(\s)(select|update|delete|insert|create|from|where|group by|having|set)(\s)/gim,'$1<b>$2</b>$3')
} else if ((title||'none')!=='none') {
block = block.replace(/^\/\/(.*)/gm,'<rem>//$1</rem>').replace(/\s\/\/(.*)/gm,' <rem>//$1</rem>')
block = block.replace(/(\s)(function|procedure|return|if|then|else|end|loop|while|or|and|case|when)(\s)/gim,'$1<b>$2</b>$3')
block = block.replace(/(\s)(var|let|const|for|next|do|while|loop|continue|break|switch|try|catch|finally)(\s)/gim,'$1<b>$2</b>$3')
}
return '<pre title="' + title + '"><code>' + block + '</code></pre>'
}
//===== parse markdown string into HTML string (exclude code-block)
md.parser = function( mdstr ) {
// apply yaml variables
for (var name in this.yaml) mdstr = mdstr.replace( new RegExp('\{\{\\s*'+name+'\\s*\}\}', 'gm'), this.yaml[name] )
// table syntax
mdstr = mdstr.replace(/\n(.+?)\n.*?\-\-\|\-\-.*?\n([\s\S]*?)\n\s*?\n/g, function (m,p1,p2) {
var thead = p1.replace(/^\|(.+)/gm,'$1').replace(/(.+)\|$/gm,'$1').replace(/\|/g,'<th>')
var tbody = p2.replace(/^\|(.+)/gm,'$1').replace(/(.+)\|$/gm,'$1')
tbody = tbody.replace(/(.+)/gm,'<tr><td>$1</td></tr>').replace(/\|/g,'<td>')
return '\n<table>\n<thead>\n<th>' + thead + '\n</thead>\n<tbody>' + tbody + '\n</tbody></table>\n\n'
} )
// horizontal rule => <hr>
mdstr = mdstr.replace(/^-{3,}|^\_{3,}|^\*{3,}$/gm, '<hr>').replace(/\n\n<hr\>/g, '\n<br><hr>')
// header => <h1>..<h5>
mdstr = mdstr.replace(/^##### (.*?)\s*#*$/gm, '<h5>$1</h5>')
.replace(/^#### (.*?)\s*#*$/gm, '<h4>$1</h4>')
.replace(/^### (.*?)\s*#*$/gm, '<h3>$1</h3>')
.replace(/^## (.*?)\s*#*$/gm, '<h2>$1</h2>')
.replace(/^# (.*?)\s*#*$/gm, '<h1>$1</h1>')
.replace(/^<h(\d)\>(.*?)\s*{(.*)}\s*<\/h\d\>$/gm, '<h$1 id="$3">$2</h$1>')
// inline code-block: `code-block` => <code>code-block</code>
mdstr = mdstr.replace(/``(.*?)``/gm, function(m,p){ return '<code>' + md.formatTag(p).replace(/`/g,'`') + '</code>'} )
mdstr = mdstr.replace(/`(.*?)`/gm, '<code>$1</code>' )
// blockquote, max 2 levels => <blockquote>{text}</blockquote>
mdstr = mdstr.replace(/^\>\> (.*$)/gm, '<blockquote><blockquote>$1</blockquote></blockquote>')
mdstr = mdstr.replace(/^\> (.*$)/gm, '<blockquote>$1</blockquote>')
mdstr = mdstr.replace(/<\/blockquote\>\n<blockquote\>/g, '\n<br>' )
mdstr = mdstr.replace(/<\/blockquote\>\n<br\><blockquote\>/g, '\n<br>' )
// image syntax: ![title](url) => <img alt="title" src="url" />
mdstr = mdstr.replace(/!\[(.*?)\]\((.*?) "(.*?)"\)/gm, '<img alt="$1" src="$2" $3 />')
mdstr = mdstr.replace(/!\[(.*?)\]\((.*?)\)/gm, '<img alt="$1" src="$2" width="90%" />')
// links syntax: [title "title"](url) => <a href="url" title="title">text</a>
mdstr = mdstr.replace(/\[(.*?)\]\((.*?) "new"\)/gm, '<a href="$2" target=_new>$1</a>')
mdstr = mdstr.replace(/\[(.*?)\]\((.*?) "(.*?)"\)/gm, '<a href="$2" title="$3">$1</a>')
mdstr = mdstr.replace(/([<\s])(https?\:\/\/.*?)([\s\>])/gm, '$1<a href="$2">$2</a>$3')
mdstr = mdstr.replace(/\[(.*?)\]\(\)/gm, '<a href="$1">$1</a>')
mdstr = mdstr.replace(/\[(.*?)\]\((.*?)\)/gm, '<a href="$2">$1</a>')
// unordered/ordered list, max 2 levels => <ul><li>..</li></ul>, <ol><li>..</li></ol>
mdstr = mdstr.replace(/^[\*+-][ .](.*)/gm, '<ul><li>$1</li></ul>' )
mdstr = mdstr.replace(/^\d[ .](.*)/gm, '<ol><li>$1</li></ol>' )
mdstr = mdstr.replace(/^\s{2,6}[\*+-][ .](.*)/gm, '<ul><ul><li>$1</li></ul></ul>' )
mdstr = mdstr.replace(/^\s{2,6}\d[ .](.*)/gm, '<ul><ol><li>$1</li></ol></ul>' )
mdstr = mdstr.replace(/<\/[ou]l\>\n<[ou]l\>/g, '\n' )
mdstr = mdstr.replace(/<\/[ou]l\>\n<[ou]l\>/g, '\n' )
// text decoration: bold, italic, underline, strikethrough, highlight
mdstr = mdstr.replace(/\*\*\*(\w.*?[^\\])\*\*\*/gm, '<b><em>$1</em></b>')
mdstr = mdstr.replace(/\*\*(\w.*?[^\\])\*\*/gm, '<b>$1</b>')
mdstr = mdstr.replace(/\*(\w.*?[^\\])\*/gm, '<em>$1</em>')
mdstr = mdstr.replace(/___(\w.*?[^\\])___/gm, '<b><em>$1</em></b>')
mdstr = mdstr.replace(/__(\w.*?[^\\])__/gm, '<u>$1</u>')
// mdstr = mdstr.replace(/_(\w.*?[^\\])_/gm, '<u>$1</u>') // NOT support!!
mdstr = mdstr.replace(/\^\^\^(.+?)\^\^\^/gm, '<mark>$1</mark>')
mdstr = mdstr.replace(/\^\^(\w.*?)\^\^/gm, '<ins>$1</ins>')
mdstr = mdstr.replace(/~~(\w.*?)~~/gm, '<del>$1</del>')
// line break and paragraph => <br/> <p>
mdstr = mdstr.replace(/ \n/g, '\n<br/>').replace(/\n\s*\n/g, '\n<p>\n')
// indent as code-block
mdstr = mdstr.replace(/^ {4,10}(.*)/gm, function(m,p) { return '<pre><code>' + md.formatTag(p) + '</code></pre>'} )
mdstr = mdstr.replace(/^\t(.*)/gm, function(m,p) { return '<pre><code>' + md.formatTag(p) + '</code></pre>'} )
mdstr = mdstr.replace(/<\/code\><\/pre\>\n<pre\><code\>/g, '\n' )
// Escaping Characters
return mdstr.replace(/\\([`_~\*\+\-\.\^\\\<\>\(\)\[\]])/gm, '$1' )
}
//===== parse markdown string into HTML content (cater code-block)
md.html = function (mdText) {
// replace \r\n to \n, and handle front matter for simple YAML
mdText = mdText.replace(/\r\n/g, '\n').replace( /^---+\s*\n([\s\S]*?)\n---+\s*\n/, md.formatYAML )
// handle code-block.
mdText = mdText.replace(/\n~~~/g,'\n```').replace(/\n``` *(.*?)\n([\s\S]*?)\n``` *\n/g, md.formatCode)
// split by "<code>", skip for code-block and process normal text
var pos1=0, pos2=0, mdHTML = ''
while ( (pos1 = mdText.indexOf('<code>')) >= 0 ) {
pos2 = mdText.indexOf('</code>', pos1 )
mdHTML += md.after( md.parser( md.before( mdText.substr(0,pos1) ) ) )
mdHTML += mdText.substr(pos1, (pos2>0? pos2-pos1+7 : mdtext.length) )
mdText = mdText.substr( pos2 + 7 )
}
return '<div class="markdown">' + mdHTML + md.after( md.parser( md.before(mdText) ) ) + '</div>'
}
//===== TOC support
md.toc = function (srcDiv, tocDiv, options ) {
// select elements, set title
var tocSelector = (options&&options.css) || 'h1,h2,h3,h4'
var tocTitle = (options&&options.title) || 'Table of Contents'
var toc = document.getElementById(srcDiv).querySelectorAll( tocSelector )
var html = '<div class="toc"><ul>' + (tocTitle=='none'? '' : '<h3>' + tocTitle + '</h3>');
// loop for each element,add <li> element with class in TAG name.
for (var i=0; i<toc.length; i++ ) {
if (toc[i].id.substr(0,6)=='no-toc') continue;
if (!toc[i].id) toc[i].id = "toc-item-" + i;
html += '<li class="' + toc[i].nodeName + '" title="#' + toc[i].id + '" onclick="location=this.title">'
html += toc[i].textContent + '</a></li>';
}
document.getElementById(tocDiv).innerHTML = html + "</ul>";
//===== scrollspy support (ps: add to document.body if element(scrollspy) not found)
if ( options && options.scrollspy ) {
(document.getElementById(options.scrollspy)||document).onscroll = function () {
// get TOC elements, and viewport position
var list = document.getElementById(tocDiv).querySelectorAll('li')
var divScroll = document.getElementById(options.scrollspy) || document.documentElement
var divHeight = divScroll.clientHeight || divScroll.offsetHeight
// loop for each TOC element, add/remove scrollspy class
for (var i=0; i<list.length; i++) {
var div = document.getElementById( list[i].title.substr(1) )
var pos = (div? div.offsetTop - divScroll.scrollTop + 10: 0 )
if ( pos>0 && pos<divHeight ) {
list[i].className = list[i].className.replace('active','') + ' active' // classList.add( 'active' );
} else {
list[i].className = list[i].className.replace('active','') // classList.remove( 'active' );
}
}
}
}
//===== end of scrollspy
}
</script>
<body onload="md.load( location.href.split('?file=')[1]||'index.md' )">
<div id=header class="theme">
<span id=title>casual-markdown</span>
<span id=menu style="float:right; padding:12px"></span>
</div>
<div id=content>
<div id="left-panel" style=""></div>
<div id="right-panel" style=""></div>
</div>
<button style="display:none" onclick="toggleHTML()" accesskey=s>ShowHTML</button>
<button style="display:none" onclick="darkmode()" accesskey=k>Dark</button>
<style id=theme comment="for additional style"></style>
<script>
/*****************************************************************************
* casual-markdown-page - view markdown as web page
* last updated on 2022/12/28, v0.62.
*
* Copyright (c) 2022, Casualwriter (MIT Licensed)
* https://github.com/casualwriter/casual-markdown
*****************************************************************************/
//=== toggle HTML in right-panel. (this is a hidden function for developer)
function toggleHTML() {
var html = document.getElementById('right-panel').innerHTML
if (html.substr(0,5)=='<xmp>') {
document.getElementById('right-panel').innerHTML = html.substr(5, html.length-11)
} else {
document.getElementById('right-panel').innerHTML = '<xmp>' + html.replace(/xmp\>/g,'xmp>') + '</xmp>'
}
}
//=== apply dark mode style
function darkmode() {
var css = document.getElementById('theme').textContent
var dark = ' body, pre, code { background:#333!important; color:#ccc!important } '
dark += '\n #header, a {background:#555;} th, tr:nth-child(even) {color:#333} '
dark += '\n .active { color:white!important } #left-panel {background:#444;} '
document.getElementById('theme').textContent = (css===(md.yaml.style||'')? dark : md.yaml.style||'')
}
//=== load and parser markdown file.
md.load = function (fname) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function (e) {
document.getElementById('right-panel').innerHTML = md.html(md.text=this.responseText) + '<br>'
document.getElementById('right-panel').scrollTop = 0
md.toc( 'right-panel', 'left-panel', { title:'none', scrollspy:'right-panel'} )
document.title = document.getElementById('title').innerHTML = md.yaml.title || 'Markdown Page'
document.getElementById('theme').textContent = md.yaml.style ||''
document.body.style.display='block';
if (fname.indexOf('#')>0) location.href = fname.substr( fname.indexOf('#') )
var i, html = ''
for (i in md.yaml.menu) {
html += '<a href="' + (md.yaml.menu[i].substr(-3)==='.md'? '?file=' : '' )
html += md.yaml.menu[i] + '">' + i + '</a>'
}
document.getElementById('menu').innerHTML = html
}
xmlhttp.open("GET", fname , true)
xmlhttp.send();
}
//=== touch event for mobile (swipe to show/hide left-panel)
if (window.innerWidth<900) {
function toggleTOC(show) {
var disp = document.getElementById('left-panel').style.display
document.getElementById('left-panel').style.display = show||(disp=='none')? 'block' : 'none'
document.getElementById('right-panel').style.display = show||(disp=='none')? 'none' : 'block'
}
window.addEventListener( 'touchstart', function(e) { document.touch=e.changedTouches[0] } )
window.addEventListener( 'touchend', function(e) {
var distX = e.changedTouches[0].clientX - document.touch.clientX
var distY = e.changedTouches[0].clientY - document.touch.clientY
if ( Math.abs(distY) < 15 && distX > 90 ) {
e.preventDefault();
toggleTOC(true)
} else if ( Math.abs(distY) < 15 && distX < -30 ) {
e.preventDefault();
toggleTOC(false)
}
} );
document.getElementById('left-panel').onclick = function() {toggleTOC(false)}
document.getElementById('title').onclick = function() {toggleTOC()}
}
</script>