markserv 1.19.1 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -256,28 +256,36 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
256
256
  <!-- prettier-ignore-start -->
257
257
  <!-- markdownlint-disable -->
258
258
  <table>
259
- <tr>
260
- <td align="center"><a href="https://f1lt3r.io"><img src="https://avatars1.githubusercontent.com/u/1218446?v=4" width="100px;" alt=""/><br /><sub><b>Alistair MacDonald</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=F1LT3R" title="Code">💻</a></td>
261
- <td align="center"><a href="https://finenet.com.tw"><img src="https://avatars3.githubusercontent.com/u/154892?v=4" width="100px;" alt=""/><br /><sub><b>陳瀛洲</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=ChenYingChou" title="Code">💻</a></td>
262
- <td align="center"><a href="https://kflu.github.io/"><img src="https://avatars2.githubusercontent.com/u/1031978?v=4" width="100px;" alt=""/><br /><sub><b>Kefei Lu</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=kflu" title="Code">💻</a></td>
263
- <td align="center"><a href="https://www.imyzf.com"><img src="https://avatars1.githubusercontent.com/u/8298849?v=4" width="100px;" alt=""/><br /><sub><b>Zhenfei You</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=imyzf" title="Code">💻</a></td>
264
- <td align="center"><a href="https://github.com/anslzo"><img src="https://avatars2.githubusercontent.com/u/11443948?v=4" width="100px;" alt=""/><br /><sub><b>Andrew</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=anslzo" title="Code">💻</a></td>
265
- <td align="center"><a href="https://daniel.perez.sh"><img src="https://avatars2.githubusercontent.com/u/1436271?v=4" width="100px;" alt=""/><br /><sub><b>Daniel Perez</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=danhper" title="Code">💻</a></td>
266
- <td align="center"><a href="https://github.com/sushruth"><img src="https://avatars0.githubusercontent.com/u/2114206?v=4" width="100px;" alt=""/><br /><sub><b>Sushruth Shastry</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=sushruth" title="Code">💻</a></td>
267
- </tr>
268
- <tr>
269
- <td align="center"><a href="https://ptkdev.it"><img src="https://avatars1.githubusercontent.com/u/442844?v=4" width="100px;" alt=""/><br /><sub><b>Patryk Rzucidło</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=ptkdev" title="Code">💻</a></td>
270
- <td align="center"><a href="https://github.com/EstebanMarin"><img src="https://avatars3.githubusercontent.com/u/13613037?v=4" width="100px;" alt=""/><br /><sub><b>EstebanMarin</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=EstebanMarin" title="Code">💻</a></td>
271
- <td align="center"><a href="https://matthewreishus.com/"><img src="https://avatars3.githubusercontent.com/u/937354?v=4" width="100px;" alt=""/><br /><sub><b>Matthew Reishus</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=mreishus" title="Documentation">📖</a></td>
272
- <td align="center"><a href="https://github.com/danielwe"><img src="https://avatars3.githubusercontent.com/u/5809017?v=4" width="100px;" alt=""/><br /><sub><b>Daniel Wennberg</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=danielwe" title="Code">💻</a></td>
273
- <td align="center"><a href="http://thepete.net"><img src="https://avatars1.githubusercontent.com/u/65444?v=4" width="100px;" alt=""/><br /><sub><b>Pete Hodgson</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=moredip" title="Code">💻</a></td>
274
- <td align="center"><a href="https://github.com/ghost"><img src="https://avatars3.githubusercontent.com/u/10137?v=4" width="100px;" alt=""/><br /><sub><b>Deleted user</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=ghost" title="Documentation">📖</a></td>
275
- <td align="center"><a href="https://www.ldaws.com"><img src="https://avatars2.githubusercontent.com/u/760143?v=4" width="100px;" alt=""/><br /><sub><b>Liam Dawson</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=liamdawson" title="Code">💻</a></td>
276
- </tr>
259
+ <tbody>
260
+ <tr>
261
+ <td align="center" valign="top" width="14.28%"><a href="https://f1lt3r.io"><img src="https://avatars1.githubusercontent.com/u/1218446?v=4?s=100" width="100px;" alt="Alistair MacDonald"/><br /><sub><b>Alistair MacDonald</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=F1LT3R" title="Code">💻</a></td>
262
+ <td align="center" valign="top" width="14.28%"><a href="https://finenet.com.tw"><img src="https://avatars3.githubusercontent.com/u/154892?v=4?s=100" width="100px;" alt="陳瀛洲"/><br /><sub><b>陳瀛洲</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=ChenYingChou" title="Code">💻</a></td>
263
+ <td align="center" valign="top" width="14.28%"><a href="https://kflu.github.io/"><img src="https://avatars2.githubusercontent.com/u/1031978?v=4?s=100" width="100px;" alt="Kefei Lu"/><br /><sub><b>Kefei Lu</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=kflu" title="Code">💻</a></td>
264
+ <td align="center" valign="top" width="14.28%"><a href="https://www.imyzf.com"><img src="https://avatars1.githubusercontent.com/u/8298849?v=4?s=100" width="100px;" alt="Zhenfei You"/><br /><sub><b>Zhenfei You</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=imyzf" title="Code">💻</a></td>
265
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/anslzo"><img src="https://avatars2.githubusercontent.com/u/11443948?v=4?s=100" width="100px;" alt="Andrew"/><br /><sub><b>Andrew</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=anslzo" title="Code">💻</a></td>
266
+ <td align="center" valign="top" width="14.28%"><a href="https://daniel.perez.sh"><img src="https://avatars2.githubusercontent.com/u/1436271?v=4?s=100" width="100px;" alt="Daniel Perez"/><br /><sub><b>Daniel Perez</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=danhper" title="Code">💻</a></td>
267
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/sushruth"><img src="https://avatars0.githubusercontent.com/u/2114206?v=4?s=100" width="100px;" alt="Sushruth Shastry"/><br /><sub><b>Sushruth Shastry</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=sushruth" title="Code">💻</a></td>
268
+ </tr>
269
+ <tr>
270
+ <td align="center" valign="top" width="14.28%"><a href="https://ptkdev.it"><img src="https://avatars1.githubusercontent.com/u/442844?v=4?s=100" width="100px;" alt="Patryk Rzucidło"/><br /><sub><b>Patryk Rzucidło</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=ptkdev" title="Code">💻</a></td>
271
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/EstebanMarin"><img src="https://avatars3.githubusercontent.com/u/13613037?v=4?s=100" width="100px;" alt="EstebanMarin"/><br /><sub><b>EstebanMarin</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=EstebanMarin" title="Code">💻</a></td>
272
+ <td align="center" valign="top" width="14.28%"><a href="https://matthewreishus.com/"><img src="https://avatars3.githubusercontent.com/u/937354?v=4?s=100" width="100px;" alt="Matthew Reishus"/><br /><sub><b>Matthew Reishus</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=mreishus" title="Documentation">📖</a></td>
273
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/danielwe"><img src="https://avatars3.githubusercontent.com/u/5809017?v=4?s=100" width="100px;" alt="Daniel Wennberg"/><br /><sub><b>Daniel Wennberg</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=danielwe" title="Code">💻</a></td>
274
+ <td align="center" valign="top" width="14.28%"><a href="http://thepete.net"><img src="https://avatars1.githubusercontent.com/u/65444?v=4?s=100" width="100px;" alt="Pete Hodgson"/><br /><sub><b>Pete Hodgson</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=moredip" title="Code">💻</a></td>
275
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/ghost"><img src="https://avatars3.githubusercontent.com/u/10137?v=4?s=100" width="100px;" alt="Deleted user"/><br /><sub><b>Deleted user</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=ghost" title="Documentation">📖</a></td>
276
+ <td align="center" valign="top" width="14.28%"><a href="https://www.ldaws.com"><img src="https://avatars2.githubusercontent.com/u/760143?v=4?s=100" width="100px;" alt="Liam Dawson"/><br /><sub><b>Liam Dawson</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=liamdawson" title="Code">💻</a></td>
277
+ </tr>
278
+ <tr>
279
+ <td align="center" valign="top" width="14.28%"><a href="https://choly.ca/"><img src="https://avatars.githubusercontent.com/u/943597?v=4?s=100" width="100px;" alt="Ilia Choly"/><br /><sub><b>Ilia Choly</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=icholy" title="Code">💻</a></td>
280
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/rcarrionr"><img src="https://avatars.githubusercontent.com/u/26934511?v=4?s=100" width="100px;" alt="Richard Carrion"/><br /><sub><b>Richard Carrion</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/commits?author=rcarrionr" title="Code">💻</a></td>
281
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/alysonfs"><img src="https://avatars.githubusercontent.com/u/928412?v=4?s=100" width="100px;" alt="Alyson Felipe"/><br /><sub><b>Alyson Felipe</b></sub></a><br /><a href="https://github.com/f1lt3r/markserv/issues?q=author%3Aalysonfs" title="Bug reports">🐛</a></td>
282
+ </tr>
283
+ </tbody>
277
284
  </table>
