hongdown 0.2.5

A Markdown formatter that enforces Hong Minhee's Markdown style conventions
Documentation
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
Hong Minhee's Markdown style convention
=======================================

This document describes the Markdown style convention enforced by Hongdown.


Philosophy
----------

The core principle of this style is:

> *Markdown should be readable as plain text, not just after rendering.*

A well-formatted Markdown document should convey its structure and emphasis
clearly even when viewed in a plain text editor without any rendering.
You shouldn't need to render the document to HTML to understand its formatting
and hierarchy.

This philosophy leads to several practical implications:

 -  *Visual structure in source*: Headings, lists, and sections should be
    visually distinct in the raw text.
 -  *Consistent spacing*: Predictable whitespace patterns help readers scan
    the document structure.
 -  *Minimal escaping*: Choose delimiter styles that minimize the need for
    escape characters.
 -  *Reference-style links*: Keep prose readable by moving URLs out of the
    text flow.

This style prioritizes reading over writing.  Many rules are tedious to follow
manually—and that's intentional.  The assumption is that you'll use an
automated formatter like [Hongdown] to handle the mechanical work, freeing you
to focus on content rather than formatting details.

[Hongdown]: https://github.com/dahlia/hongdown


Headings
--------

### Setext-style for top-level headings

Use Setext-style (underlined) headings for document titles (H1) and major
sections (H2):

~~~~ markdown
Document Title
==============

Section Name
------------
~~~~

*Rationale*: Setext headings create strong visual separation in plain text.
The underline makes the heading immediately recognizable without needing to
count `#` characters.

### ATX-style for subsections

Use ATX-style (`###`, `####`, etc.) for subsections within a section:

~~~~ markdown
### Subsection

#### Sub-subsection
~~~~

*Rationale*: ATX-style is more compact for deeper nesting levels where
Setext-style would be awkward.

### Sentence case

Use sentence case for headings (capitalize only the first word and proper
nouns):

~~~~ markdown
Development commands    ← Correct
Development Commands    ← Incorrect
~~~~

*Rationale*: Sentence case is easier to read and more natural in technical
documentation.

### Underline length

The underline of a Setext-style heading should match the display width of
the heading text, accounting for East Asian wide characters.

#### East Asian character width

East Asian wide characters (CJK characters) are counted as two columns when
calculating the display width.


Emphasis
--------

### Asterisks for emphasis

Use asterisks (`*`) for emphasis by default:

~~~~ markdown
This is *emphasized* text.
This is **strongly emphasized** text.
~~~~

### Underscores when content contains asterisks

When the emphasized content contains asterisk characters, use underscores
to avoid escaping:

