forked from RFnexus/micron-parser-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
653 lines (454 loc) · 21.7 KB
/
index.html
File metadata and controls
653 lines (454 loc) · 21.7 KB
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Micron Playground</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="vendor/purify.min.js"></script>
<script type="module" src="js/micron-parser.js"></script>
<style>
@font-face {
font-family: 'Roboto Mono Nerd Font';
src: url('/fonts/RobotoMonoNerdFont-Regular.ttf') format('truetype');
font-weight: 400;
font-style: normal;
}
body {
font-family: Roboto Mono Nerd Font, monospace, monospace !important;
line-height: normal !important;
}
pre {
font-family: Roboto Mono Nerd Font, monospace, monospace !important;
line-height: normal !important;
}
</style>
</head>
<body class="bg-black text-white h-screen flex flex-col overflow-y-hidden">
<div class="bg-zinc-900 border-b border-zinc-700 p-2 flex items-center">
<div id="tabs" class="flex-1 flex space-x-2 overflow-x-auto"></div>
<button id="hideEditor" class="px-3 py-1 bg-zinc-500 text-white rounded hover:bg-red-700">Hide Editor</button>
<button id="saveFile" class="px-3 py-1 bg-green-600 text-white rounded hover:bg-green-700 ml-2">Save to Disk</button>
<button id="newFile" class="px-3 py-1 bg-blue-600 text-white rounded hover:bg-blue-700 ml-2">New File</button>
</div>
<div class="flex flex-1 min-h-0 min-h-0">
<div hidden id="welcomeContent">
`Ffd0
`=
_ _
(_) (_)
_ __ ___ _ ___ _ __ ___ _ __ ______ _ __ __ _ _ __ ___ ___ _ __ _ ___
| '_ ` _ \| |/ __| '__/ _ \| '_ \______| '_ \ / _` | '__/ __|/ _ \ '__| / __|
| | | | | | | (__| | | (_) | | | | | |_) | (_| | | \__ \ __/ |_ | \__ \
|_| |_| |_|_|\___|_| \___/|_| |_| | .__/ \__,_|_| |___/\___|_(_)| |___/
| | _/ |
|_| |__/
`=
`f
`!Welcome to micron-parser.js`!
-
Micron is a lightweight, terminal-friendly monospace markdown format used in Reticulum applications such as `!MeshChat`! `*(https://github.com/liamcottle/reticulum-meshchat) `*and `!NomadNet`! `*(https://github.com/markqvist/NomadNet)`*.
Micron supports a number of tags that can be used to create interactive pages which can be served over extremely low bandwidth connections. micron-parser.js is a 1:1 implementation of the MicronParser found in NomadNet.
-∿
`!With Micron, you can``:
`c Align`b
`r text,
`a
`c
set `B005 backgrounds, `b and `*` `B777`Ffffcombine any number of`f`b`_`_ `Ff00f`Ff80o`Ffd0r`F9f0m`F0f2a`F0fdt`F07ft`F43fi`F70fn`Fe0fg `ftags.
``
Micron also supports content sections, dividers, links, and dynamic input fields like text inputs, checkboxes, and radio groups.
To view the full guide click on the tab "NomadNetGuide.mu" in the top navigation bar.
To create a new Micron tab, click "New File".
</div>
<div hidden id="nomadNetGuideContent">
-∿
<
`c`!Hello!`! This is output from `*micron`*
Micron generates formatted text for your terminal
`a
-∿
<
Nomad Network supports a simple and functional markup language called `*micron`*. If you are familiar with `*markdown`* or `*HTML`*, you will feel right at home writing pages with micron.
With micron you can easily create structured documents and pages with formatting, colors, glyphs and icons, ideal for display in terminals.
>>Recommendations and Requirements
While micron can output formatted text to even the most basic terminal, there's a few capabilities your terminal `*must`* support to display micron output correctly, and some that, while not strictly necessary, make the experience a lot better.
Formatting such as `_underline`_, `!bold`! or `*italics`* will be displayed if your terminal supports it.
If you are having trouble getting micron output to display correctly, try using `*gnome-terminal`* or `*alacritty`*, which should work with all formatting options out of the box. Most other terminals will work fine as well, but you might have to change some settings to get certain formatting to display correctly.
>>>Encoding
All micron sources are intepreted as UTF-8, and micron assumes it can output UTF-8 characters to the terminal. If your terminal does not support UTF-8, output will be faulty.
>>>Colors
Shading and coloring text and backgrounds is integral to micron output, and while micron will attempt to gracefully degrade output even to 1-bit terminals, you will get the best output with terminals supporting at least 256 colors. True-color support is recommended.
>>>Terminal Font
While any unicode capable font can be used with micron, it's highly recommended to use a `*"Nerd Font"`* (see https://www.nerdfonts.com/), which will add a lot of extra glyphs and icons to your output.
> A Few Demo Outputs
`F222`Bddd
`cWith micron, you can control layout and presentation
`a
``
`B33f
You can change background ...
``
`B393
`r`F320... and foreground colors`f
`a
`b
If you want to make a break, horizontal dividers can be inserted. They can be plain, like the one below this text, or you can style them with unicode characters and glyphs, like the wavy divider in the beginning of this document.
-
`cText can be `_underlined`_, `!bold`! or `*italic`*.
You can also `_`*`!`B5d5`F222combine`f`b`_ `_`Ff00f`Ff80o`Ffd0r`F9f0m`F0f2a`F0fdt`F07ft`F43fi`F70fn`Fe0fg`` for some fabulous effects.
`a
>>>Sections and Headings
You can define an arbitrary number of sections and sub sections, each with their own named headings. Text inside sections will be automatically indented.
-
If you place a divider inside a section, it will adhere to the section indents.
>>>>>
If no heading text is defined, the section will appear as a sub-section without a header. This can be useful for creating indented blocks of text, like this one.
>Micron tags
Tags are used to format text with micron. Some tags can appear anywhere in text, and some must appear at the beginning of a line. If you need to write text that contains a sequence that would be interpreted as a tag, you can escape it with the character \\.
In the following sections, the different tags will be introduced. Any styling set within micron can be reset to the default style by using the special \\`\\` tag anywhere in the markup, which will immediately remove any formatting previously specified.
>>Alignment
To control text alignment use the tag \\`c to center text, \\`l to left-align, \\`r to right-align, and \\`a to return to the default alignment of the document. Alignment tags must appear at the beginning of a line. Here is an example:
`Faaa
`=
`cThis line will be centered.
So will this.
`aThe alignment has now been returned to default.
`rThis will be aligned to the right
``
`=
``
The above markup produces the following output:
`Faaa`B333
`cThis line will be centered.
So will this.
`aThe alignment has now been returned to default.
`rThis will be aligned to the right
``
>>Formatting
Text can be formatted as `!bold`! by using the \\`! tag, `_underline`_ by using the \\`_ tag and `*italic`* by using the \\`* tag.
Here's an example of formatting text:
`Faaa
`=
We shall soon see `!bold`! paragraphs of text decorated with `_underlines`_ and `*italics`*. Some even dare `!`*`_combine`` them!
`=
``
The above markup produces the following output:
`Faaa`B333
We shall soon see `!bold`! paragraphs of text decorated with `_underlines`_ and `*italics`*. Some even dare `!`*`_combine`!`*`_ them!
``
>>Sections
To create sections and subsections, use the > tag. This tag must be placed at the beginning of a line. To specify a sub-section of any level, use any number of > tags. If text is placed after a > tag, it will be used as a heading.
Here is an example of sections:
`Faaa
`=
>High Level Stuff
This is a section. It contains this text.
>>Another Level
This is a sub section.
>>>Going deeper
A sub sub section. We could continue, but you get the point.
>>>>
Wait! It's worth noting that we can also create sections without headings. They look like this.
`=
``
The above markup produces the following output:
`Faaa`B333
>High Level Stuff
This is a section. It contains this text.
>>Another Level
This is a sub section.
>>>Going deeper
A sub sub section. We could continue, but you get the point.
>>>>
Wait! It's worth noting that we can also create sections without headings. They look like this.
``
>Colors
Foreground colors can be specified with the \\`F tag, followed by three hexadecimal characters. To return to the default foreground color, use the \\`f tag. Background color is specified in the same way, but by using the \\`B and \\`b tags.
Here's a few examples:
`Faaa
`=
You can use `B5d5`F222 color `f`b `Ff00f`Ff80o`Ffd0r`F9f0m`F0f2a`F0fdt`F07ft`F43fi`F70fn`Fe0fg`f for some fabulous effects.
`=
``
The above markup produces the following output:
`Faaa`B333
You can use `B5d5`F222 color `f`B333 `Ff00f`Ff80o`Ffd0r`F9f0m`F0f2a`F0fdt`F07ft`F43fi`F70fn`Fe0fg`f for some fabulous effects.
``
>Links
Links to pages, files or other resources can be created with the \\`[ tag, which should always be terminated with a closing ]. You can create links with and without labels, it is up to you to control the formatting of links with other tags. Although not strictly necessary, it is good practice to at least format links with underlining.
Here's a few examples:
`Faaa
`=
Here is a link without any label: `[72914442a3689add83a09a767963f57c:/page/index.mu]
This is a `[labeled link`72914442a3689add83a09a767963f57c:/page/index.mu] to the same page, but it's hard to see if you don't know it
Here is `F00a`_`[a more visible link`72914442a3689add83a09a767963f57c:/page/index.mu]`_`f
`=
``
The above markup produces the following output:
`Faaa`B333
Here is a link without any label: `[72914442a3689add83a09a767963f57c:/page/index.mu]
This is a `[labeled link`72914442a3689add83a09a767963f57c:/page/index.mu] to the same page, but it's hard to see if you don't know it
Here is `F00f`_`[a more visible link`72914442a3689add83a09a767963f57c:/page/index.mu]`_`f
``
When links like these are displayed in the built-in browser, clicking on them or activating them using the keyboard will cause the browser to load the specified URL.
>Fields & Requests
Nomad Network let's you use simple input fields for submitting data to node-side applications. Submitted data, along with other session variables will be available to the node-side script / program as environment variables.
>>Request Links
Links can contain request variables and a list of fields to submit to the node-side application. You can include all fields on the page, only specific ones, and any number of request variables. To simply submit all fields on a page to a specified node-side page, create a link like this:
`Faaa
`=
`[Submit Fields`:/page/fields.mu`*]
`=
``
Note the `!*`! following the extra `!\\``! at the end of the path. This `!*`! denotes `*all fields`*. You can also specify a list of fields to include:
`Faaa
`=
`[Submit Fields`:/page/fields.mu`username|auth_token]
`=
``
If you want to include pre-set variables, you can do it like this:
`Faaa
`=
`[Query the System`:/page/fields.mu`username|auth_token|action=view|amount=64]
`=
``
>> Fields
Here's an example of creating a field. We'll create a field named `!user_input`! and fill it with the text `!Pre-defined data`!. Note that we are using background color tags to make the field more visible to the user:
`Faaa
`=
A simple input field: `B444`<user_input`Pre-defined data>`b
`=
``
You must always set a field `*name`*, but you can of course omit the pre-defined value of the field:
`Faaa
`=
An empty input field: `B444`<demo_empty`>`b
`=
``
You can set the size of the field like this:
`Faaa
`=
A sized input field: `B444`<16|with_size`>`b
`=
``
It is possible to mask fields, for example for use with passwords and similar:
`Faaa
`=
A masked input field: `B444`<!|masked_demo`hidden text>`b
`=
``
And you can of course control all parameters at the same time:
`Faaa
`=
Full control: `B444`<!32|all_options`hidden text>`b
`=
``
Collecting the above markup produces the following output:
`Faaa`B333
A simple input field: `B444`<user_input`Pre-defined data>`B333
An empty input field: `B444`<demo_empty`>`B333
A sized input field: `B444`<16|with_size`>`B333
A masked input field: `B444`<!|masked_demo`hidden text>`B333
Full control: `B444`<!32|all_options`hidden text>`B333
`b
>>> Checkboxes
In addition to text fields, Checkboxes are another way of submitting data. They allow the user to make a single selection or select multiple options.
`Faaa
`=
`<?|field_name|value`>`b Label Text`
`=
When the checkbox is checked, it's field will be set to the provided value. If there are multiple checkboxes that share the same field name, the checked values will be concatenated when they are sent to the node by a comma.
``
`B444`<?|sign_up|1`>`b Sign me up`
You can also pre-check both checkboxes and radio groups by appending a |* after the field value.
`B444`<?|checkbox|1|*`>`b Pre-checked checkbox`
>>> Radio groups
Radio groups are another input that lets the user chose from a set of options. Unlike checkboxes, radio buttons with the same field name are mutually exclusive.
Example:
`=
`B900`<^|color|Red`>`b Red
`B090`<^|color|Green`>`b Green
`B009`<^|color|Blue`>`b Blue
`=
will render:
`B900`<^|color|Red`>`b Red
`B090`<^|color|Green`>`b Green
`B009`<^|color|Blue`>`b Blue
In this example, when the data is submitted, `B444` field_color`b will be set to whichever value from the list was selected.
``
>Comments
You can insert comments that will not be displayed in the output by starting a line with the # character.
Here's an example:
`Faaa
`=
# This line will not be displayed
This line will
`=
``
The above markup produces the following output:
`Faaa`B333
# This line will not be displayed
This line will
``
>Literals
To display literal content, for example source-code, or blocks of text that should not be interpreted by micron, you can use literal blocks, specified by the \\`= tag. Below is the source code of this entire document, presented as a literal block.
-
`=
</div>
<div id='editor-pane' class="w-1/2 border-r border-zinc-700">
<textarea
id="text-editor"
class="w-full h-full bg-black text-white p-4 resize-none focus:outline-none focus:ring-2 focus:ring-blue-500"
placeholder="Enter your Micron markup here..."></textarea>
</div>
<div class="w-1/2 overflow-auto">
<pre id="output" class="bg-black break-words whitespace-pre-wrap p-4 text-wrap"></pre>
</div>
</div>
<script type="module">
import MicronParser from './js/micron-parser.js';
class FileManager {
constructor() {
this.files = JSON.parse(localStorage.getItem('micronFiles')) || {};
this.currentFile = localStorage.getItem('currentMicronFile') || null;
this.init();
}
init() {
// create initial default files
if (Object.keys(this.files).length === 0) {
const welcomeContent = document.getElementById('welcomeContent').innerText;
const nomadNetGuideContent = document.getElementById('nomadNetGuideContent').innerText;
this.createFile('welcome.mu', welcomeContent);
this.createFile('NomadNetGuide.mu', nomadNetGuideContent);
this.currentFile = 'welcome.mu';
this.saveToStorage();
}
}
createFile(name, content = '') {
if (!name.endsWith('.mu')) name += '.mu';
this.files[name] = content;
this.currentFile = name;
this.saveToStorage();
return name;
}
updateFile(name, content) {
this.files[name] = content;
this.saveToStorage();
}
deleteFile(name) {
delete this.files[name];
if (this.currentFile === name) {
this.currentFile = Object.keys(this.files)[0] || null;
}
this.saveToStorage();
}
saveToStorage() {
localStorage.setItem('micronFiles', JSON.stringify(this.files));
localStorage.setItem('currentMicronFile', this.currentFile);
}
}
class Editor {
constructor() {
this.fileManager = new FileManager();
this.parser = new MicronParser(true);
this.isEditorVisible = true;
this.editor = document.getElementById('text-editor');
this.editorPane = document.getElementById('editor-pane');
this.output = document.getElementById('output');
this.tabsContainer = document.getElementById('tabs');
this.newFileBtn = document.getElementById('newFile');
this.saveFileBtn = document.getElementById('saveFile')
this.hideEditorBtn = document.getElementById('hideEditor');
this.setupEventListeners();
this.renderTabs();
this.loadCurrentFile();
}
setupEventListeners() {
this.editor.addEventListener('input', () => this.handleInput());
this.newFileBtn.addEventListener('click', () => this.createNewFile());
this.saveFileBtn.addEventListener('click', () => this.saveFile());
this.hideEditorBtn.addEventListener('click', () => this.toggleEditor());
}
handleInput() {
const content = this.editor.value;
this.output.innerHTML = this.parser.convertMicronToHtml(content);
if (this.fileManager.currentFile) {
this.fileManager.updateFile(this.fileManager.currentFile, content);
}
}
createNewFile() {
const name = prompt('Enter file name:');
if (name) {
const fileName = this.fileManager.createFile(name);
this.renderTabs();
this.loadFile(fileName);
}
}
saveFile() {
if (!this.fileManager.currentFile) return null;
const content = this.fileManager.files[this.fileManager.currentFile];
const blob = new Blob([content], { type: 'text/plain' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = this.fileManager.currentFile;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(a.href);
}
createTab(fileName) {
const tab = document.createElement('div');
tab.className = `group flex items-center px-3 py-1 rounded cursor-pointer ${
fileName === this.fileManager.currentFile ? 'bg-blue-600' : 'bg-zinc-800 hover:bg-zinc-700'
}`;
const nameSpan = document.createElement('span');
nameSpan.textContent = fileName;
const closeBtn = document.createElement('button');
closeBtn.className = 'ml-2 px-1 text-zinc-400 hover:text-white';
closeBtn.innerHTML = '×';
closeBtn.onclick = (e) => {
e.stopPropagation();
if (Object.keys(this.fileManager.files).length > 1 && confirm(`Delete ${fileName}?`)) {
this.fileManager.deleteFile(fileName);
this.renderTabs();
this.loadCurrentFile();
}
};
tab.onclick = () => this.loadFile(fileName);
tab.append(nameSpan, closeBtn);
return tab;
}
renderTabs() {
this.tabsContainer.innerHTML = '';
Object.keys(this.fileManager.files).forEach(fileName => {
this.tabsContainer.appendChild(this.createTab(fileName));
});
}
toggleEditor() {
this.isEditorVisible = !this.isEditorVisible;
this.editorPane.style.display = this.isEditorVisible ? 'block' : 'none';
this.hideEditorBtn.textContent = this.isEditorVisible ? 'Hide Editor' : 'Show Editor';
this.hideEditorBtn.classList.toggle('bg-zinc-500', this.isEditorVisible);
this.hideEditorBtn.classList.toggle('bg-green-500', !this.isEditorVisible);
const outputPane = this.output.parentElement;
outputPane.className = this.isEditorVisible ? 'w-1/2 overflow-auto' : 'w-full overflow-auto';
}
loadFile(fileName) {
this.fileManager.currentFile = fileName;
this.fileManager.saveToStorage();
this.loadCurrentFile();
this.renderTabs();
}
loadCurrentFile() {
if (this.fileManager.currentFile) {
const content = this.fileManager.files[this.fileManager.currentFile];
this.editor.value = content;
this.output.innerHTML = this.parser.convertMicronToHtml(content);
}
}
}
new Editor();
</script>
</body>
</html>