278
285
 
279
- <!-- markdownlint-enable -->
286
+ <!-- markdownlint-restore -->
280
287
  <!-- prettier-ignore-end -->
288
+
281
289
  <!-- ALL-CONTRIBUTORS-LIST:END -->
282
290
 
283
291
  This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
package/lib/server.js CHANGED
@@ -61,6 +61,20 @@ const md = new MarkdownIt({
61
61
  slugify
62
62
  })
63
63
 
64
+ // Mermaid fences are rendered client-side by the lazy loader in
65
+ // templates/markdown.html. Pass the source through escaped (the loader
66
+ // reads it back via innerHTML) and keep highlight.js away from it, which
67
+ // would otherwise log "Could not find the language 'mermaid'".
68
+ // markdown-it passes strings starting with <pre straight through.
69
+ const {highlight} = md.options
70
+ md.options.highlight = (code, lang) => {
71
+ if (lang === 'mermaid') {
72
+ return `<pre class="mermaid">${md.utils.escapeHtml(code)}</pre>`
73
+ }
74
+
75
+ return highlight(code, lang)
76
+ }
77
+
64
78
  // Markdown Extension Types
65
79
  const fileTypes = {
66
80
  markdown: [
@@ -42,6 +42,12 @@
42
42
  var btn = document.getElementById('theme-toggle');
43
43
  if (btn) btn.textContent = icons[t] || icons.dark;
44
44
  current = t;
45
+
46
+ // Re-render mermaid diagrams so they follow the new theme
47
+ // (mermaid bakes theme CSS into the SVG at render time)
48
+ if (window.markservRenderMermaid) {
49
+ window.markservRenderMermaid();
50
+ }
45
51
  }
46
52
 
47
53
  applyTheme(current);
@@ -159,7 +165,12 @@
159
165
  };
