-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathindex.html
More file actions
157 lines (155 loc) · 5.54 KB
/
index.html
File metadata and controls
157 lines (155 loc) · 5.54 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
<!-- Dcycle Documentation 1.1 -->
<!-- This file displays the README with a table of contents as a web page -->
<!-- See https://documentation.dcycle.com -->
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>...</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<style>
pre {
background: #ccc;
padding: 30px;
border-radius: 20px;
font-weight: bold;
}
.toc-list a {
color: black;
}
.back-to-top a {
position: fixed;
bottom: 20px;
right: 20px;
background: #333;
color: white;
padding: 10px;
border-radius: 5px;
cursor: pointer;
text-decoration: none;
font-weight: bold;
}
.about-documentation {
font-style: italic;
}
</style>
</head>
<body>
<header class="mb-5">
<div class="navbar navbar-dark bg-dark box-shadow">
<div class="container d-flex justify-content-between">
<a href="#" class="navbar-brand put-title-here">...</a>
</div>
</div>
</header>
<main role="main">
<section style="display:none;" class="unhide-if-errors mb-5">
<div class="container">
<div class="alert alert-danger put-errors-here" role="alert">
</div>
</div>
</section>
<section class="mb-5">
<div class="container">
<div class="row">
<div class="col-sm col-lg-3">
<div class="back-to-top">
<a href="#">Back to top</a>
</div>
<div class="put-table-of-contents-here"></div>
</div>
<div class="col-sm col-lg-9">
<div class="put-content-here"></div>
<div class="about-documentation">
Documentation layout was created using <a href="https://documentation.dcycle.com">Dcycle Documentation</a> from a README.md file.
</div>
</div>
</div>
</div>
</section>
</main>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/15.0.4/marked.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.30.0/tocbot.min.js"></script>
<script>
class MyDocumentation {
static async init() {
const instance = this.instance();
try {
instance.preflight();
const markdown = await instance.readReadme();
const renderer = new marked.Renderer();
renderer.heading = function(text, level) {
const id = text.text.toLowerCase().replace(/[^a-zA-Z0-9]+/g, '-');
return `<h${text.depth} id="${id}">${text.text}</h${text.depth}>`;
}
marked.setOptions({renderer});
const html = marked.parse(markdown);
instance.placeHtml(html);
instance.createTableOfContents();
instance.setTitle();
}
catch (error) {
instance.showError(error);
}
}
getTitleFromMarkup() {
const candidate = document.querySelector('h1');
const candidateText = candidate ? candidate.textContent : null;
if (candidateText) {
return candidateText;
}
return 'Documentation';
}
setTitle() {
const title = this.getTitleFromMarkup();
document.querySelector('.put-title-here').textContent = title;
document.title = title;
}
createTableOfContents() {
// See https://tscanlin.github.io/tocbot/#options
tocbot.init({
// Where to render the table of contents.
tocSelector: '.put-table-of-contents-here',
// Where to grab the headings to build the table of contents.
contentSelector: '.put-content-here',
// Which headings to grab inside of the contentSelector element.
headingSelector: 'h2, h3, h4, h5, h6',
// For headings inside relative or absolute positioned containers within content.
hasInnerContainers: true,
orderedList: false,
});
}
placeHtml(html) {
var new_elem = document.createElement('div');
new_elem.innerHTML = html;
document.querySelector('.put-content-here').appendChild(new_elem);
}
preflight() {
if (location.protocol == 'file:') {
throw ('Cannot read README.md file from file:// protocol. You might want to try: python3 -m http.server; see https://documentation.dcycle.com for more details.');
}
}
async readReadme(callback) {
const response = await fetch('./README.md');
if (!response.ok) {
throw ('Could not read README.md file, make sure it exists');
}
return response.text();
}
showError(error) {
document.querySelector(".unhide-if-errors").style.display = "block";
document.querySelector('.put-errors-here').textContent = error;
}
static instance() {
if (!this._instance) {
this._instance = new this();
}
return this._instance;
}
}
document.addEventListener("DOMContentLoaded", function(event) {
MyDocumentation.init();
});
</script>
</body>
</html>