markdown-viewer-rs 0.4.0

Render a Markdown file with GitHub styling and live-reload it in your browser
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
---
title: markdown-viewer feature tour
description: YAML front matter is shown as a table, like on GitHub.
---

<p align="center"><img src="images/logo.svg" alt="Markdown logo" width="120"></p>

# markdown-viewer feature tour

A tour of everything markdown-viewer renders. Open it with:

```sh
markdown-viewer --watch examples/example.md
```

In the viewer, press <kbd>?</kbd> for keyboard shortcuts, <kbd>o</kbd> for the
contents, and <kbd>t</kbd> to switch between auto, light and dark.

**Contents:** [Text](#text) · [Headings](#headings) · [Links](#links) ·
[Images](#images) · [Lists](#lists) · [Tables](#tables) · [Code](#code) ·
[Quotes and alerts](#quotes-and-alerts) · [Footnotes](#footnotes) ·
[Emoji](#emoji) · [Raw HTML](#raw-html) · [Math](#math) ·
[Mermaid diagrams](#mermaid-diagrams)

---

## Text

Plain paragraph text wraps
across source lines into one paragraph.

**Bold**, *italic*, ***bold italic***, ~~strikethrough~~, `inline code`,
and **nested *emphasis* with `code`** inside.

End a line with a backslash for a hard line break\
like this, or with two trailing spaces.  
Like this.

Escaped characters stay literal: \*not italic\*, \`not code\`, \# not a heading.

## Headings

# Heading level 1
## Heading level 2
### Heading level 3
#### Heading level 4
##### Heading level 5
###### Heading level 6

Setext heading level 1
======================

Setext heading level 2
----------------------

Every heading gets an anchor; hover one to see the link icon.

## Links

- Inline link: [GitHub]https://github.com "GitHub's home page"
- Reference link: [CommonMark spec][spec]
- Autolinks: https://github.github.com/gfm/ and <https://example.com>
- Email autolink: someone@example.com
- Link to a heading on this page: [jump to Mermaid]#mermaid-diagrams
- Relative link to another Markdown file: [other.md]other.md

[spec]: https://spec.commonmark.org/ "CommonMark"

## Images

A relative image (served from the Markdown file's folder):

![markdown-viewer logo](images/logo.svg "The logo")

A linked image:

[![logo as a link](images/logo.svg)](https://github.com/mdellavo/markdown-viewer)

Theme-aware images, as on GitHub: add `#gh-light-mode-only` or
`#gh-dark-mode-only` to the image URL. There are two images below, but only
the one for the current theme is shown (hover it to see which):

![Light-mode image](images/logo.svg#gh-light-mode-only "light-mode image")
![Dark-mode image](images/logo.svg#gh-dark-mode-only "dark-mode image")

## Lists

Unordered, with nesting:

- Fruit
  - Apples
    - Granny Smith
    - Honeycrisp
  - Oranges
- Vegetables
* A different bullet marker
+ And another

Ordered, starting at 3:

3. Third
4. Fourth
5. Fifth

Mixed nesting:

1. Install
   - with Homebrew
   - or with Cargo
2. Run
   ```sh
   markdown-viewer README.md
   ```
3. Edit and watch it reload

Task list:

- [x] Render GitHub Flavored Markdown
- [x] Live reload
- [x] Mermaid diagrams
- [x] Math
- [ ] Native window
  - [x] Nested tasks work too

## Tables

| Feature | Supported | Notes |
|:--------|:---------:|------:|
| Tables | ✅ | left, center and right alignment |
| **Inline** *formatting* | ✅ | `code`, [links]#links, ~~strike~~ |
| Escaped \| pipe | ✅ | use `\|` |

## Code

Fenced code with syntax highlighting:

```rust
use std::collections::HashMap;

/// Count words in a string.
fn word_counts(text: &str) -> HashMap<&str, usize> {
    let mut counts = HashMap::new();
    for word in text.split_whitespace() {
        *counts.entry(word).or_insert(0) += 1;
    }
    counts
}
```

```python
from dataclasses import dataclass

@dataclass
class Point:
    x: float
    y: float

    def norm(self) -> float:
        return (self.x ** 2 + self.y ** 2) ** 0.5
```

```javascript
const greet = (name = "world") => `Hello, ${name}!`;
console.log(greet());
```

```json
{ "name": "markdown-viewer", "features": ["gfm", "mermaid"], "offline": true }
```

```diff
- old line
+ new line
  unchanged line
```

A fence with no language:

```
plain preformatted text
    keeps its spacing
```

An indented code block:

    four spaces of indent
    makes a code block

## Quotes and alerts

> A blockquote.
>
> > A nested blockquote.
>
> Back to the outer quote, with **formatting** and a list:
> - one
> - two

GitHub alerts:

> [!NOTE]
> Useful information that users should know, even when skimming content.

> [!TIP]
> Helpful advice for doing things better or more easily.

> [!IMPORTANT]
> Key information users need to know to achieve their goal.

> [!WARNING]
> Urgent info that needs immediate user attention to avoid problems.

> [!CAUTION]
> Advises about risks or negative outcomes of certain actions.

## Footnotes

Footnotes are collected at the bottom of the page.[^first] They can have
names and longer content.[^long]

[^first]: The first footnote.
[^long]: A footnote with **formatting** and a [link](https://example.com).

## Emoji

Shortcodes: :rocket: :tada: :white_check_mark: :warning: :heart: :+1:

Unicode emoji work as-is: 🚀 🎉

## Raw HTML

<details>
<summary>Click to expand a <code>&lt;details&gt;</code> block</summary>

Hidden content, with **Markdown** inside (note the blank line after
`<summary>`).

</details>

Press <kbd>Ctrl</kbd> + <kbd>C</kbd> to stop the server.

H<sub>2</sub>O and E = mc<sup>2</sup>.

<!-- HTML comments are not rendered. -->

<script>document.body.innerHTML = "scripts in Markdown are blocked";</script>

The `<script>` above is blocked by the page's Content-Security-Policy, so
this page is still here.

---

## Math

Inline math with dollars: the Pythagorean theorem is $a^2 + b^2 = c^2$, and
Euler's identity is $e^{i\pi} + 1 = 0$. Dollar amounts like $5 or $10 are left
alone.

Inline math with backticks, for when the TeX would confuse Markdown:
$`\sqrt{x_1^2 + x_2^2}`$.

A display equation on its own lines:

$$
\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}
$$

A `math` code block:

```math
\begin{aligned}
\nabla \cdot \mathbf{E} &= \frac{\rho}{\varepsilon_0} \\
\nabla \times \mathbf{B} - \frac{1}{c^2}\frac{\partial \mathbf{E}}{\partial t} &= \mu_0 \mathbf{J}
\end{aligned}
```

Matrices, sums and cases:

$$
\mathbf{A} = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}, \qquad
\sum_{k=1}^{n} k = \frac{n(n+1)}{2}, \qquad
|x| = \begin{cases} x & x \ge 0 \\ -x & x < 0 \end{cases}
$$

Invalid TeX is shown in red instead of breaking the page: $\frac{1}{$.

---

## Mermaid diagrams

Code blocks tagged `mermaid` are drawn as diagrams.

### Flowchart

```mermaid
flowchart LR
    A[Edit example.md] -->|save| B(File watcher)
    B --> C{Changed?}
    C -->|yes| D[Re-render HTML]
    C -->|no| B
    D --> E[Push to browser]
    E --> F((Page updates))
```

### Sequence diagram

```mermaid
sequenceDiagram
    actor You
    participant Editor
    participant Viewer as markdown-viewer
    participant Browser
    You->>Editor: Save file
    Editor->>Viewer: File changed
    Viewer->>Viewer: Render Markdown
    Viewer-->>Browser: Server-Sent Event
    Browser->>Browser: Swap content, keep scroll
    Note over Viewer,Browser: Diagrams are drawn before the swap
```

### Class diagram

```mermaid
classDiagram
    class Renderer {
        +render_body(markdown) String
        +render_page(markdown, page) String
    }
    class Server {
        +bind(port) Server
        +run()
    }
    class FileWatcher
    Server --> Renderer : uses
    FileWatcher --> Renderer : uses
```

### State diagram

```mermaid
stateDiagram-v2
    [*] --> Idle
    Idle --> Rendering : file saved
    Rendering --> Pushing : HTML ready
    Pushing --> Idle : page updated
    Rendering --> Idle : file unchanged
```

### Entity relationship diagram

```mermaid
erDiagram
    AUTHOR ||--o{ DOCUMENT : writes
    DOCUMENT ||--|{ SECTION : contains
    SECTION }o--o{ DIAGRAM : includes
```

### Gantt chart

```mermaid
gantt
    title Release plan
    dateFormat YYYY-MM-DD
    section Core
    Rendering       :done,    r1, 2026-11-01, 7d
    Live reload     :done,    r2, after r1, 5d
    section Extras
    Mermaid         :active,  m1, 2026-11-20, 6d
    Native window   :         w1, after m1, 10d
```

### Pie chart

```mermaid
pie title Time spent writing docs
    "Writing" : 45
    "Previewing" : 30
    "Fixing typos" : 25
```

### Git graph

```mermaid
gitGraph
    commit
    branch feature
    checkout feature
    commit
    commit
    checkout main
    merge feature
    commit
```

### Mindmap

```mermaid
mindmap
  root((markdown-viewer))
    Rendering
      GitHub styles
      Syntax highlighting
      Alerts
    Viewing
      Browser
      New window
      Live reload
    Diagrams
      Mermaid
```

### Timeline

```mermaid
timeline
    title markdown-viewer
    0.1.0 : Rendering : Live reload : Homebrew
    Unreleased : Mermaid : New window
```