160
166
  ws.onmessage = function(e) {
161
167
  var el = document.querySelector('.markdown-body');
162
- if (el) el.innerHTML = e.data;
168
+ if (el) {
169
+ el.innerHTML = e.data;
170
+ if (el.querySelector('pre.mermaid')) {
171
+ window.markservLoadMermaid();
172
+ }
173
+ }
163
174
  };
164
175
  ws.onclose = function() {
165
176
  if (retries < maxRetries) {
@@ -173,5 +184,77 @@
173
184
  })();
174
185
  </script>
175
186
  {{/if}}
187
+ <script>
188
+ (function() {
189
+ // Lazy mermaid loader: costs nothing (no network) on pages without a
190
+ // mermaid fence, and degrades to the plain source text when the CDN is
191
+ // unreachable. The script is appended asynchronously and rendered via
192
+ // contentLoaded(), because startOnLoad hooks the window load event,
193
+ // which may already have fired by the time the CDN answers.
194
+ var loading = false;
195
+ var sourceCache = new WeakMap();
196
+
197
+ function mermaidThemeFor(theme) {
198
+ return theme === 'light' ? 'default' : (theme === 'solarized' ? 'neutral' : 'dark')
199
+ }
200
+
201
+ // Render/re-render all mermaid fences with the page's current theme.
202
+ // Mermaid replaces a fence's content with the SVG, so previously
203
+ // rendered fences get their source restored from the cache first.
204
+ window.markservRenderMermaid = function() {
205
+ // window.mermaid can be a named element (e.g. <h1 id="mermaid">);
206
+ // only treat it as the library if it actually exposes the API
207
+ var mermaidLib = window.mermaid;
208
+ if (!mermaidLib || typeof mermaidLib.contentLoaded !== 'function') {
209
+ return
210
+ }
211
+
212
+ var els = document.querySelectorAll('pre.mermaid');
213
+ els.forEach(function(el) {
214
+ if (!sourceCache.has(el)) {
215
+ sourceCache.set(el, el.innerHTML);
216
+ }
217
+ });
218
+ els.forEach(function(el) {
219
+ if (el.getAttribute('data-processed')) {
220
+ el.innerHTML = sourceCache.get(el);
221
+ el.removeAttribute('data-processed');
222
+ }
223
+ });
224
+
225
+ var theme = document.documentElement.getAttribute('data-theme') || 'dark';
226
+ mermaidLib.initialize({ theme: mermaidThemeFor(theme) });
227
+ mermaidLib.contentLoaded();
228
+ };
229
+
230
+ window.markservLoadMermaid = function() {
231
+ var mermaidLib = window.mermaid;
232
+ if (mermaidLib && typeof mermaidLib.contentLoaded === 'function') {
233
+ window.markservRenderMermaid();
234
+ return
235
+ }
236
+
237
+ if (loading) {
238
+ return
239
+ }
240
+
241
+ loading = true;
242
+ var script = document.createElement('script');
243
+ script.src = 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js';
244
+ script.onload = function() {
245
+ window.markservRenderMermaid();
246
+ };
247
+ script.onerror = function() {
248
+ // Offline or CDN unreachable: keep the diagram source as plain text
249
+ loading = false;
250
+ };
251
+ document.head.appendChild(script);
252
+ };
253
+
254
+ if (document.querySelector('pre.mermaid')) {
255
+ window.markservLoadMermaid();
256
+ }
257
+ })();
258
+ </script>
176
259
  </body>
177
260
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markserv",
3
- "version": "1.19.1",
3
+ "version": "1.20.0",
4
4
  "description": "🏁 serve markdown as html (GitHub style), index directories, live-reload as you edit",
5
5
  "preferGlobal": true,
6
6
  "scripts": {
@@ -28,6 +28,8 @@
28
28
  "marked",
29
29
  "markitdown",
30
30
  "md",
31
+ "mermaid",
32
+ "mathjax",
31
33
  "realtime",
32
34
  "reload",
33
35
  "server",