-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathindex.html
More file actions
1065 lines (920 loc) · 38.1 KB
/
index.html
File metadata and controls
1065 lines (920 loc) · 38.1 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">
<meta name="theme-color" content="#ffffff">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<!-- SEO Meta Tags -->
<title>Analyzing Bitcoin Consensus: Risks in Protocol Upgrades | BCAP </title>
<meta name="description" content="Comprehensive analysis of Bitcoin's consensus mechanism, stakeholder roles, protocol upgrade risks, and recommendations for evaluating consensus changes. Research by Ren Crypto Fish, Steve Lee, and Lyn Alden.">
<meta name="keywords" content="Bitcoin consensus, protocol upgrades, soft fork, hard fork, Bitcoin Core, stakeholders, consensus mechanism, blockchain governance, Bitcoin research">
<meta name="author" content="Ren Crypto Fish, Steve Lee, Lyn Alden">
<meta name="robots" content="index, follow">
<link rel="canonical" href="https://bitcoin-cap.github.io/bcap/">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="article">
<meta property="og:url" content="https://bitcoin-cap.github.io/bcap/">
<meta property="og:title" content="Analyzing Bitcoin Consensus: Risks in Protocol Upgrades">
<meta property="og:description" content="Comprehensive analysis of Bitcoin's consensus mechanism, stakeholder roles, and the risks associated with protocol upgrades. Essential research for Bitcoin developers, investors, and enthusiasts.">
<meta property="og:image" content="https://opengraph.githubassets.com/1/bitcoin-cap/bcap">
<meta property="og:site_name" content="Bitcoin Consensus Analysis Project">
<meta property="article:published_time" content="2024-11-01">
<meta property="article:author" content="Ren Crypto Fish, Steve Lee, Lyn Alden">
<!-- Twitter Card -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:url" content="https://bitcoin-cap.github.io/bcap/">
<meta name="twitter:title" content="Analyzing Bitcoin Consensus: Risks in Protocol Upgrades">
<meta name="twitter:description" content="Comprehensive analysis of Bitcoin's consensus mechanism, stakeholder roles, and protocol upgrade risks. Essential research for the Bitcoin community.">
<meta name="twitter:image" content="https://opengraph.githubassets.com/1/bitcoin-cap/bcap">
<!-- Additional SEO -->
<meta name="language" content="English">
<meta name="revisit-after" content="30 days">
<meta http-equiv="content-language" content="en">
<!-- Schema.org JSON-LD -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "Analyzing Bitcoin Consensus: Risks in Protocol Upgrades",
"description": "Comprehensive analysis of Bitcoin's consensus mechanism, stakeholder roles, and the risks associated with protocol upgrades.",
"image": "https://opengraph.githubassets.com/1/bitcoin-cap/bcap",
"author": [
{
"@type": "Person",
"name": "Ren Crypto Fish"
},
{
"@type": "Person",
"name": "Steve Lee"
},
{
"@type": "Person",
"name": "Lyn Alden"
}
],
"publisher": {
"@type": "Organization",
"name": "Bitcoin Consensus Analysis Project",
"url": "https://github.com/bitcoin-cap/bcap"
},
"datePublished": "2024-11-01",
"dateModified": "2024-11-22",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://bitcoin-cap.github.io/bcap/"
},
"keywords": "Bitcoin consensus, protocol upgrades, soft fork, hard fork, Bitcoin Core, stakeholders",
"articleSection": "Research",
"wordCount": "15000"
}
</script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
line-height: 1.6;
color: #333;
margin: 0;
padding: 0;
background-color: #f5f5f5;
display: flex;
}
.sidebar {
position: fixed;
left: 0;
top: 0;
width: 280px;
height: 100vh;
background-color: #fff;
border-right: 1px solid #e1e4e8;
overflow-y: auto;
padding: 20px;
box-sizing: border-box;
}
.sidebar-header {
margin-bottom: 30px;
padding-bottom: 20px;
border-bottom: 1px solid #e1e4e8;
}
.sidebar-title {
font-size: 16px;
font-weight: 600;
color: #24292e;
margin: 0 0 16px 0;
line-height: 1.4;
}
.sidebar-meta {
font-size: 12px;
color: #586069;
line-height: 1.6;
}
.sidebar-meta p {
margin: 4px 0;
}
.github-link {
display: inline-flex;
align-items: center;
gap: 6px;
margin-top: 12px;
padding: 6px 12px;
background-color: #f6f8fa;
border: 1px solid #d1d5da;
border-radius: 6px;
color: #24292e;
text-decoration: none;
font-size: 12px;
font-weight: 500;
transition: all 0.2s;
}
.github-link:hover {
background-color: #f3f4f6;
border-color: #c9cbcf;
}
.github-link svg {
width: 16px;
height: 16px;
}
.sidebar h3 {
margin: 0 0 20px 0;
font-size: 18px;
font-weight: 600;
color: #333;
}
.toc {
list-style: none;
padding: 0;
margin: 0;
}
.toc li {
margin-bottom: 8px;
}
.toc a {
color: #586069;
text-decoration: none;
display: block;
padding: 4px 0;
font-size: 14px;
transition: color 0.2s;
}
.toc a:hover {
color: #0366d6;
}
.toc a.active {
color: #0366d6;
font-weight: 600;
}
.toc .toc-h1 {
font-weight: 600;
font-size: 15px;
margin-top: 12px;
}
.toc .toc-h2 {
padding-left: 16px;
}
.toc .toc-h3 {
padding-left: 32px;
font-size: 13px;
}
.toc .toc-h4 {
padding-left: 48px;
font-size: 13px;
}
.main-content {
margin-left: 280px;
width: calc(100% - 280px);
padding: 20px;
box-sizing: border-box;
display: flex;
justify-content: center;
}
.container {
background-color: white;
padding: 40px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
max-width: 900px;
width: 100%;
}
/* Mobile header */
.mobile-header {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
height: 56px;
background-color: #fff;
border-bottom: 1px solid #e1e4e8;
z-index: 1001;
padding: 0 16px;
align-items: center;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.mobile-header h1 {
font-size: 18px;
font-weight: 600;
margin: 0;
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.menu-toggle {
background: none;
border: none;
padding: 8px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
border-radius: 6px;
transition: background-color 0.2s;
}
.menu-toggle:hover {
background-color: #f6f8fa;
}
.menu-toggle svg {
width: 24px;
height: 24px;
}
/* Mobile sidebar overlay */
.sidebar-overlay {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
z-index: 1002;
opacity: 0;
transition: opacity 0.3s;
}
.sidebar-overlay.active {
opacity: 1;
}
/* Mobile responsive */
@media (max-width: 1024px) {
.mobile-header {
display: flex;
}
.sidebar {
position: fixed;
left: -100%;
top: 0;
width: 85%;
max-width: 320px;
height: 100vh;
z-index: 1003;
transition: left 0.3s ease;
box-shadow: 2px 0 10px rgba(0,0,0,0.1);
}
.sidebar.active {
left: 0;
}
.main-content {
margin-left: 0;
width: 100%;
padding-top: 76px; /* Account for mobile header */
}
.container {
border-radius: 0;
padding: 20px;
}
}
@media (max-width: 768px) {
.container {
padding: 16px;
}
body {
font-size: 16px;
}
}
h1, h2, h3, h4, h5, h6 {
margin-top: 24px;
margin-bottom: 16px;
font-weight: 600;
line-height: 1.25;
}
h1 {
font-size: 2em;
border-bottom: 1px solid #eee;
padding-bottom: 0.3em;
}
h2 {
font-size: 1.5em;
border-bottom: 1px solid #eee;
padding-bottom: 0.3em;
}
h3 {
font-size: 1.25em;
}
h4 {
font-size: 1em;
}
p {
margin-bottom: 16px;
}
a {
color: #0366d6;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
ul, ol {
margin-bottom: 16px;
padding-left: 2em;
}
li {
margin-bottom: 4px;
}
code {
background-color: #f6f8fa;
padding: 2px 4px;
border-radius: 3px;
font-family: Consolas, Monaco, 'Courier New', monospace;
font-size: 85%;
}
pre {
background-color: #f6f8fa;
padding: 16px;
overflow: auto;
font-size: 85%;
line-height: 1.45;
border-radius: 3px;
}
pre code {
background-color: transparent;
padding: 0;
}
blockquote {
margin: 0;
padding: 0 1em;
color: #6a737d;
border-left: 0.25em solid #dfe2e5;
}
table {
border-collapse: collapse;
width: 100%;
margin-bottom: 16px;
}
table th,
table td {
padding: 6px 13px;
border: 1px solid #dfe2e5;
}
table th {
font-weight: 600;
background-color: #f6f8fa;
}
table tr {
background-color: #fff;
border-top: 1px solid #c6cbd1;
}
table tr:nth-child(2n) {
background-color: #f6f8fa;
}
img {
max-width: 100%;
height: auto;
display: block;
margin: 16px 0;
}
/* Responsive tables */
.table-wrapper {
overflow-x: auto;
-webkit-overflow-scrolling: touch;
margin: 16px -20px;
padding: 0 20px;
}
@media (max-width: 768px) {
.table-wrapper {
margin: 16px -16px;
padding: 0 16px;
}
table {
font-size: 14px;
}
pre {
font-size: 14px;
padding: 12px;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
}
img {
margin: 12px -16px;
max-width: calc(100% + 32px);
width: calc(100% + 32px);
}
}
.mermaid {
text-align: center;
margin: 16px 0;
}
/* Footnote styling */
sup {
font-size: 0.8em;
vertical-align: super;
line-height: 0;
}
.footnote-ref {
color: #0366d6;
text-decoration: none;
cursor: help;
position: relative;
}
.footnote-tooltip {
visibility: hidden;
opacity: 0;
position: absolute;
bottom: 100%;
left: 50%;
transform: translateX(-50%);
background-color: #333;
color: white;
text-align: left;
padding: 10px 14px;
border-radius: 6px;
font-size: 13px;
line-height: 1.5;
white-space: normal;
width: 350px;
max-width: 90vw;
max-height: 200px;
overflow-y: auto;
word-wrap: break-word;
overflow-wrap: break-word;
z-index: 1000;
transition: opacity 0.3s, visibility 0.3s;
margin-bottom: 5px;
box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
/* Custom scrollbar for tooltip */
.footnote-tooltip::-webkit-scrollbar {
width: 6px;
}
.footnote-tooltip::-webkit-scrollbar-track {
background: rgba(255,255,255,0.1);
border-radius: 3px;
}
.footnote-tooltip::-webkit-scrollbar-thumb {
background: rgba(255,255,255,0.3);
border-radius: 3px;
}
.footnote-tooltip::-webkit-scrollbar-thumb:hover {
background: rgba(255,255,255,0.5);
}
.footnote-tooltip::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #333 transparent transparent transparent;
}
.footnote-ref:hover .footnote-tooltip {
visibility: visible;
opacity: 1;
}
/* Mobile footnotes */
@media (max-width: 768px) {
.footnote-ref {
padding: 4px;
margin: -4px;
}
.footnote-tooltip {
position: fixed;
bottom: 20px;
left: 20px;
right: 20px;
top: auto;
transform: none;
width: auto;
max-width: none;
max-height: 40vh;
font-size: 14px;
z-index: 1004;
}
.footnote-tooltip::after {
display: none;
}
/* Show on tap for mobile */
.footnote-ref.active .footnote-tooltip {
visibility: visible;
opacity: 1;
}
}
@media (max-width: 768px) {
body {
padding: 10px;
}
.container {
padding: 20px;
}
table {
font-size: 14px;
}
}
</style>
</head>
<body>
<!-- Mobile header -->
<header class="mobile-header">
<button class="menu-toggle" id="menuToggle" aria-label="Toggle navigation">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="3" y1="12" x2="21" y2="12"></line>
<line x1="3" y1="6" x2="21" y2="6"></line>
<line x1="3" y1="18" x2="21" y2="18"></line>
</svg>
</button>
<h1>Bitcoin Consensus Analysis</h1>
</header>
<!-- Sidebar overlay for mobile -->
<div class="sidebar-overlay" id="sidebarOverlay"></div>
<div class="sidebar" id="sidebar">
<div class="sidebar-header">
<h2 class="sidebar-title">Analyzing Bitcoin Consensus: Risks in Protocol Upgrades</h2>
<div class="sidebar-meta">
<p>First published: November 2024</p>
<p id="last-updated">Last updated: Loading...</p>
</div>
<a href="https://github.com/bitcoin-cap/bcap" target="_blank" rel="noopener noreferrer" class="github-link">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor">
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/>
</svg>
Contributions welcome
</a>
</div>
<h3>Table of Contents</h3>
<ul id="toc" class="toc">
<!-- TOC will be dynamically generated -->
</ul>
</div>
<div class="main-content">
<div class="container">
<div id="content">
<div style="text-align: center; padding: 40px;">
<div style="display: inline-block; width: 40px; height: 40px; border: 3px solid #f3f3f3; border-top: 3px solid #0366d6; border-radius: 50%; animation: spin 1s linear infinite;"></div>
<p style="margin-top: 16px; color: #586069;">Loading content...</p>
</div>
</div>
<style>
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
<script>
// Initialize mermaid
mermaid.initialize({
startOnLoad: false,
theme: 'default',
themeVariables: {
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif'
}
});
// Fetch and render the README.md
fetch('README.md')
.then(response => response.text())
.then(text => {
// First, collect all footnote definitions
const footnotes = {};
const footnotePattern = /^\[(\^[^\]]+)\]:\s*(.+)$/gm;
let match;
while ((match = footnotePattern.exec(text)) !== null) {
const id = match[1]; // Keep the ^ symbol for now
const content = match[2].trim();
footnotes[id] = content;
}
// Process footnote references before marked.js parsing
// Replace [^1] with custom HTML that includes tooltip
let processedText = text;
// Store the original footnote definitions for the appendix
const footnoteDefinitions = [];
const footnoteDefPattern = /^\[(\^[^\]]+)\]:\s*(.+)$/gm;
let defMatch;
while ((defMatch = footnoteDefPattern.exec(text)) !== null) {
const num = defMatch[1].substring(1); // Remove ^ for numbering
const content = defMatch[2].trim();
footnoteDefinitions.push({ num, content });
}
// First, remove the footnote definitions from the bottom of the text
// so they don't appear in the rendered content
processedText = processedText.replace(/^\[\^[^\]]+\]:\s*.+$/gm, '');
// Now replace each footnote reference with HTML that includes tooltip
Object.keys(footnotes).forEach(id => {
// Match [^1] style references
const refPattern = new RegExp('\\[\\' + id + '\\]', 'g');
const footnoteNum = id.substring(1); // Remove ^ for display
// Process the footnote content
let content = footnotes[id];
// Check if it's a markdown link format [text](url)
const markdownLinkMatch = content.match(/^\[([^\]]+)\]\(([^)]+)\)$/);
if (markdownLinkMatch) {
// Extract text and URL from markdown format
const linkText = markdownLinkMatch[1];
const linkUrl = markdownLinkMatch[2];
content = `<a href="${linkUrl}" target="_blank" rel="noopener noreferrer" style="color: #8cb4ff; text-decoration: none; word-break: break-all;">${linkUrl}</a>`;
} else if (content.match(/^https?:\/\//)) {
// For plain URLs, make them clickable
content = `<a href="${content}" target="_blank" rel="noopener noreferrer" style="color: #8cb4ff; text-decoration: none; word-break: break-all;">${content}</a>`;
} else {
// For other content, escape HTML
content = content
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
// Create a unique placeholder for this footnote
const placeholder = `%%FOOTNOTE_${footnoteNum}_PLACEHOLDER%%`;
// Store the HTML content for later
if (!window.footnoteContent) window.footnoteContent = {};
window.footnoteContent[footnoteNum] = content;
// For now, just use a placeholder
const tooltipHtml = `<span class="footnote-ref" style="position: relative; display: inline-block;"><sup><a href="#" onclick="return false;" style="text-decoration: none; color: #0366d6;">[${footnoteNum}]</a></sup><span class="footnote-tooltip" data-footnote="${footnoteNum}">${placeholder}</span></span>`;
processedText = processedText.replace(refPattern, tooltipHtml);
});
// Configure marked options
marked.setOptions({
breaks: true,
gfm: true,
headerIds: true,
mangle: false,
headerPrefix: ''
});
// Parse the markdown
let html = marked.parse(processedText);
// Process mermaid code blocks
// Replace ```mermaid blocks with div elements
html = html.replace(/<pre><code class="language-mermaid">([\s\S]*?)<\/code><\/pre>/g, function(match, code) {
// Decode HTML entities
const textarea = document.createElement('textarea');
textarea.innerHTML = code;
const decodedCode = textarea.value;
return '<div class="mermaid">' + decodedCode + '</div>';
});
// Display the content
document.getElementById('content').innerHTML = html;
// Fix header IDs to match the internal links
fixHeaderIds();
// Add formatted footnotes to the Appendix section if they exist
if (footnoteDefinitions.length > 0) {
const appendixHeader = Array.from(document.querySelectorAll('h1, h2')).find(
h => h.textContent.trim() === 'Appendix'
);
if (appendixHeader) {
// Create an ordered list for footnotes
const footnoteList = document.createElement('ol');
footnoteList.style.paddingLeft = '20px';
footnoteList.style.lineHeight = '1.8';
// Sort footnotes by number
footnoteDefinitions.sort((a, b) => parseInt(a.num) - parseInt(b.num));
footnoteDefinitions.forEach(fn => {
const li = document.createElement('li');
li.style.marginBottom = '8px';
// Check if content is a URL or markdown link
let formattedContent = fn.content;
// Handle markdown links [text](url)
const markdownLinkMatch = formattedContent.match(/^\[([^\]]+)\]\(([^)]+)\)$/);
if (markdownLinkMatch) {
const linkUrl = markdownLinkMatch[2];
formattedContent = `<a href="${linkUrl}" target="_blank" rel="noopener noreferrer">${linkUrl}</a>`;
} else if (formattedContent.match(/^https?:\/\//)) {
// Plain URLs
formattedContent = `<a href="${formattedContent}" target="_blank" rel="noopener noreferrer">${formattedContent}</a>`;
}
li.innerHTML = formattedContent;
footnoteList.appendChild(li);
});
// Insert the list after the Appendix header
appendixHeader.parentNode.insertBefore(footnoteList, appendixHeader.nextSibling);
}
}
// Replace footnote placeholders with actual content
if (window.footnoteContent) {
Object.keys(window.footnoteContent).forEach(num => {
const tooltips = document.querySelectorAll(`.footnote-tooltip[data-footnote="${num}"]`);
tooltips.forEach(tooltip => {
tooltip.innerHTML = window.footnoteContent[num];
});
});
}
// Process any mermaid diagrams
mermaid.init(undefined, document.querySelectorAll('.mermaid'));
// Generate table of contents
generateTOC();
// Set up scroll spy
setupScrollSpy();
// Fetch last updated date
fetchLastUpdated();
// Setup mobile interactions
setupMobileInteractions();
// Wrap tables for responsive scrolling
wrapTables();
})
.catch(error => {
document.getElementById('content').innerHTML = '<p>Error loading README.md: ' + error + '</p>';
});
function fetchLastUpdated() {
// Try to fetch from GitHub API
fetch('https://api.github.com/repos/bitcoin-cap/bcap/commits?per_page=1')
.then(response => response.json())
.then(data => {
if (data && data.length > 0) {
const lastCommitDate = new Date(data[0].commit.author.date);
const formattedDate = lastCommitDate.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
document.getElementById('last-updated').textContent = `Last updated: ${formattedDate}`;
}
})
.catch(error => {
// If API fails, show a fallback
console.error('Failed to fetch last commit date:', error);
document.getElementById('last-updated').textContent = 'Last updated: See GitHub';
});
}
function fixHeaderIds() {
// Get all headers
const headers = document.querySelectorAll('h1, h2, h3, h4, h5, h6');
headers.forEach(header => {
// Get the text content and create a proper ID
const text = header.textContent || header.innerText || '';
const newId = text.toLowerCase()
.replace(/[^\w\s-]/g, '') // Remove special characters
.replace(/\s+/g, '-') // Replace spaces with hyphens
.trim();
// Set the new ID
if (newId) {
header.id = newId;
}
});
}
function generateTOC() {
const content = document.getElementById('content');
const toc = document.getElementById('toc');
const headers = content.querySelectorAll('h1, h2, h3, h4');
headers.forEach((header, index) => {
// Skip the first two headers (title and "Table of contents")
const headerText = header.textContent || header.innerText || '';
if (headerText === 'Analyzing Bitcoin Consensus: Risks in Protocol Upgrades' ||
headerText === 'Table of contents') {
return;
}
// Header should already have an ID from marked.js
// Only add one if it's missing for some reason
if (!header.id) {
const text = headerText;
header.id = text.toLowerCase()
.replace(/[^\w\s-]/g, '')
.replace(/\s+/g, '-')
.trim();
}
const li = document.createElement('li');
const a = document.createElement('a');
a.href = '#' + header.id;
a.textContent = header.textContent;
a.className = 'toc-' + header.tagName.toLowerCase();
// Smooth scroll on click
a.addEventListener('click', (e) => {
e.preventDefault();
const target = document.getElementById(header.id);
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
// Update active state
document.querySelectorAll('.toc a').forEach(link => link.classList.remove('active'));
a.classList.add('active');
// Update URL without adding to history
history.replaceState(null, '', '#' + header.id);
});
li.appendChild(a);
toc.appendChild(li);
});
}
function setupScrollSpy() {
const headers = document.querySelectorAll('h1, h2, h3, h4');
const tocLinks = document.querySelectorAll('.toc a');
let scrollTimeout;
let lastHash = window.location.hash;
window.addEventListener('scroll', () => {
let current = '';
headers.forEach(header => {
const rect = header.getBoundingClientRect();
if (rect.top <= 100) {
current = header.id;
}
});
tocLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === '#' + current) {
link.classList.add('active');
}
});
// Update URL on scroll with debouncing
clearTimeout(scrollTimeout);
scrollTimeout = setTimeout(() => {
if (current && '#' + current !== lastHash) {
history.replaceState(null, '', current ? '#' + current : window.location.pathname);
lastHash = '#' + current;
}
}, 150);
});
// Handle direct navigation to hash on page load
if (window.location.hash) {
setTimeout(() => {
const target = document.querySelector(window.location.hash);
if (target) {
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
// Update active state in TOC
tocLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === window.location.hash) {
link.classList.add('active');
}
});
}
}, 100);
}
}
function setupMobileInteractions() {
const menuToggle = document.getElementById('menuToggle');
const sidebar = document.getElementById('sidebar');
const sidebarOverlay = document.getElementById('sidebarOverlay');
// Toggle mobile menu
menuToggle.addEventListener('click', () => {
sidebar.classList.toggle('active');
sidebarOverlay.style.display = sidebar.classList.contains('active') ? 'block' : 'none';
setTimeout(() => {
sidebarOverlay.classList.toggle('active', sidebar.classList.contains('active'));
}, 10);
document.body.style.overflow = sidebar.classList.contains('active') ? 'hidden' : '';