-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1135 lines (1020 loc) · 82.9 KB
/
index.html
File metadata and controls
1135 lines (1020 loc) · 82.9 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
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>string.md</title>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #0d1117;
--panel-bg: #161b22;
--border: #30363d;
--accent: #58a6ff;
--accent2: #f78166;
--text: #e6edf3;
--text-dim: #8b949e;
--editor-bg: #0d1117;
--preview-bg: #161b22;
--green: #3fb950;
--red: #f85149;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: var(--bg);
color: var(--text);
height: 100vh;
display: flex;
flex-direction: column;
overflow: hidden;
}
/* ── Header ── */
header {
display: flex;
align-items: center;
gap: 10px;
padding: 6px 14px;
background: var(--panel-bg);
border-bottom: 1px solid var(--border);
flex-shrink: 0;
min-height: 42px;
}
.logo { font-size: 1.1rem; font-weight: 700; color: var(--accent); letter-spacing: -0.02em; }
.toolbar { display: flex; gap: 6px; margin-left: auto; align-items: center; }
button {
background: transparent;
color: var(--text);
border: 1px solid var(--border);
padding: 4px 10px;
border-radius: 6px;
cursor: pointer;
font-size: 0.82rem;
transition: background 0.15s, border-color 0.15s;
white-space: nowrap;
}
button:hover { background: rgba(255,255,255,0.07); border-color: var(--accent); }
button.primary { background: var(--accent); color: #000; border-color: var(--accent); }
button.primary:hover { background: #79c0ff; }
/* ── Main 3-panel grid ── */
.main {
display: grid;
grid-template-columns: 20% 40% 40%;
flex: 1;
overflow: hidden;
width: 100%;
}
.panel {
border-right: 1px solid var(--border);
display: flex;
flex-direction: column;
overflow: hidden;
min-width: 0;
}
.panel:last-child { border-right: none; }
.panel-header {
padding: 6px 10px;
font-size: 0.72rem;
font-weight: 600;
color: var(--text-dim);
text-transform: uppercase;
letter-spacing: 0.08em;
background: var(--panel-bg);
border-bottom: 1px solid var(--border);
flex-shrink: 0;
display: flex;
align-items: center;
gap: 6px;
}
/* ── History panel ── */
#history-panel { background: var(--panel-bg); }
#history-list { flex: 1; overflow-y: auto; padding: 6px; }
.history-section-label {
font-size: 0.7rem;
color: var(--text-dim);
text-transform: uppercase;
letter-spacing: 0.07em;
padding: 6px 6px 2px;
margin-top: 4px;
}
.history-entry {
padding: 7px 8px;
border-radius: 5px;
cursor: pointer;
font-size: 0.78rem;
border: 1px solid transparent;
margin-bottom: 3px;
}
.history-entry:hover { border-color: var(--border); background: rgba(255,255,255,0.04); }
.history-entry.active { border-color: var(--accent); background: rgba(88,166,255,0.07); }
.history-entry .he-time { color: var(--text-dim); font-size: 0.7rem; display: flex; align-items: center; gap: 4px; }
.history-entry .he-preview { margin-top: 2px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.git-entry { border-left: 2px solid var(--green); padding-left: 8px; }
.git-entry .he-sha { font-family: monospace; font-size: 0.7rem; color: var(--green); }
.git-entry .he-author { color: var(--text-dim); font-size: 0.7rem; }
/* ── Editor panel ── */
#editor-panel { background: var(--editor-bg); }
#editor {
flex: 1;
width: 100%;
background: var(--editor-bg);
color: var(--text);
border: none;
outline: none;
padding: 14px 16px;
font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Courier New', monospace;
font-size: 13.5px;
line-height: 1.65;
resize: none;
overflow-y: auto;
tab-size: 2;
}
/* ── Preview panel ── */
#preview-panel { background: var(--preview-bg); }
#preview {
flex: 1;
overflow-y: auto;
padding: 16px 20px;
font-size: 14.5px;
line-height: 1.75;
}
/* Markdown preview typography */
#preview h1, #preview h2, #preview h3,
#preview h4, #preview h5, #preview h6 { margin: 1.1em 0 0.4em; line-height: 1.3; }
#preview h1 { font-size: 1.9em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
#preview h2 { font-size: 1.45em; border-bottom: 1px solid var(--border); padding-bottom: 0.2em; }
#preview h3 { font-size: 1.15em; }
#preview p { margin: 0.7em 0; }
#preview code {
background: rgba(255,255,255,0.08);
padding: 2px 5px;
border-radius: 3px;
font-family: 'JetBrains Mono', 'Fira Code', monospace;
font-size: 0.88em;
}
#preview pre {
background: #010409;
padding: 14px 16px;
border-radius: 6px;
overflow-x: auto;
margin: 0.9em 0;
border: 1px solid var(--border);
}
#preview pre code { background: none; padding: 0; font-size: 0.87em; }
#preview blockquote {
border-left: 3px solid var(--accent);
margin: 0.8em 0;
padding: 4px 14px;
color: var(--text-dim);
}
#preview a { color: var(--accent); text-decoration: none; }
#preview a:hover { text-decoration: underline; }
#preview ul, #preview ol { padding-left: 1.8em; margin: 0.7em 0; }
#preview li { margin: 0.25em 0; }
#preview table { border-collapse: collapse; width: 100%; margin: 0.9em 0; font-size: 0.93em; }
#preview th, #preview td { border: 1px solid var(--border); padding: 6px 10px; }
#preview th { background: var(--panel-bg); }
#preview hr { border: none; border-top: 1px solid var(--border); margin: 1.5em 0; }
#preview img { max-width: 100%; border-radius: 4px; }
/* ── Status bar ── */
.status-bar {
padding: 3px 14px;
font-size: 0.72rem;
color: var(--text-dim);
background: var(--panel-bg);
border-top: 1px solid var(--border);
display: flex;
gap: 14px;
align-items: center;
flex-shrink: 0;
}
#lock-indicator { color: var(--green); }
#lock-indicator.plain { color: var(--text-dim); }
/* ── Collaboration bar ── */
#collab-bar {
padding: 4px 10px;
font-size: 0.75rem;
background: rgba(88,166,255,0.08);
border-bottom: 1px solid rgba(88,166,255,0.25);
color: var(--accent);
display: flex;
align-items: center;
gap: 8px;
flex-shrink: 0;
}
/* ── Modals ── */
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(0,0,0,0.75);
display: flex;
align-items: center;
justify-content: center;
z-index: 100;
}
.modal {
background: var(--panel-bg);
border: 1px solid var(--border);
border-radius: 10px;
padding: 22px 24px;
min-width: 310px;
max-width: 460px;
width: 90%;
}
.modal h2 { margin-bottom: 8px; font-size: 1rem; }
.modal p { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 14px; }
.modal input[type="password"],
.modal input[type="text"] {
width: 100%;
background: var(--editor-bg);
border: 1px solid var(--border);
color: var(--text);
padding: 7px 10px;
border-radius: 5px;
font-size: 13px;
margin-bottom: 10px;
outline: none;
}
.modal input:focus { border-color: var(--accent); }
.modal-error { color: var(--red); font-size: 0.82rem; margin-bottom: 8px; min-height: 16px; }
.modal-buttons { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
/* ── Toast ── */
.toast {
position: fixed;
bottom: 20px;
right: 20px;
background: var(--panel-bg);
border: 1px solid var(--border);
border-radius: 7px;
padding: 9px 14px;
font-size: 0.85rem;
z-index: 200;
pointer-events: none;
animation: toastIn 0.18s ease;
}
.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }
@keyframes toastIn { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
/* ── Git connect bar ── */
#git-bar {
padding: 4px 10px;
font-size: 0.75rem;
background: rgba(63,185,80,0.08);
border-bottom: 1px solid rgba(63,185,80,0.25);
color: var(--green);
display: flex;
align-items: center;
gap: 8px;
flex-shrink: 0;
}
.hidden { display: none !important; }
.spacer { flex: 1; }
</style>
</head>
<body>
<header>
<span class="logo">string.md</span>
<div class="toolbar">
<button id="btn-collab" title="Start or join a live P2P collaboration session">👥 Live</button>
<button id="btn-git" title="Connect to git backend">⎇ Git</button>
<button id="btn-encrypt" title="Encrypt document with a password">🔒 Encrypt</button>
<button id="btn-share" class="primary" title="Copy shareable URL to clipboard">⎘ Share</button>
<button id="btn-new" title="New document">+ New</button>
</div>
</header>
<!-- Git connection bar (shown when git backend is connected) -->
<div id="git-bar" class="hidden">
<span>⎇</span>
<span id="git-branch-label">main</span>
<span id="git-file-label" style="color:var(--text-dim);"></span>
<span class="spacer"></span>
<button id="btn-git-pull" style="font-size:0.72rem;padding:2px 8px;">↓ Pull</button>
<button id="btn-git-push" style="font-size:0.72rem;padding:2px 8px;">↑ Push</button>
<button id="btn-git-disconnect" style="font-size:0.72rem;padding:2px 8px;border-color:var(--red);color:var(--red);">✕</button>
</div>
<!-- Collaboration bar (shown during a live session) -->
<div id="collab-bar" class="hidden">
<span>👥</span>
<span id="collab-room-label"></span>
<span id="collab-peer-count" style="color:var(--text-dim);">0 peers</span>
<span class="spacer"></span>
<button id="btn-collab-copy" style="font-size:0.72rem;padding:2px 8px;">⎘ Copy link</button>
<button id="btn-collab-leave" style="font-size:0.72rem;padding:2px 8px;border-color:var(--red);color:var(--red);">✕ Leave</button>
</div>
<div class="main">
<!-- History panel (20%) -->
<div class="panel" id="history-panel">
<div class="panel-header">📜 History</div>
<div id="history-list"></div>
</div>
<!-- Editor panel (40%) -->
<div class="panel" id="editor-panel">
<div class="panel-header">✏️ Editor</div>
<textarea id="editor" spellcheck="false" placeholder="# Hello world Start writing markdown here… Your content is saved in the URL — click **Share** to copy a link."></textarea>
</div>
<!-- Preview panel (40%) -->
<div class="panel" id="preview-panel">
<div class="panel-header">👁 Preview</div>
<div id="preview"></div>
</div>
</div>
<div class="status-bar">
<span id="lock-indicator" class="plain">🔓 Plain</span>
<span id="char-count">0 chars</span>
<span id="word-count">0 words</span>
<span id="url-size"></span>
<span class="spacer"></span>
<span id="autosave-status" style="color:var(--green);"></span>
</div>
<!-- Decrypt modal -->
<div id="modal-decrypt" class="modal-overlay hidden">
<div class="modal">
<h2>🔒 Encrypted document</h2>
<p>Enter the password to decrypt and open this document.</p>
<input type="password" id="decrypt-pw" placeholder="Password" autocomplete="current-password" />
<div id="decrypt-error" class="modal-error"></div>
<div class="modal-buttons">
<button id="btn-decrypt-cancel">Cancel</button>
<button id="btn-decrypt-ok" class="primary">Decrypt</button>
</div>
</div>
</div>
<!-- Encrypt modal -->
<div id="modal-encrypt" class="modal-overlay hidden">
<div class="modal">
<h2>🔒 Encrypt document</h2>
<p>Set a password to encrypt the document content stored in the URL. Recipients need the same password to read it. Leave blank to remove encryption.</p>
<input type="password" id="encrypt-pw" placeholder="New password (empty = remove encryption)" autocomplete="new-password" />
<input type="password" id="encrypt-pw2" placeholder="Confirm password" autocomplete="new-password" />
<div id="encrypt-error" class="modal-error"></div>
<div class="modal-buttons">
<button id="btn-encrypt-cancel">Cancel</button>
<button id="btn-encrypt-ok" class="primary">Apply</button>
</div>
</div>
</div>
<!-- Git modal -->
<div id="modal-git" class="modal-overlay hidden">
<div class="modal">
<h2>⎇ Connect to Git backend</h2>
<p>Run <code style="background:rgba(255,255,255,0.1);padding:1px 5px;border-radius:3px;">npm start</code> locally to start the git backend server, then enter its URL below.</p>
<input type="text" id="git-server-url" placeholder="http://localhost:3000" />
<input type="text" id="git-file-path" placeholder="notes/README.md (file path in repo)" />
<div id="git-error" class="modal-error"></div>
<div class="modal-buttons">
<button id="btn-git-cancel">Cancel</button>
<button id="btn-git-ok" class="primary">Connect</button>
</div>
</div>
</div>
<!-- Collaboration modal -->
<div id="modal-collab" class="modal-overlay hidden">
<div class="modal">
<h2>👥 Live Collaboration</h2>
<p>Co-edit this document in real-time with others. Peers connect directly P2P via <a href="https://github.com/dmotz/trystero" target="_blank" rel="noopener noreferrer" style="color:var(--accent)">Trystero</a> — no server required. Share the link once connected.</p>
<input type="text" id="collab-room-id" placeholder="Room ID (leave blank to create a new room)" autocomplete="off" />
<div id="collab-error" class="modal-error"></div>
<div class="modal-buttons">
<button id="btn-collab-cancel">Cancel</button>
<button id="btn-collab-ok" class="primary">Join Room</button>
</div>
</div>
</div>
<!-- Bundled libraries (marked v12 + lz-string v1) -->
<script>
/**
* marked v12.0.2 - a markdown parser
* Copyright (c) 2011-2024, Christopher Jeffrey. (MIT Licensed)
* https://github.com/markedjs/marked
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).marked={})}(this,(function(e){"use strict";function t(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}function n(t){e.defaults=t}e.defaults={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};const s=/[&<>"']/,r=new RegExp(s.source,"g"),i=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,l=new RegExp(i.source,"g"),o={"&":"&","<":"<",">":">",'"':""","'":"'"},a=e=>o[e];function c(e,t){if(t){if(s.test(e))return e.replace(r,a)}else if(i.test(e))return e.replace(l,a);return e}const h=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi;function p(e){return e.replace(h,((e,t)=>"colon"===(t=t.toLowerCase())?":":"#"===t.charAt(0)?"x"===t.charAt(1)?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""))}const u=/(^|[^\[])\^/g;function k(e,t){let n="string"==typeof e?e:e.source;t=t||"";const s={replace:(e,t)=>{let r="string"==typeof t?t:t.source;return r=r.replace(u,"$1"),n=n.replace(e,r),s},getRegex:()=>new RegExp(n,t)};return s}function g(e){try{e=encodeURI(e).replace(/%25/g,"%")}catch(e){return null}return e}const f={exec:()=>null};function d(e,t){const n=e.replace(/\|/g,((e,t,n)=>{let s=!1,r=t;for(;--r>=0&&"\\"===n[r];)s=!s;return s?"|":" |"})).split(/ \|/);let s=0;if(n[0].trim()||n.shift(),n.length>0&&!n[n.length-1].trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push("");for(;s<n.length;s++)n[s]=n[s].trim().replace(/\\\|/g,"|");return n}function x(e,t,n){const s=e.length;if(0===s)return"";let r=0;for(;r<s;){const i=e.charAt(s-r-1);if(i!==t||n){if(i===t||!n)break;r++}else r++}return e.slice(0,s-r)}function b(e,t,n,s){const r=t.href,i=t.title?c(t.title):null,l=e[1].replace(/\\([\[\]])/g,"$1");if("!"!==e[0].charAt(0)){s.state.inLink=!0;const e={type:"link",raw:n,href:r,title:i,text:l,tokens:s.inlineTokens(l)};return s.state.inLink=!1,e}return{type:"image",raw:n,href:r,title:i,text:c(l)}}class w{options;rules;lexer;constructor(t){this.options=t||e.defaults}space(e){const t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){const t=this.rules.block.code.exec(e);if(t){const e=t[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:x(e,"\n")}}}fences(e){const t=this.rules.block.fences.exec(e);if(t){const e=t[0],n=function(e,t){const n=e.match(/^(\s+)(?:```)/);if(null===n)return t;const s=n[1];return t.split("\n").map((e=>{const t=e.match(/^\s+/);if(null===t)return e;const[n]=t;return n.length>=s.length?e.slice(s.length):e})).join("\n")}(e,t[3]||"");return{type:"code",raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:n}}}heading(e){const t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(/#$/.test(e)){const t=x(e,"#");this.options.pedantic?e=t.trim():t&&!/ $/.test(t)||(e=t.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){const t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:t[0]}}blockquote(e){const t=this.rules.block.blockquote.exec(e);if(t){let e=t[0].replace(/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,"\n $1");e=x(e.replace(/^ *>[ \t]?/gm,""),"\n");const n=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(e);return this.lexer.state.top=n,{type:"blockquote",raw:t[0],tokens:s,text:e}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim();const s=n.length>1,r={type:"list",raw:"",ordered:s,start:s?+n.slice(0,-1):"",loose:!1,items:[]};n=s?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=s?n:"[*+-]");const i=new RegExp(`^( {0,3}${n})((?:[\t ][^\\n]*)?(?:\\n|$))`);let l="",o="",a=!1;for(;e;){let n=!1;if(!(t=i.exec(e)))break;if(this.rules.block.hr.test(e))break;l=t[0],e=e.substring(l.length);let s=t[2].split("\n",1)[0].replace(/^\t+/,(e=>" ".repeat(3*e.length))),c=e.split("\n",1)[0],h=0;this.options.pedantic?(h=2,o=s.trimStart()):(h=t[2].search(/[^ ]/),h=h>4?1:h,o=s.slice(h),h+=t[1].length);let p=!1;if(!s&&/^ *$/.test(c)&&(l+=c+"\n",e=e.substring(c.length+1),n=!0),!n){const t=new RegExp(`^ {0,${Math.min(3,h-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),n=new RegExp(`^ {0,${Math.min(3,h-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),r=new RegExp(`^ {0,${Math.min(3,h-1)}}(?:\`\`\`|~~~)`),i=new RegExp(`^ {0,${Math.min(3,h-1)}}#`);for(;e;){const a=e.split("\n",1)[0];if(c=a,this.options.pedantic&&(c=c.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),r.test(c))break;if(i.test(c))break;if(t.test(c))break;if(n.test(e))break;if(c.search(/[^ ]/)>=h||!c.trim())o+="\n"+c.slice(h);else{if(p)break;if(s.search(/[^ ]/)>=4)break;if(r.test(s))break;if(i.test(s))break;if(n.test(s))break;o+="\n"+c}p||c.trim()||(p=!0),l+=a+"\n",e=e.substring(a.length+1),s=c.slice(h)}}r.loose||(a?r.loose=!0:/\n *\n *$/.test(l)&&(a=!0));let u,k=null;this.options.gfm&&(k=/^\[[ xX]\] /.exec(o),k&&(u="[ ] "!==k[0],o=o.replace(/^\[[ xX]\] +/,""))),r.items.push({type:"list_item",raw:l,task:!!k,checked:u,loose:!1,text:o,tokens:[]}),r.raw+=l}r.items[r.items.length-1].raw=l.trimEnd(),r.items[r.items.length-1].text=o.trimEnd(),r.raw=r.raw.trimEnd();for(let e=0;e<r.items.length;e++)if(this.lexer.state.top=!1,r.items[e].tokens=this.lexer.blockTokens(r.items[e].text,[]),!r.loose){const t=r.items[e].tokens.filter((e=>"space"===e.type)),n=t.length>0&&t.some((e=>/\n.*\n/.test(e.raw)));r.loose=n}if(r.loose)for(let e=0;e<r.items.length;e++)r.items[e].loose=!0;return r}}html(e){const t=this.rules.block.html.exec(e);if(t){return{type:"html",block:!0,raw:t[0],pre:"pre"===t[1]||"script"===t[1]||"style"===t[1],text:t[0]}}}def(e){const t=this.rules.block.def.exec(e);if(t){const e=t[1].toLowerCase().replace(/\s+/g," "),n=t[2]?t[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:e,raw:t[0],href:n,title:s}}}table(e){const t=this.rules.block.table.exec(e);if(!t)return;if(!/[:|]/.test(t[2]))return;const n=d(t[1]),s=t[2].replace(/^\||\| *$/g,"").split("|"),r=t[3]&&t[3].trim()?t[3].replace(/\n[ \t]*$/,"").split("\n"):[],i={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===s.length){for(const e of s)/^ *-+: *$/.test(e)?i.align.push("right"):/^ *:-+: *$/.test(e)?i.align.push("center"):/^ *:-+ *$/.test(e)?i.align.push("left"):i.align.push(null);for(const e of n)i.header.push({text:e,tokens:this.lexer.inline(e)});for(const e of r)i.rows.push(d(e,i.header.length).map((e=>({text:e,tokens:this.lexer.inline(e)}))));return i}}lheading(e){const t=this.rules.block.lheading.exec(e);if(t)return{type:"heading",raw:t[0],depth:"="===t[2].charAt(0)?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){const t=this.rules.block.paragraph.exec(e);if(t){const e="\n"===t[1].charAt(t[1].length-1)?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:e,tokens:this.lexer.inline(e)}}}text(e){const t=this.rules.block.text.exec(e);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){const t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:c(t[1])}}tag(e){const t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&/^<a /i.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){const t=this.rules.inline.link.exec(e);if(t){const e=t[2].trim();if(!this.options.pedantic&&/^</.test(e)){if(!/>$/.test(e))return;const t=x(e.slice(0,-1),"\\");if((e.length-t.length)%2==0)return}else{const e=function(e,t){if(-1===e.indexOf(t[1]))return-1;let n=0;for(let s=0;s<e.length;s++)if("\\"===e[s])s++;else if(e[s]===t[0])n++;else if(e[s]===t[1]&&(n--,n<0))return s;return-1}(t[2],"()");if(e>-1){const n=(0===t[0].indexOf("!")?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=""}}let n=t[2],s="";if(this.options.pedantic){const e=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(n);e&&(n=e[1],s=e[3])}else s=t[3]?t[3].slice(1,-1):"";return n=n.trim(),/^</.test(n)&&(n=this.options.pedantic&&!/>$/.test(e)?n.slice(1):n.slice(1,-1)),b(t,{href:n?n.replace(this.rules.inline.anyPunctuation,"$1"):n,title:s?s.replace(this.rules.inline.anyPunctuation,"$1"):s},t[0],this.lexer)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){const e=t[(n[2]||n[1]).replace(/\s+/g," ").toLowerCase()];if(!e){const e=n[0].charAt(0);return{type:"text",raw:e,text:e}}return b(n,e,n[0],this.lexer)}}emStrong(e,t,n=""){let s=this.rules.inline.emStrongLDelim.exec(e);if(!s)return;if(s[3]&&n.match(/[\p{L}\p{N}]/u))return;if(!(s[1]||s[2]||"")||!n||this.rules.inline.punctuation.exec(n)){const n=[...s[0]].length-1;let r,i,l=n,o=0;const a="*"===s[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(a.lastIndex=0,t=t.slice(-1*e.length+n);null!=(s=a.exec(t));){if(r=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!r)continue;if(i=[...r].length,s[3]||s[4]){l+=i;continue}if((s[5]||s[6])&&n%3&&!((n+i)%3)){o+=i;continue}if(l-=i,l>0)continue;i=Math.min(i,i+l+o);const t=[...s[0]][0].length,a=e.slice(0,n+s.index+t+i);if(Math.min(n,i)%2){const e=a.slice(1,-1);return{type:"em",raw:a,text:e,tokens:this.lexer.inlineTokens(e)}}const c=a.slice(2,-2);return{type:"strong",raw:a,text:c,tokens:this.lexer.inlineTokens(c)}}}}codespan(e){const t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(/\n/g," ");const n=/[^ ]/.test(e),s=/^ /.test(e)&&/ $/.test(e);return n&&s&&(e=e.substring(1,e.length-1)),e=c(e,!0),{type:"codespan",raw:t[0],text:e}}}br(e){const t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e){const t=this.rules.inline.del.exec(e);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}autolink(e){const t=this.rules.inline.autolink.exec(e);if(t){let e,n;return"@"===t[2]?(e=c(t[1]),n="mailto:"+e):(e=c(t[1]),n=e),{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if("@"===t[2])e=c(t[0]),n="mailto:"+e;else{let s;do{s=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??""}while(s!==t[0]);e=c(t[0]),n="www."===t[1]?"http://"+t[0]:t[0]}return{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}inlineText(e){const t=this.rules.inline.text.exec(e);if(t){let e;return e=this.lexer.state.inRawBlock?t[0]:c(t[0]),{type:"text",raw:t[0],text:e}}}}const m=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,y=/(?:[*+-]|\d{1,9}[.)])/,$=k(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).replace(/bull/g,y).replace(/blockCode/g,/ {4}/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).getRegex(),z=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,T=/(?!\s*\])(?:\\.|[^\[\]\\])+/,R=k(/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/).replace("label",T).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),_=k(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,y).getRegex(),A="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",S=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,I=k("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))","i").replace("comment",S).replace("tag",A).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),E=k(z).replace("hr",m).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",A).getRegex(),q={blockquote:k(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",E).getRegex(),code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,def:R,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:m,html:I,lheading:$,list:_,newline:/^(?: *(?:\n|$))+/,paragraph:E,table:f,text:/^[^\n]+/},Z=k("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",m).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",A).getRegex(),L={...q,table:Z,paragraph:k(z).replace("hr",m).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Z).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",A).getRegex()},P={...q,html:k("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",S).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:f,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:k(z).replace("hr",m).replace("heading"," *#{1,6} *[^\n]").replace("lheading",$).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Q=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,v=/^( {2,}|\\)\n(?!\s*$)/,B="\\p{P}\\p{S}",C=k(/^((?![*_])[\spunctuation])/,"u").replace(/punctuation/g,B).getRegex(),M=k(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/,"u").replace(/punct/g,B).getRegex(),O=k("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)[punct](\\*+)(?=[\\s]|$)|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])|[\\s](\\*+)(?!\\*)(?=[punct])|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])|[^punct\\s](\\*+)(?=[^punct\\s])","gu").replace(/punct/g,B).getRegex(),D=k("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\\s]|$)|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)|(?!_)[punct\\s](_+)(?=[^punct\\s])|[\\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])","gu").replace(/punct/g,B).getRegex(),j=k(/\\([punct])/,"gu").replace(/punct/g,B).getRegex(),H=k(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),U=k(S).replace("(?:--\x3e|$)","--\x3e").getRegex(),X=k("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",U).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),F=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,N=k(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label",F).replace("href",/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),G=k(/^!?\[(label)\]\[(ref)\]/).replace("label",F).replace("ref",T).getRegex(),J=k(/^!?\[(ref)\](?:\[\])?/).replace("ref",T).getRegex(),K={_backpedal:f,anyPunctuation:j,autolink:H,blockSkip:/\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g,br:v,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:f,emStrongLDelim:M,emStrongRDelimAst:O,emStrongRDelimUnd:D,escape:Q,link:N,nolink:J,punctuation:C,reflink:G,reflinkSearch:k("reflink|nolink(?!\\()","g").replace("reflink",G).replace("nolink",J).getRegex(),tag:X,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,url:f},V={...K,link:k(/^!?\[(label)\]\((.*?)\)/).replace("label",F).getRegex(),reflink:k(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",F).getRegex()},W={...K,escape:k(Q).replace("])","~|])").getRegex(),url:k(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},Y={...W,br:k(v).replace("{2,}","*").getRegex(),text:k(W.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},ee={normal:q,gfm:L,pedantic:P},te={normal:K,gfm:W,breaks:Y,pedantic:V};class ne{tokens;options;state;tokenizer;inlineQueue;constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||e.defaults,this.options.tokenizer=this.options.tokenizer||new w,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const n={block:ee.normal,inline:te.normal};this.options.pedantic?(n.block=ee.pedantic,n.inline=te.pedantic):this.options.gfm&&(n.block=ee.gfm,this.options.breaks?n.inline=te.breaks:n.inline=te.gfm),this.tokenizer.rules=n}static get rules(){return{block:ee,inline:te}}static lex(e,t){return new ne(t).lex(e)}static lexInline(e,t){return new ne(t).inlineTokens(e)}lex(e){e=e.replace(/\r\n|\r/g,"\n"),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){const t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[]){let n,s,r,i;for(e=this.options.pedantic?e.replace(/\t/g," ").replace(/^ +$/gm,""):e.replace(/^( *)(\t+)/gm,((e,t,n)=>t+" ".repeat(n.length)));e;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some((s=>!!(n=s.call({lexer:this},e,t))&&(e=e.substring(n.raw.length),t.push(n),!0)))))if(n=this.tokenizer.space(e))e=e.substring(n.raw.length),1===n.raw.length&&t.length>0?t[t.length-1].raw+="\n":t.push(n);else if(n=this.tokenizer.code(e))e=e.substring(n.raw.length),s=t[t.length-1],!s||"paragraph"!==s.type&&"text"!==s.type?t.push(n):(s.raw+="\n"+n.raw,s.text+="\n"+n.text,this.inlineQueue[this.inlineQueue.length-1].src=s.text);else if(n=this.tokenizer.fences(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.heading(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.hr(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.blockquote(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.list(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.html(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.def(e))e=e.substring(n.raw.length),s=t[t.length-1],!s||"paragraph"!==s.type&&"text"!==s.type?this.tokens.links[n.tag]||(this.tokens.links[n.tag]={href:n.href,title:n.title}):(s.raw+="\n"+n.raw,s.text+="\n"+n.raw,this.inlineQueue[this.inlineQueue.length-1].src=s.text);else if(n=this.tokenizer.table(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.lheading(e))e=e.substring(n.raw.length),t.push(n);else{if(r=e,this.options.extensions&&this.options.extensions.startBlock){let t=1/0;const n=e.slice(1);let s;this.options.extensions.startBlock.forEach((e=>{s=e.call({lexer:this},n),"number"==typeof s&&s>=0&&(t=Math.min(t,s))})),t<1/0&&t>=0&&(r=e.substring(0,t+1))}if(this.state.top&&(n=this.tokenizer.paragraph(r)))s=t[t.length-1],i&&"paragraph"===s.type?(s.raw+="\n"+n.raw,s.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=s.text):t.push(n),i=r.length!==e.length,e=e.substring(n.raw.length);else if(n=this.tokenizer.text(e))e=e.substring(n.raw.length),s=t[t.length-1],s&&"text"===s.type?(s.raw+="\n"+n.raw,s.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=s.text):t.push(n);else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let n,s,r,i,l,o,a=e;if(this.tokens.links){const e=Object.keys(this.tokens.links);if(e.length>0)for(;null!=(i=this.tokenizer.rules.inline.reflinkSearch.exec(a));)e.includes(i[0].slice(i[0].lastIndexOf("[")+1,-1))&&(a=a.slice(0,i.index)+"["+"a".repeat(i[0].length-2)+"]"+a.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(i=this.tokenizer.rules.inline.blockSkip.exec(a));)a=a.slice(0,i.index)+"["+"a".repeat(i[0].length-2)+"]"+a.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;null!=(i=this.tokenizer.rules.inline.anyPunctuation.exec(a));)a=a.slice(0,i.index)+"++"+a.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;e;)if(l||(o=""),l=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some((s=>!!(n=s.call({lexer:this},e,t))&&(e=e.substring(n.raw.length),t.push(n),!0)))))if(n=this.tokenizer.escape(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.tag(e))e=e.substring(n.raw.length),s=t[t.length-1],s&&"text"===n.type&&"text"===s.type?(s.raw+=n.raw,s.text+=n.text):t.push(n);else if(n=this.tokenizer.link(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.reflink(e,this.tokens.links))e=e.substring(n.raw.length),s=t[t.length-1],s&&"text"===n.type&&"text"===s.type?(s.raw+=n.raw,s.text+=n.text):t.push(n);else if(n=this.tokenizer.emStrong(e,a,o))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.codespan(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.br(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.del(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.autolink(e))e=e.substring(n.raw.length),t.push(n);else if(this.state.inLink||!(n=this.tokenizer.url(e))){if(r=e,this.options.extensions&&this.options.extensions.startInline){let t=1/0;const n=e.slice(1);let s;this.options.extensions.startInline.forEach((e=>{s=e.call({lexer:this},n),"number"==typeof s&&s>=0&&(t=Math.min(t,s))})),t<1/0&&t>=0&&(r=e.substring(0,t+1))}if(n=this.tokenizer.inlineText(r))e=e.substring(n.raw.length),"_"!==n.raw.slice(-1)&&(o=n.raw.slice(-1)),l=!0,s=t[t.length-1],s&&"text"===s.type?(s.raw+=n.raw,s.text+=n.text):t.push(n);else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}else e=e.substring(n.raw.length),t.push(n);return t}}class se{options;constructor(t){this.options=t||e.defaults}code(e,t,n){const s=(t||"").match(/^\S*/)?.[0];return e=e.replace(/\n$/,"")+"\n",s?'<pre><code class="language-'+c(s)+'">'+(n?e:c(e,!0))+"</code></pre>\n":"<pre><code>"+(n?e:c(e,!0))+"</code></pre>\n"}blockquote(e){return`<blockquote>\n${e}</blockquote>\n`}html(e,t){return e}heading(e,t,n){return`<h${t}>${e}</h${t}>\n`}hr(){return"<hr>\n"}list(e,t,n){const s=t?"ol":"ul";return"<"+s+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"</"+s+">\n"}listitem(e,t,n){return`<li>${e}</li>\n`}checkbox(e){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph(e){return`<p>${e}</p>\n`}table(e,t){return t&&(t=`<tbody>${t}</tbody>`),"<table>\n<thead>\n"+e+"</thead>\n"+t+"</table>\n"}tablerow(e){return`<tr>\n${e}</tr>\n`}tablecell(e,t){const n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>\n`}strong(e){return`<strong>${e}</strong>`}em(e){return`<em>${e}</em>`}codespan(e){return`<code>${e}</code>`}br(){return"<br>"}del(e){return`<del>${e}</del>`}link(e,t,n){const s=g(e);if(null===s)return n;let r='<a href="'+(e=s)+'"';return t&&(r+=' title="'+t+'"'),r+=">"+n+"</a>",r}image(e,t,n){const s=g(e);if(null===s)return n;let r=`<img src="${e=s}" alt="${n}"`;return t&&(r+=` title="${t}"`),r+=">",r}text(e){return e}}class re{strong(e){return e}em(e){return e}codespan(e){return e}del(e){return e}html(e){return e}text(e){return e}link(e,t,n){return""+n}image(e,t,n){return""+n}br(){return""}}class ie{options;renderer;textRenderer;constructor(t){this.options=t||e.defaults,this.options.renderer=this.options.renderer||new se,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new re}static parse(e,t){return new ie(t).parse(e)}static parseInline(e,t){return new ie(t).parseInline(e)}parse(e,t=!0){let n="";for(let s=0;s<e.length;s++){const r=e[s];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[r.type]){const e=r,t=this.options.extensions.renderers[e.type].call({parser:this},e);if(!1!==t||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(e.type)){n+=t||"";continue}}switch(r.type){case"space":continue;case"hr":n+=this.renderer.hr();continue;case"heading":{const e=r;n+=this.renderer.heading(this.parseInline(e.tokens),e.depth,p(this.parseInline(e.tokens,this.textRenderer)));continue}case"code":{const e=r;n+=this.renderer.code(e.text,e.lang,!!e.escaped);continue}case"table":{const e=r;let t="",s="";for(let t=0;t<e.header.length;t++)s+=this.renderer.tablecell(this.parseInline(e.header[t].tokens),{header:!0,align:e.align[t]});t+=this.renderer.tablerow(s);let i="";for(let t=0;t<e.rows.length;t++){const n=e.rows[t];s="";for(let t=0;t<n.length;t++)s+=this.renderer.tablecell(this.parseInline(n[t].tokens),{header:!1,align:e.align[t]});i+=this.renderer.tablerow(s)}n+=this.renderer.table(t,i);continue}case"blockquote":{const e=r,t=this.parse(e.tokens);n+=this.renderer.blockquote(t);continue}case"list":{const e=r,t=e.ordered,s=e.start,i=e.loose;let l="";for(let t=0;t<e.items.length;t++){const n=e.items[t],s=n.checked,r=n.task;let o="";if(n.task){const e=this.renderer.checkbox(!!s);i?n.tokens.length>0&&"paragraph"===n.tokens[0].type?(n.tokens[0].text=e+" "+n.tokens[0].text,n.tokens[0].tokens&&n.tokens[0].tokens.length>0&&"text"===n.tokens[0].tokens[0].type&&(n.tokens[0].tokens[0].text=e+" "+n.tokens[0].tokens[0].text)):n.tokens.unshift({type:"text",text:e+" "}):o+=e+" "}o+=this.parse(n.tokens,i),l+=this.renderer.listitem(o,r,!!s)}n+=this.renderer.list(l,t,s);continue}case"html":{const e=r;n+=this.renderer.html(e.text,e.block);continue}case"paragraph":{const e=r;n+=this.renderer.paragraph(this.parseInline(e.tokens));continue}case"text":{let i=r,l=i.tokens?this.parseInline(i.tokens):i.text;for(;s+1<e.length&&"text"===e[s+1].type;)i=e[++s],l+="\n"+(i.tokens?this.parseInline(i.tokens):i.text);n+=t?this.renderer.paragraph(l):l;continue}default:{const e='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}parseInline(e,t){t=t||this.renderer;let n="";for(let s=0;s<e.length;s++){const r=e[s];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[r.type]){const e=this.options.extensions.renderers[r.type].call({parser:this},r);if(!1!==e||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(r.type)){n+=e||"";continue}}switch(r.type){case"escape":{const e=r;n+=t.text(e.text);break}case"html":{const e=r;n+=t.html(e.text);break}case"link":{const e=r;n+=t.link(e.href,e.title,this.parseInline(e.tokens,t));break}case"image":{const e=r;n+=t.image(e.href,e.title,e.text);break}case"strong":{const e=r;n+=t.strong(this.parseInline(e.tokens,t));break}case"em":{const e=r;n+=t.em(this.parseInline(e.tokens,t));break}case"codespan":{const e=r;n+=t.codespan(e.text);break}case"br":n+=t.br();break;case"del":{const e=r;n+=t.del(this.parseInline(e.tokens,t));break}case"text":{const e=r;n+=t.text(e.text);break}default:{const e='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}}class le{options;constructor(t){this.options=t||e.defaults}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}}class oe{defaults={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};options=this.setOptions;parse=this.#e(ne.lex,ie.parse);parseInline=this.#e(ne.lexInline,ie.parseInline);Parser=ie;Renderer=se;TextRenderer=re;Lexer=ne;Tokenizer=w;Hooks=le;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(const s of e)switch(n=n.concat(t.call(this,s)),s.type){case"table":{const e=s;for(const s of e.header)n=n.concat(this.walkTokens(s.tokens,t));for(const s of e.rows)for(const e of s)n=n.concat(this.walkTokens(e.tokens,t));break}case"list":{const e=s;n=n.concat(this.walkTokens(e.items,t));break}default:{const e=s;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach((s=>{const r=e[s].flat(1/0);n=n.concat(this.walkTokens(r,t))})):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){const t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach((e=>{const n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach((e=>{if(!e.name)throw new Error("extension name required");if("renderer"in e){const n=t.renderers[e.name];t.renderers[e.name]=n?function(...t){let s=e.renderer.apply(this,t);return!1===s&&(s=n.apply(this,t)),s}:e.renderer}if("tokenizer"in e){if(!e.level||"block"!==e.level&&"inline"!==e.level)throw new Error("extension level must be 'block' or 'inline'");const n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&("block"===e.level?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:"inline"===e.level&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}"childTokens"in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)})),n.extensions=t),e.renderer){const t=this.defaults.renderer||new se(this.defaults);for(const n in e.renderer){if(!(n in t))throw new Error(`renderer '${n}' does not exist`);if("options"===n)continue;const s=n,r=e.renderer[s],i=t[s];t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=i.apply(t,e)),n||""}}n.renderer=t}if(e.tokenizer){const t=this.defaults.tokenizer||new w(this.defaults);for(const n in e.tokenizer){if(!(n in t))throw new Error(`tokenizer '${n}' does not exist`);if(["options","rules","lexer"].includes(n))continue;const s=n,r=e.tokenizer[s],i=t[s];t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=i.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){const t=this.defaults.hooks||new le;for(const n in e.hooks){if(!(n in t))throw new Error(`hook '${n}' does not exist`);if("options"===n)continue;const s=n,r=e.hooks[s],i=t[s];le.passThroughHooks.has(n)?t[s]=e=>{if(this.defaults.async)return Promise.resolve(r.call(t,e)).then((e=>i.call(t,e)));const n=r.call(t,e);return i.call(t,n)}:t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=i.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){const t=this.defaults.walkTokens,s=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(s.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}})),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return ne.lex(e,t??this.defaults)}parser(e,t){return ie.parse(e,t??this.defaults)}#e(e,t){return(n,s)=>{const r={...s},i={...this.defaults,...r};!0===this.defaults.async&&!1===r.async&&(i.silent||console.warn("marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored."),i.async=!0);const l=this.#t(!!i.silent,!!i.async);if(null==n)return l(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof n)return l(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(i.hooks&&(i.hooks.options=i),i.async)return Promise.resolve(i.hooks?i.hooks.preprocess(n):n).then((t=>e(t,i))).then((e=>i.hooks?i.hooks.processAllTokens(e):e)).then((e=>i.walkTokens?Promise.all(this.walkTokens(e,i.walkTokens)).then((()=>e)):e)).then((e=>t(e,i))).then((e=>i.hooks?i.hooks.postprocess(e):e)).catch(l);try{i.hooks&&(n=i.hooks.preprocess(n));let s=e(n,i);i.hooks&&(s=i.hooks.processAllTokens(s)),i.walkTokens&&this.walkTokens(s,i.walkTokens);let r=t(s,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(e){return l(e)}}}#t(e,t){return n=>{if(n.message+="\nPlease report this to https://github.com/markedjs/marked.",e){const e="<p>An error occurred:</p><pre>"+c(n.message+"",!0)+"</pre>";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}}const ae=new oe;function ce(e,t){return ae.parse(e,t)}ce.options=ce.setOptions=function(e){return ae.setOptions(e),ce.defaults=ae.defaults,n(ce.defaults),ce},ce.getDefaults=t,ce.defaults=e.defaults,ce.use=function(...e){return ae.use(...e),ce.defaults=ae.defaults,n(ce.defaults),ce},ce.walkTokens=function(e,t){return ae.walkTokens(e,t)},ce.parseInline=ae.parseInline,ce.Parser=ie,ce.parser=ie.parse,ce.Renderer=se,ce.TextRenderer=re,ce.Lexer=ne,ce.lexer=ne.lex,ce.Tokenizer=w,ce.Hooks=le,ce.parse=ce;const he=ce.options,pe=ce.setOptions,ue=ce.use,ke=ce.walkTokens,ge=ce.parseInline,fe=ce,de=ie.parse,xe=ne.lex;e.Hooks=le,e.Lexer=ne,e.Marked=oe,e.Parser=ie,e.Renderer=se,e.TextRenderer=re,e.Tokenizer=w,e.getDefaults=t,e.lexer=xe,e.marked=ce,e.options=he,e.parse=fe,e.parseInline=ge,e.parser=de,e.setOptions=pe,e.use=ue,e.walkTokens=ke}));
</script>
<script>
var LZString=function(){var r=String.fromCharCode,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",e={};function t(r,o){if(!e[r]){e[r]={};for(var n=0;n<r.length;n++)e[r][r.charAt(n)]=n}return e[r][o]}var i={compressToBase64:function(r){if(null==r)return"";var n=i._compress(r,6,function(r){return o.charAt(r)});switch(n.length%4){default:case 0:return n;case 1:return n+"===";case 2:return n+"==";case 3:return n+"="}},decompressFromBase64:function(r){return null==r?"":""==r?null:i._decompress(r.length,32,function(n){return t(o,r.charAt(n))})},compressToUTF16:function(o){return null==o?"":i._compress(o,15,function(o){return r(o+32)})+" "},decompressFromUTF16:function(r){return null==r?"":""==r?null:i._decompress(r.length,16384,function(o){return r.charCodeAt(o)-32})},compressToUint8Array:function(r){for(var o=i.compress(r),n=new Uint8Array(2*o.length),e=0,t=o.length;e<t;e++){var s=o.charCodeAt(e);n[2*e]=s>>>8,n[2*e+1]=s%256}return n},decompressFromUint8Array:function(o){if(null==o)return i.decompress(o);for(var n=new Array(o.length/2),e=0,t=n.length;e<t;e++)n[e]=256*o[2*e]+o[2*e+1];var s=[];return n.forEach(function(o){s.push(r(o))}),i.decompress(s.join(""))},compressToEncodedURIComponent:function(r){return null==r?"":i._compress(r,6,function(r){return n.charAt(r)})},decompressFromEncodedURIComponent:function(r){return null==r?"":""==r?null:(r=r.replace(/ /g,"+"),i._decompress(r.length,32,function(o){return t(n,r.charAt(o))}))},compress:function(o){return i._compress(o,16,function(o){return r(o)})},_compress:function(r,o,n){if(null==r)return"";var e,t,i,s={},u={},a="",p="",c="",l=2,f=3,h=2,d=[],m=0,v=0;for(i=0;i<r.length;i+=1)if(a=r.charAt(i),Object.prototype.hasOwnProperty.call(s,a)||(s[a]=f++,u[a]=!0),p=c+a,Object.prototype.hasOwnProperty.call(s,p))c=p;else{if(Object.prototype.hasOwnProperty.call(u,c)){if(c.charCodeAt(0)<256){for(e=0;e<h;e++)m<<=1,v==o-1?(v=0,d.push(n(m)),m=0):v++;for(t=c.charCodeAt(0),e=0;e<8;e++)m=m<<1|1&t,v==o-1?(v=0,d.push(n(m)),m=0):v++,t>>=1}else{for(t=1,e=0;e<h;e++)m=m<<1|t,v==o-1?(v=0,d.push(n(m)),m=0):v++,t=0;for(t=c.charCodeAt(0),e=0;e<16;e++)m=m<<1|1&t,v==o-1?(v=0,d.push(n(m)),m=0):v++,t>>=1}0==--l&&(l=Math.pow(2,h),h++),delete u[c]}else for(t=s[c],e=0;e<h;e++)m=m<<1|1&t,v==o-1?(v=0,d.push(n(m)),m=0):v++,t>>=1;0==--l&&(l=Math.pow(2,h),h++),s[p]=f++,c=String(a)}if(""!==c){if(Object.prototype.hasOwnProperty.call(u,c)){if(c.charCodeAt(0)<256){for(e=0;e<h;e++)m<<=1,v==o-1?(v=0,d.push(n(m)),m=0):v++;for(t=c.charCodeAt(0),e=0;e<8;e++)m=m<<1|1&t,v==o-1?(v=0,d.push(n(m)),m=0):v++,t>>=1}else{for(t=1,e=0;e<h;e++)m=m<<1|t,v==o-1?(v=0,d.push(n(m)),m=0):v++,t=0;for(t=c.charCodeAt(0),e=0;e<16;e++)m=m<<1|1&t,v==o-1?(v=0,d.push(n(m)),m=0):v++,t>>=1}0==--l&&(l=Math.pow(2,h),h++),delete u[c]}else for(t=s[c],e=0;e<h;e++)m=m<<1|1&t,v==o-1?(v=0,d.push(n(m)),m=0):v++,t>>=1;0==--l&&(l=Math.pow(2,h),h++)}for(t=2,e=0;e<h;e++)m=m<<1|1&t,v==o-1?(v=0,d.push(n(m)),m=0):v++,t>>=1;for(;;){if(m<<=1,v==o-1){d.push(n(m));break}v++}return d.join("")},decompress:function(r){return null==r?"":""==r?null:i._decompress(r.length,32768,function(o){return r.charCodeAt(o)})},_decompress:function(o,n,e){var t,i,s,u,a,p,c,l=[],f=4,h=4,d=3,m="",v=[],g={val:e(0),position:n,index:1};for(t=0;t<3;t+=1)l[t]=t;for(s=0,a=Math.pow(2,2),p=1;p!=a;)u=g.val&g.position,g.position>>=1,0==g.position&&(g.position=n,g.val=e(g.index++)),s|=(u>0?1:0)*p,p<<=1;switch(s){case 0:for(s=0,a=Math.pow(2,8),p=1;p!=a;)u=g.val&g.position,g.position>>=1,0==g.position&&(g.position=n,g.val=e(g.index++)),s|=(u>0?1:0)*p,p<<=1;c=r(s);break;case 1:for(s=0,a=Math.pow(2,16),p=1;p!=a;)u=g.val&g.position,g.position>>=1,0==g.position&&(g.position=n,g.val=e(g.index++)),s|=(u>0?1:0)*p,p<<=1;c=r(s);break;case 2:return""}for(l[3]=c,i=c,v.push(c);;){if(g.index>o)return"";for(s=0,a=Math.pow(2,d),p=1;p!=a;)u=g.val&g.position,g.position>>=1,0==g.position&&(g.position=n,g.val=e(g.index++)),s|=(u>0?1:0)*p,p<<=1;switch(c=s){case 0:for(s=0,a=Math.pow(2,8),p=1;p!=a;)u=g.val&g.position,g.position>>=1,0==g.position&&(g.position=n,g.val=e(g.index++)),s|=(u>0?1:0)*p,p<<=1;l[h++]=r(s),c=h-1,f--;break;case 1:for(s=0,a=Math.pow(2,16),p=1;p!=a;)u=g.val&g.position,g.position>>=1,0==g.position&&(g.position=n,g.val=e(g.index++)),s|=(u>0?1:0)*p,p<<=1;l[h++]=r(s),c=h-1,f--;break;case 2:return v.join("")}if(0==f&&(f=Math.pow(2,d),d++),l[c])m=l[c];else{if(c!==h)return null;m=i+i.charAt(0)}v.push(m),l[h++]=i+m.charAt(0),i=m,0==--f&&(f=Math.pow(2,d),d++)}}};return i}();"function"==typeof define&&define.amd?define(function(){return LZString}):"undefined"!=typeof module&&null!=module?module.exports=LZString:"undefined"!=typeof angular&&null!=angular&&angular.module("LZString",[]).factory("LZString",function(){return LZString});
</script>
<script>
'use strict';
// ── Constants ────────────────────────────────────────────────────────────────
const VERSION = 'v1';
const PBKDF2_ITER = 100000;
const SALT_LEN = 16;
const IV_LEN = 12;
const HISTORY_KEY = 'stringmd_history';
const MAX_HISTORY = 60;
const AUTOSAVE_MS = 600;
// ── State ────────────────────────────────────────────────────────────────────
let currentPassword = null; // active encryption password (null = plain)
let autoSaveTimer = null;
let historyEntries = []; // [{id, time, content, encrypted}]
let gitConfig = null; // {serverUrl, filePath} when connected
let pendingDecryptData = null; // base64 payload waiting for password input
window._collabRoomId = null; // set by the collab module when in a live session
// ── DOM refs ─────────────────────────────────────────────────────────────────
const editor = document.getElementById('editor');
const preview = document.getElementById('preview');
const historyList = document.getElementById('history-list');
const lockIndicator = document.getElementById('lock-indicator');
const charCount = document.getElementById('char-count');
const wordCount = document.getElementById('word-count');
const urlSize = document.getElementById('url-size');
const autosaveStatus = document.getElementById('autosave-status');
const gitBar = document.getElementById('git-bar');
const gitBranchLabel = document.getElementById('git-branch-label');
const gitFileLabel = document.getElementById('git-file-label');
// ── Crypto helpers ────────────────────────────────────────────────────────────
async function deriveKey(password, salt) {
const raw = await crypto.subtle.importKey(
'raw', new TextEncoder().encode(password), 'PBKDF2', false, ['deriveKey']
);
return crypto.subtle.deriveKey(
{ name: 'PBKDF2', salt, iterations: PBKDF2_ITER, hash: 'SHA-256' },
raw,
{ name: 'AES-GCM', length: 256 },
false, ['encrypt', 'decrypt']
);
}
async function encryptContent(content, password) {
const salt = crypto.getRandomValues(new Uint8Array(SALT_LEN));
const iv = crypto.getRandomValues(new Uint8Array(IV_LEN));
const key = await deriveKey(password, salt);
const ct = await crypto.subtle.encrypt(
{ name: 'AES-GCM', iv }, key, new TextEncoder().encode(content)
);
const buf = new Uint8Array(SALT_LEN + IV_LEN + ct.byteLength);
buf.set(salt);
buf.set(iv, SALT_LEN);
buf.set(new Uint8Array(ct), SALT_LEN + IV_LEN);
// Use URL-safe base64
// Chunked to avoid stack overflow on large files
let binary = '';
for (let i = 0; i < buf.length; i += 8192) {
binary += String.fromCharCode(...buf.subarray(i, i + 8192));
}
return btoa(binary).replace(/\+/g,'-').replace(/\//g,'_').replace(/=+$/,'');
}
async function decryptContent(encoded, password) {
// Restore standard base64
const b64 = encoded.replace(/-/g,'+').replace(/_/g,'/');
const buf = Uint8Array.from(atob(b64), c => c.charCodeAt(0));
const salt = buf.slice(0, SALT_LEN);
const iv = buf.slice(SALT_LEN, SALT_LEN + IV_LEN);
const ct = buf.slice(SALT_LEN + IV_LEN);
const key = await deriveKey(password, salt);
const pt = await crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, ct);
return new TextDecoder().decode(pt);
}
// ── URL helpers ───────────────────────────────────────────────────────────────
async function buildHash(content, password) {
if (password) {
const enc = await encryptContent(content, password);
return `#${VERSION}:enc:${enc}`;
}
const compressed = LZString.compressToEncodedURIComponent(content);
return `#${VERSION}:plain:${compressed}`;
}
async function parseHash(hash) {
if (!hash || !hash.startsWith('#')) return { content: '' };
const raw = hash.slice(1);
const colonIdx = raw.indexOf(':');
if (colonIdx === -1) return { content: '' };
const ver = raw.slice(0, colonIdx);
if (ver !== VERSION) return { content: '' };
const rest = raw.slice(colonIdx + 1);
const colon2 = rest.indexOf(':');
if (colon2 === -1) return { content: '' };
const type = rest.slice(0, colon2);
const data = rest.slice(colon2 + 1);
if (type === 'plain') {
return { content: LZString.decompressFromEncodedURIComponent(data) || '', encrypted: false };
}
if (type === 'enc') {
return { encrypted: true, data };
}
return { content: '' };
}
async function updateURL() {
const hash = await buildHash(editor.value, currentPassword);
const roomParam = window._collabRoomId ? `?room=${encodeURIComponent(window._collabRoomId)}` : '';
history.replaceState(null, '', roomParam + hash);
urlSize.textContent = `URL: ${((roomParam + hash).length / 1024).toFixed(1)} KB`;
}
function scheduleAutoSave() {
clearTimeout(autoSaveTimer);
autosaveStatus.textContent = '';
autoSaveTimer = setTimeout(async () => {
await updateURL();
addHistoryEntry(editor.value);
autosaveStatus.textContent = 'saved ✓';
setTimeout(() => { autosaveStatus.textContent = ''; }, 1500);
}, AUTOSAVE_MS);
}
// ── Preview ───────────────────────────────────────────────────────────────────
function updatePreview() {
const html = typeof marked !== 'undefined'
? marked.parse(editor.value || '')
: `<pre>${escapeHtml(editor.value)}</pre>`;
preview.innerHTML = html;
}
// ── Stats ─────────────────────────────────────────────────────────────────────
function updateStats() {
const text = editor.value;
charCount.textContent = `${text.length} chars`;
const words = text.trim() ? text.trim().split(/\s+/).length : 0;
wordCount.textContent = `${words} words`;
}
// ── History ───────────────────────────────────────────────────────────────────
function loadHistory() {
try { historyEntries = JSON.parse(localStorage.getItem(HISTORY_KEY) || '[]'); }
catch { historyEntries = []; }
}
function saveHistory() {
localStorage.setItem(HISTORY_KEY, JSON.stringify(historyEntries));
}
function addHistoryEntry(content) {
// Skip storing history when document is encrypted to avoid writing
// plaintext content to localStorage (which would defeat E2E encryption).
if (currentPassword) return;
if (!content.trim()) return;
if (historyEntries.length && historyEntries[0].content === content) return;
historyEntries.unshift({ id: crypto.randomUUID(), time: new Date().toISOString(), content, encrypted: !!currentPassword });
if (historyEntries.length > MAX_HISTORY) historyEntries.pop();
saveHistory();
renderHistory();
}
async function renderHistory(gitLog) {
historyList.innerHTML = '';
// Git log section
if (gitLog && gitLog.length) {
const label = document.createElement('div');
label.className = 'history-section-label';
label.textContent = 'Git commits';
historyList.appendChild(label);
gitLog.forEach(commit => {
if (!commit || typeof commit !== 'object') return;
const sha = typeof commit.sha === 'string' && commit.sha.length >= 4 ? commit.sha : null;
if (!sha) return;
const message = typeof commit.message === 'string' ? commit.message : '';
const author = typeof commit.author === 'string' ? commit.author : 'Unknown';
const d = commit.date ? new Date(commit.date) : null;
const dateStr = (d && !isNaN(d.getTime())) ? d.toLocaleDateString() : '';
const div = document.createElement('div');
div.className = 'history-entry git-entry';
div.innerHTML = `
<div class="he-time"><span class="he-sha"></span></div>
<div class="he-preview">${escapeHtml(message)}</div>
<div class="he-author">${escapeHtml(author)}${dateStr ? ' · ' + dateStr : ''}</div>`;
div.querySelector('.he-sha').textContent = sha.slice(0, 7);
div.addEventListener('click', () => loadGitCommit(sha));
historyList.appendChild(div);
});
}
// Local history section
const localLabel = document.createElement('div');
localLabel.className = 'history-section-label';
localLabel.textContent = 'Local history';
historyList.appendChild(localLabel);
if (!historyEntries.length) {
const empty = document.createElement('p');
empty.style.cssText = 'padding:10px;color:var(--text-dim);font-size:0.8rem;';
empty.textContent = 'No local history yet.';
historyList.appendChild(empty);
return;
}
historyEntries.forEach((entry, i) => {
const div = document.createElement('div');
div.className = 'history-entry' + (i === 0 ? ' active' : '');
const d = new Date(entry.time);
const ts = d.toLocaleDateString() + ' ' + d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
const snippet = entry.encrypted
? '🔒 encrypted'
: (entry.content.slice(0, 55).replace(/\n/g, ' ') || '(empty)');
div.innerHTML = `<div class="he-time">${ts}${entry.encrypted ? ' 🔒' : ''}</div>
<div class="he-preview">${escapeHtml(snippet)}</div>`;
div.addEventListener('click', () => {
if (entry.encrypted && !currentPassword) {
showToast('Cannot restore encrypted entry — set a password first', 'error');
return;
}
editor.value = entry.content;
updatePreview();
updateStats();
updateURL();
});
historyList.appendChild(div);
});
}
// ── Toast ─────────────────────────────────────────────────────────────────────
function showToast(msg, type = 'success') {
const t = document.createElement('div');
t.className = `toast ${type}`;
t.textContent = msg;
document.body.appendChild(t);
setTimeout(() => t.remove(), 3000);
}
// ── Lock indicator ────────────────────────────────────────────────────────────
function updateLockIndicator() {
if (currentPassword) {
lockIndicator.textContent = '🔒 Encrypted';
lockIndicator.className = '';
} else {
lockIndicator.textContent = '🔓 Plain';
lockIndicator.className = 'plain';
}
}
// ── Util ──────────────────────────────────────────────────────────────────────
function escapeHtml(s) {
return String(s)
.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>')
.replace(/"/g,'"');
}
// ── Button: Share ─────────────────────────────────────────────────────────────
document.getElementById('btn-share').addEventListener('click', async () => {
await updateURL();
const url = location.href;
try {
await navigator.clipboard.writeText(url);
showToast('URL copied to clipboard!');
} catch {
prompt('Copy this shareable URL:', url);
}
});
// ── Button: New ───────────────────────────────────────────────────────────────
document.getElementById('btn-new').addEventListener('click', () => {
if (editor.value && !confirm('Start a new document? Current content will be lost.')) return;
editor.value = '';
currentPassword = null;
updateLockIndicator();
updatePreview();
updateStats();
history.replaceState(null, '', '#');
urlSize.textContent = '';
});
// ── Encrypt modal ─────────────────────────────────────────────────────────────
const modalEncrypt = document.getElementById('modal-encrypt');
const encryptPw = document.getElementById('encrypt-pw');
const encryptPw2 = document.getElementById('encrypt-pw2');
const encryptError = document.getElementById('encrypt-error');
document.getElementById('btn-encrypt').addEventListener('click', () => {
encryptPw.value = ''; encryptPw2.value = ''; encryptError.textContent = '';
modalEncrypt.classList.remove('hidden');
encryptPw.focus();
});
document.getElementById('btn-encrypt-cancel').addEventListener('click', () => modalEncrypt.classList.add('hidden'));
document.getElementById('btn-encrypt-ok').addEventListener('click', async () => {
const pw = encryptPw.value;
const pw2 = encryptPw2.value;
if (pw && pw !== pw2) { encryptError.textContent = 'Passwords do not match.'; return; }
currentPassword = pw || null;
updateLockIndicator();
await updateURL();
modalEncrypt.classList.add('hidden');
showToast(pw ? '🔒 Document encrypted. Share the URL!' : '🔓 Encryption removed.');
});
encryptPw.addEventListener('keydown', e => { if (e.key === 'Enter') encryptPw2.focus(); });
encryptPw2.addEventListener('keydown', e => { if (e.key === 'Enter') document.getElementById('btn-encrypt-ok').click(); });
// ── Decrypt modal ─────────────────────────────────────────────────────────────
const modalDecrypt = document.getElementById('modal-decrypt');
const decryptPw = document.getElementById('decrypt-pw');
const decryptError = document.getElementById('decrypt-error');
document.getElementById('btn-decrypt-cancel').addEventListener('click', () => {
modalDecrypt.classList.add('hidden');
pendingDecryptData = null;
});
document.getElementById('btn-decrypt-ok').addEventListener('click', async () => {
const pw = decryptPw.value;
if (!pw) { decryptError.textContent = 'Please enter a password.'; return; }
decryptError.textContent = '';
try {
const content = await decryptContent(pendingDecryptData, pw);
currentPassword = pw;
editor.value = content;
updatePreview();
updateStats();
updateLockIndicator();
modalDecrypt.classList.add('hidden');
addHistoryEntry(content);
showToast('🔓 Document decrypted!');
} catch {
decryptError.textContent = 'Wrong password or corrupted data.';
decryptPw.select();
}
});
decryptPw.addEventListener('keydown', e => { if (e.key === 'Enter') document.getElementById('btn-decrypt-ok').click(); });
// ── Git modal & connection ────────────────────────────────────────────────────
const modalGit = document.getElementById('modal-git');
const gitServerUrl = document.getElementById('git-server-url');
const gitFilePath = document.getElementById('git-file-path');
const gitError = document.getElementById('git-error');
document.getElementById('btn-git').addEventListener('click', () => {
gitServerUrl.value = (gitConfig && gitConfig.serverUrl) || 'http://localhost:3000';
gitFilePath.value = (gitConfig && gitConfig.filePath) || '';
gitError.textContent = '';
modalGit.classList.remove('hidden');
gitServerUrl.focus();
});
document.getElementById('btn-git-cancel').addEventListener('click', () => modalGit.classList.add('hidden'));
document.getElementById('btn-git-ok').addEventListener('click', async () => {
const serverUrl = gitServerUrl.value.trim().replace(/\/$/, '');
const filePath = gitFilePath.value.trim();
if (!serverUrl) { gitError.textContent = 'Server URL is required.'; return; }
if (!filePath) { gitError.textContent = 'File path is required.'; return; }
gitError.textContent = '';
try {
const res = await fetch(`${serverUrl}/file?path=${encodeURIComponent(filePath)}`);
if (!res.ok) throw new Error(await res.text());
const data = await res.json();
gitConfig = { serverUrl, filePath };
editor.value = data.content;
if (currentPassword !== null) {
const disable = confirm(
'Loading from git will clear the current encryption password.\n' +
'Click OK to disable encryption, or Cancel to keep it.'
);
if (disable) {
currentPassword = null;
}
}
updateLockIndicator();
updatePreview();
updateStats();
await updateURL();
// Show git bar
gitBranchLabel.textContent = data.branch || 'main';
gitFileLabel.textContent = filePath;
gitBar.classList.remove('hidden');
modalGit.classList.add('hidden');
// Load git history
const logRes = await fetch(`${serverUrl}/log?path=${encodeURIComponent(filePath)}`);
if (logRes.ok) {
const log = await logRes.json();
renderHistory(log);
} else {
renderHistory();
}
showToast('⎇ Connected to git backend');
} catch (err) {
gitError.textContent = 'Connection failed — check the URL and that the backend is running.';
console.error('[Git connect]', err);
}
});
gitServerUrl.addEventListener('keydown', e => { if (e.key === 'Enter') gitFilePath.focus(); });
gitFilePath.addEventListener('keydown', e => { if (e.key === 'Enter') document.getElementById('btn-git-ok').click(); });
document.getElementById('btn-git-disconnect').addEventListener('click', () => {
gitConfig = null;
gitBar.classList.add('hidden');
renderHistory();
showToast('Disconnected from git');
});
document.getElementById('btn-git-pull').addEventListener('click', async () => {
if (!gitConfig) return;
try {
const res = await fetch(`${gitConfig.serverUrl}/file?path=${encodeURIComponent(gitConfig.filePath)}`);
if (!res.ok) throw new Error(await res.text());
const data = await res.json();
editor.value = data.content;
updatePreview(); updateStats(); await updateURL();
addHistoryEntry(data.content);
showToast('↓ Pulled latest from git');
} catch (err) { showToast('Pull failed — check connection', 'error'); console.error(err); }
});
document.getElementById('btn-git-push').addEventListener('click', async () => {
if (!gitConfig) return;
const msg = prompt('Commit message:', 'Update via string.md');
if (msg === null) return;
try {
const res = await fetch(`${gitConfig.serverUrl}/file`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ path: gitConfig.filePath, content: editor.value, message: msg })
});
if (!res.ok) throw new Error(await res.text());
// Refresh log
const logRes = await fetch(`${gitConfig.serverUrl}/log?path=${encodeURIComponent(gitConfig.filePath)}`);
if (logRes.ok) renderHistory(await logRes.json());
showToast('↑ Pushed to git');
} catch (err) { showToast('Push failed — check connection', 'error'); console.error(err); }
});
async function loadGitCommit(sha) {
if (!gitConfig) return;
try {
const res = await fetch(`${gitConfig.serverUrl}/file?path=${encodeURIComponent(gitConfig.filePath)}&sha=${encodeURIComponent(sha)}`);
if (!res.ok) throw new Error(await res.text());
const data = await res.json();
editor.value = data.content;
updatePreview(); updateStats(); await updateURL();
showToast(`Loaded commit ${sha.slice(0,7)}`);
} catch (err) { showToast('Failed to load commit', 'error'); console.error(err); }
}
// ── Editor events ─────────────────────────────────────────────────────────────
editor.addEventListener('input', () => {
updatePreview();
updateStats();
scheduleAutoSave();
});
// Tab → 2 spaces
editor.addEventListener('keydown', e => {
if (e.key === 'Tab') {
e.preventDefault();
const s = editor.selectionStart, end = editor.selectionEnd;
editor.value = editor.value.slice(0, s) + ' ' + editor.value.slice(end);
editor.selectionStart = editor.selectionEnd = s + 2;
updatePreview(); updateStats(); scheduleAutoSave();
}
});
// ── Init ──────────────────────────────────────────────────────────────────────
async function init() {
loadHistory();
if (typeof marked !== 'undefined') {
marked.use({ gfm: true, breaks: true });
}
const hash = location.hash;
const parsed = await parseHash(hash);
if (parsed.encrypted) {
pendingDecryptData = parsed.data;
decryptPw.value = ''; decryptError.textContent = '';
modalDecrypt.classList.remove('hidden');
decryptPw.focus();
} else if (parsed.content) {
editor.value = parsed.content;
urlSize.textContent = `URL: ${(hash.length / 1024).toFixed(1)} KB`;
}
updatePreview();
updateStats();
updateLockIndicator();
renderHistory();
}
window._initReady = init();
</script>
<!-- ── Trystero P2P real-time collaboration ──────────────────────────────────
Peers connect directly (WebRTC) using the Nostr strategy for signaling.
No collaboration server is required.
CRD conflict resolution: last-write-wins with per-peer sequence numbers.
-->
<script type="module">
import { joinRoom } from 'https://esm.run/trystero@0.22.0';
// ── DOM refs ──────────────────────────────────────────────────────────────────
const editor = document.getElementById('editor');
const collabBar = document.getElementById('collab-bar');
const collabRoomLbl = document.getElementById('collab-room-label');
const collabPeerCnt = document.getElementById('collab-peer-count');
const modalCollab = document.getElementById('modal-collab');
const collabRoomIn = document.getElementById('collab-room-id');
const collabErrEl = document.getElementById('collab-error');
// ── State ─────────────────────────────────────────────────────────────────────
let room = null; // active Trystero room
let sendContent = null; // action sender
let localSeq = 0; // increments on every local edit we broadcast
let peerSeq = {}; // peerId → highest seq seen from that peer
let peers = new Set();
let lastLocalEdit = 0; // timestamp of last user keystroke
let isApplying = false; // true while writing remote content to editor
let broadcastTimer = null; // debounce handle for outbound broadcasts
const APP_ID = 'string-md';
const EDIT_GAP = 400; // ms — don't overwrite local edits within this window
// (400 ms gives comfortable pause after last keystroke)
const ROOM_ID_RE = /^[\w\-]{1,64}$/;
// ── Helpers ───────────────────────────────────────────────────────────────────
function genRoomId() {
const buf = new Uint8Array(5);
crypto.getRandomValues(buf);
return Array.from(buf, b => b.toString(16).padStart(2, '0')).join('');
}
function updatePeerCount() {
const n = peers.size;
collabPeerCnt.textContent = n === 0 ? 'no peers yet'
: n === 1 ? '1 peer connected'
: `${n} peers connected`;
}
function collabCopyLink() {
const url = location.href;
navigator.clipboard.writeText(url).then(
() => window.showToast('Collaboration link copied!'),
() => prompt('Share this link with collaborators:', url)
);
}
// ── Join / leave ──────────────────────────────────────────────────────────────
function joinCollabRoom(roomId) {
if (room) leaveCollabRoom();
window._collabRoomId = roomId;
// Trigger URL update to embed ?room= so the link is shareable
if (typeof window.updateURL === 'function') window.updateURL();
room = joinRoom({ appId: APP_ID }, roomId);
const [send, receive] = room.makeAction('content');
sendContent = send;