~~~~ markdown
The file _*.txt_ matches all text files.
The pattern __**/*.md__ matches recursively.
~~~~

*Rationale*: This produces cleaner source text by avoiding backslash escapes.

### Escape all underscores in regular text

Underscores in regular text are always escaped, even in the middle of words:

~~~~ markdown
Use the CONFIG\_FILE\_NAME constant.
~~~~

*Rationale*: While CommonMark doesn't treat intraword underscores as emphasis
delimiters, escaping ensures consistent rendering across all Markdown parsers.


Lists
-----

### Unordered list markers

Use ` -  ` (space, hyphen, two spaces) for unordered list items:

~~~~ markdown
 -  First item
 -  Second item
 -  Third item
~~~~

*Rationale*: The leading space creates visual indentation from the left margin.
The two trailing spaces align the text with a 4-space tab stop, making
continuation lines easy to align.

### Nested lists

Indent nested items by 4 spaces:

~~~~ markdown
 -  Parent item
     -  Child item
     -  Another child
 -  Another parent
~~~~

### Ordered list markers

Use `.` for odd nesting levels and `)` for even nesting levels:

~~~~ markdown
1.  First item
2.  Second item
    1)  Nested first
    2)  Nested second
3.  Third item
~~~~

*Rationale*: Alternating markers make the nesting level visually apparent.

### Fixed marker width

Ordered list markers maintain a fixed 4-character width.  When numbers grow
longer, trailing spaces are reduced (minimum 1 space):

~~~~ markdown
1.  First item
2.  Second item
...
9.  Ninth item
10. Tenth item
~~~~

*Rationale*: Consistent marker width keeps continuation lines aligned at
the same column regardless of item count.

### Continuation lines

Align continuation lines with the start of the item text:

~~~~ markdown
 -  This is a list item with text that continues
    on the next line with proper alignment.
~~~~

### Task lists

Task list items use checkboxes (`[ ]` for unchecked, `[x]` for checked) after
the list marker:

~~~~ markdown
 -  [ ] Unchecked task
 -  [x] Completed task
~~~~

*Rationale*: Task lists follow the same spacing rules as regular unordered
lists, keeping the document consistent.


Code
----

### Fenced code blocks with tildes

Use four tildes (`~~~~`) for fenced code blocks:

~~~~~ markdown
~~~~ rust
fn main() {
    println!("Hello, world!");
}
~~~~
~~~~~

*Rationale*: Tildes are visually distinct from the code content, which often
contains backticks for string literals or shell commands.

### Language identifiers

Always specify a language identifier for syntax highlighting.  If no specific
language applies, the identifier can be omitted:

~~~~~ markdown
~~~~ javascript
console.log("Hello");
~~~~
~~~~~

### Inline code spans

Use backticks for inline code.  When the content contains backticks, use
multiple backticks as delimiters:

~~~~ markdown
Use the `format()` function.
The syntax is `` `code` `` with backticks.
~~~~

Preserve original spacing in code spans.  If the original source has space
padding (`` ` code ` ``), it is preserved in the output.


Links
-----

### Reference-style for external URLs

Convert external URLs to reference-style links, with definitions placed at
the end of the current section:

~~~~ markdown
See the [documentation] for more details.

Read the [installation guide] before proceeding.

[documentation]: https://example.com/docs
[installation guide]: https://example.com/install
~~~~

*Rationale*: Reference-style links keep the prose readable by moving long URLs
out of the text flow.  Placing definitions at section end keeps related content
together.

### Inline style for relative URLs

Keep relative URLs and fragment links inline:

~~~~ markdown
See *[Chapter 2](./chapter2.md)* for more details.
Jump to the [installation section](#installation).
~~~~

*Rationale*: For inter-document links, the filename itself serves as a natural
identifier.  Using reference-style would create redundancy:

~~~~ markdown
See also *[Chapter 2]* for more details.

[Chapter 2]: ./chapter2.md
~~~~

The reference definition just repeats what the link text already conveys.

### Shortcut references when text matches label

When the link text matches the reference label, use shortcut reference syntax:

~~~~ markdown
See [GitHub] for the source code.

[GitHub]: https://github.com/example/repo
~~~~

### Collapsed references before brackets

When a shortcut reference would be immediately followed by text starting with
`[` (such as a footnote reference), use collapsed reference syntax `[text][]`
instead of shortcut syntax `[text]` to avoid ambiguity:

~~~~ markdown
See [GitHub][][^1] for details.

[GitHub]: https://github.com/example/repo

[^1]: Footnote text.
~~~~

*Rationale*: Without the empty brackets, `[GitHub][^1]` could be parsed as a
full reference link with label `^1`, which would break the intended link and
footnote.


Block quotes and alerts
-----------------------

### Block quote continuation

Continue block quotes with `>` on each line:

~~~~ markdown
> This is a block quote that spans
> multiple lines of text.
~~~~

### GitHub-style alerts

Use GitHub-flavored alert syntax for callouts:

~~~~ markdown
> [!NOTE]
> This is a note with additional information.

> [!WARNING]
> This action cannot be undone.
~~~~

Supported alert types: `NOTE`, `TIP`, `IMPORTANT`, `WARNING`, `CAUTION`.


Tables
------

### Pipe table formatting

Use pipe tables with proper column alignment:

~~~~ markdown
| Name    | Description                    |
| ------- | ------------------------------ |
| foo     | The foo component              |
| bar     | The bar component              |
~~~~

### Column width

Columns are padded to align pipes vertically.  East Asian wide characters
are counted as two columns for proper alignment.

### Escaped pipes in content

Pipe characters within cell content are escaped:

~~~~ markdown
| Pattern   | Meaning          |
| --------- | ---------------- |
| `a \| b`  | a or b           |
~~~~


Thematic breaks
---------------

### Dashes with spaces

Thematic breaks (horizontal rules) are rendered as a long line of spaced dashes
(37 dashes) with 3 leading spaces:

~~~~ markdown
Previous section content.

   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

New section content.
~~~~

*Rationale*: The extended line of dashes creates a visually prominent separator
that resembles a traditional horizontal rule, making section breaks immediately
apparent when scanning the plain text source.


Line wrapping
-------------

### Wrap at 80 characters

Wrap prose at approximately 80 display columns:

~~~~ markdown
This is a paragraph that demonstrates line wrapping.  When text exceeds the
80-character limit, it wraps to the next line while preserving word boundaries.
~~~~

*Rationale*: 80 characters is a widely supported terminal width that ensures
readability across different editors and viewers.

### East Asian character width

East Asian wide characters (CJK characters) are counted as two columns when
calculating line width.

### Preserve intentional short lines

Lines that are intentionally short in the source (well under the limit) are
preserved as-is, allowing for semantic line breaks.

### Long words

Words that exceed the line width limit are not broken and may extend beyond
80 characters.


Spacing
-------

### Blank lines between elements

Use one blank line between paragraphs, list items (in loose lists), and other
block elements.

### Two blank lines before sections

Use two blank lines before Setext-style section headings (H2):

~~~~ markdown
Previous section content.


New section
-----------
~~~~

*Rationale*: Extra spacing creates clear visual separation between major
sections in the plain text source.

### Trailing newline

Files end with exactly one trailing newline.


Punctuation
-----------

Hongdown supports SmartyPants-style punctuation transformations that convert
ASCII punctuation to their typographically correct Unicode equivalents.
These transformations are optional and configurable.

### Curly quotes

Straight double quotes (`"`) are converted to curly quotes:

~~~~ markdown
He said "hello" to her.    →    He said “hello” to her.
~~~~

Straight single quotes (`'`) used as quotation marks are converted to curly
single quotes:

~~~~ markdown
She said 'hello' to him.    →    She said ‘hello’ to him.
~~~~

*Rationale*: Curly quotes are typographically correct and improve the visual
appearance of rendered text.

### Apostrophes

By default, apostrophes in contractions remain as the ASCII character (`'`).
The Unicode name for this character is U+0027 APOSTROPHE, so using it for
apostrophes is semantically correct.  Converting to curly apostrophes can be
enabled via configuration:

~~~~ markdown
It's a beautiful day.    →    It’s a beautiful day.    (when enabled)
The '90s were great.     →    The ’90s were great.     (when enabled)
~~~~

### Ellipsis

Three consecutive periods are converted to the ellipsis character:

~~~~ markdown
Wait for it...    →    Wait for it…
~~~~

Four or more periods are preserved as-is.

### Dashes

Double hyphens are converted to em-dashes by default:

~~~~ markdown
Well--I think so.    →    Well—I think so.
~~~~

En-dashes can be enabled via configuration with a custom pattern.
Single-hyphen patterns only match when surrounded by whitespace to avoid
breaking hyphenated words:

~~~~ markdown
Pages 10 - 20    →    Pages 10 – 20    (when en_dash = "-")
~~~~

### Code preservation

Punctuation transformations are never applied inside code spans or fenced
code blocks.  This ensures that code examples remain syntactically correct:

~~~~ markdown
Use `"string"` for text.    →    Use `"string"` for text.
~~~~


Special elements
----------------

### Footnotes

Footnote definitions are placed at the end of the section where they are
referenced:

~~~~ markdown
This claim needs a citation[^1].

[^1]: Source: Example Study, 2024.
~~~~

### Definition lists

Use the extended syntax for definition lists:

~~~~ markdown
Term
:   Definition of the term.

Another term
:   Its definition.
~~~~

### Abbreviations

Abbreviation definitions are preserved at the end of the document:

~~~~ markdown
The HTML specification defines this behavior.

*[HTML]: HyperText Markup Language
~~~~