hongdown 0.1.0-dev.11

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.
Files changed (3) hide show
  1. package/README.md +286 -0
  2. package/bin/hongdown.js +34 -0
  3. package/package.json +37 -0
package/README.md ADDED
@@ -0,0 +1,286 @@
1
+ Hongdown
2
+ ========
3
+
4
+ [![crates.io][crates.io badge]][crates.io]
5
+ [![npm][npm badge]][npm]
6
+ [![GitHub Actions][GitHub Actions badge]][GitHub Actions]
7
+
8
+ Hongdown is a Markdown formatter that enforces [Hong Minhee's Markdown style]
9
+ conventions. The formatter is implemented in Rust using the [Comrak] library
10
+ for parsing. It produces consistently formatted Markdown output following
11
+ a distinctive style used across multiple projects including [Fedify], [LogTape],
12
+ and [Optique].
13
+
14
+ [crates.io badge]: https://img.shields.io/crates/v/hongdown?logo=rust
15
+ [crates.io]: https://crates.io/crates/hongdown
16
+ [npm badge]: https://img.shields.io/npm/v/hongdown?logo=npm
17
+ [npm]: https://www.npmjs.com/package/hongdown
18
+ [GitHub Actions badge]: https://github.com/dahlia/hongdown/actions/workflows/main.yaml/badge.svg
19
+ [GitHub Actions]: https://github.com/dahlia/hongdown/actions/workflows/main.yaml
20
+ [Hong Minhee's Markdown style]: ./AGENTS.md#markdown-style-guide
21
+ [Comrak]: https://comrak.ee/
22
+ [Fedify]: https://fedify.dev/
23
+ [LogTape]: https://logtape.org/
24
+ [Optique]: https://optique.dev/
25
+
26
+
27
+ Installation
28
+ ------------
29
+
30
+ ### npm
31
+
32
+ ~~~~ bash
33
+ npm install -g hongdown
34
+ ~~~~
35
+
36
+ ### mise
37
+
38
+ ~~~~ bash
39
+ mise use github:dahlia/hongdown
40
+ ~~~~
41
+
42
+ ### Cargo
43
+
44
+ ~~~~ bash
45
+ cargo install hongdown
46
+ ~~~~
47
+
48
+ ### Pre-built binaries
49
+
50
+ Pre-built binaries for Linux, macOS, and Windows are available on the
51
+ [GitHub Releases] page.
52
+
53
+ [GitHub Releases]: https://github.com/dahlia/hongdown/releases
54
+
55
+
56
+ Usage
57
+ -----
58
+
59
+ ### Basic usage
60
+
61
+ ~~~~ bash
62
+ # Format a file and print to stdout
63
+ hongdown input.md
64
+
65
+ # Format a file in place
66
+ hongdown --write input.md
67
+ hongdown -w input.md
68
+
69
+ # Format multiple files
70
+ hongdown -w *.md
71
+
72
+ # Check if files are formatted (exit 1 if not)
73
+ hongdown --check input.md
74
+ hongdown -c input.md
75
+
76
+ # Show diff of formatting changes
77
+ hongdown --diff input.md
78
+ hongdown -d input.md
79
+
80
+ # Read from stdin
81
+ echo "# Hello" | hongdown
82
+ hongdown --stdin < input.md
83
+
84
+ # Custom line width
85
+ hongdown --line-width 100 input.md
86
+ ~~~~
87
+
88
+ ### Disable directives
89
+
90
+ Hongdown supports special HTML comments to disable formatting for specific
91
+ sections of your document:
92
+
93
+ ~~~~ markdown
94
+ <!-- hongdown-disable-file -->
95
+ This entire file will not be formatted.
96
+ ~~~~
97
+
98
+ ~~~~ markdown
99
+ <!-- hongdown-disable-next-line -->
100
+ This line preserves its spacing.
101
+
102
+ The next line will be formatted normally.
103
+ ~~~~
104
+
105
+ ~~~~ markdown
106
+ <!-- hongdown-disable-next-section -->
107
+ Everything here is preserved as-is
108
+ until the next heading (h1 or h2).
109
+
110
+ Next heading
111
+ ------------
112
+
113
+ This section will be formatted normally.
114
+ ~~~~
115
+
116
+ ~~~~ markdown
117
+ <!-- hongdown-disable -->
118
+ This section is not formatted.
119
+ <!-- hongdown-enable -->
120
+ This section is formatted again.
121
+ ~~~~
122
+
123
+ ### Configuration file
124
+
125
+ Hongdown looks for a *.hongdown.toml* file in the current directory and
126
+ parent directories. You can also specify a configuration file explicitly
127
+ with the `--config` option.
128
+
129
+ Below is an example configuration with all available options and their
130
+ default values:
131
+
132
+ ~~~~ toml
133
+ # File patterns (glob syntax)
134
+ include = [] # Files to format (default: none, specify on CLI)
135
+ exclude = [] # Files to skip (default: none)
136
+
137
+ # Formatting options
138
+ line_width = 80 # Maximum line width (default: 80)
139
+
140
+ [heading]
141
+ setext_h1 = true # Use === underline for h1 (default: true)
142
+ setext_h2 = true # Use --- underline for h2 (default: true)
143
+
144
+ [list]
145
+ unordered_marker = "-" # "-", "*", or "+" (default: "-")
146
+ leading_spaces = 1 # Spaces before marker (default: 1)
147
+ trailing_spaces = 2 # Spaces after marker (default: 2)
148
+ indent_width = 4 # Indentation for nested items (default: 4)
149
+
150
+ [ordered_list]
151
+ odd_level_marker = "." # "." or ")" at odd nesting levels (default: ".")
152
+ even_level_marker = ")" # "." or ")" at even nesting levels (default: ")")
153
+ pad = "start" # "start" or "end" for number alignment (default: "start")
154
+ indent_width = 4 # Indentation for nested items (default: 4)
155
+
156
+ [code_block]
157
+ fence_char = "~" # "~" or "`" (default: "~")
158
+ min_fence_length = 4 # Minimum fence length (default: 4)
159
+ space_after_fence = true # Space between fence and language (default: true)
160
+ ~~~~
161
+
162
+ When `include` patterns are configured, you can run Hongdown without
163
+ specifying files:
164
+
165
+ ~~~~ bash
166
+ # Format all files matching include patterns
167
+ hongdown --write
168
+
169
+ # Check all files matching include patterns
170
+ hongdown --check
171
+ ~~~~
172
+
173
+ CLI options override configuration file settings:
174
+
175
+ ~~~~ bash
176
+ # Use config file but override line width
177
+ hongdown --line-width 100 input.md
178
+
179
+ # Use specific config file
180
+ hongdown --config /path/to/.hongdown.toml input.md
181
+ ~~~~
182
+
183
+
184
+ Style rules
185
+ -----------
186
+
187
+ Hongdown enforces the following conventions:
188
+
189
+ ### Headings
190
+
191
+ - Level 1 and 2 use Setext-style (underlined with `=` or `-`)
192
+ - Level 3+ use ATX-style (`###`, `####`, etc.)
193
+
194
+ ~~~~ markdown
195
+ Document Title
196
+ ==============
197
+
198
+ Section
199
+ -------
200
+
201
+ ### Subsection
202
+ ~~~~
203
+
204
+ ### Lists
205
+
206
+ - Unordered lists use ` - ` (space-hyphen-two spaces)
207
+ - Ordered lists use `1.` format
208
+ - 4-space indentation for nested items
209
+
210
+ ~~~~ markdown
211
+ - First item
212
+ - Second item
213
+ - Nested item
214
+ ~~~~
215
+
216
+ ### Code blocks
217
+
218
+ - Fenced with four tildes (`~~~~`)
219
+ - Language identifier on the opening fence
220
+
221
+ ~~~~~ text
222
+ ~~~~ rust
223
+ fn main() {
224
+ println!("Hello, world!");
225
+ }
226
+ ~~~~
227
+ ~~~~~
228
+
229
+ ### Line wrapping
230
+
231
+ - Lines wrap at approximately 80 display columns
232
+ - East Asian wide characters are counted as 2 columns
233
+ - Long words that cannot be broken are preserved
234
+
235
+ ### Links
236
+
237
+ - External URLs are converted to reference-style links
238
+ - References are placed at the end of each section
239
+ - Relative/local URLs remain inline
240
+
241
+ ~~~~ markdown
242
+ See the [documentation] for more details.
243
+
244
+ [documentation]: https://example.com/docs
245
+ ~~~~
246
+
247
+ ### Tables
248
+
249
+ - Pipes are aligned accounting for East Asian wide characters
250
+ - Minimum column width is maintained
251
+
252
+ See the [*Markdown style guide*] for more detailed style conventions.
253
+
254
+ [*Markdown style guide*]: ./AGENTS.md#markdown-style-guide
255
+
256
+
257
+ Library usage
258
+ -------------
259
+
260
+ Hongdown can also be used as a Rust library:
261
+
262
+ ~~~~ rust
263
+ use hongdown::{format, Options};
264
+
265
+ let input = "# Hello World\nThis is a paragraph.";
266
+ let options = Options::default();
267
+ let output = format(input, &options).unwrap();
268
+ println!("{}", output);
269
+ ~~~~
270
+
271
+
272
+ Etymology
273
+ ---------
274
+
275
+ The name *Hongdown* is a portmanteau of *Hong* (from Hong Minhee, the author)
276
+ and *Markdown*. It also sounds like the Korean word *hongdapda* (홍답다),
277
+ meaning “befitting of Hong” or “Hong-like.”
278
+
279
+
280
+ License
281
+ -------
282
+
283
+ Distributed under the [GPL-3.0-or-later]. See *[LICENSE]* for more information.
284
+
285
+ [GPL-3.0-or-later]: https://www.gnu.org/licenses/gpl-3.0.html
286
+ [LICENSE]: ./LICENSE
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from "node:child_process";
3
+ import { createRequire } from "node:module";
4
+
5
+ const require = createRequire(import.meta.url);
6
+
7
+ const PLATFORMS = {
8
+ "darwin-arm64": "@hongdown/darwin-arm64",
9
+ "darwin-x64": "@hongdown/darwin-x64",
10
+ "linux-arm64": "@hongdown/linux-arm64",
11
+ "linux-x64": "@hongdown/linux-x64",
12
+ "win32-arm64": "@hongdown/win32-arm64",
13
+ "win32-x64": "@hongdown/win32-x64",
14
+ };
15
+
16
+ const platformKey = `${process.platform}-${process.arch}`;
17
+ const packageName = PLATFORMS[platformKey];
18
+
19
+ if (!packageName) {
20
+ console.error(`Unsupported platform: ${platformKey}`);
21
+ process.exit(1);
22
+ }
23
+
24
+ try {
25
+ const binName = process.platform === "win32" ? "hongdown.exe" : "hongdown";
26
+ const binPath = require.resolve(`${packageName}/bin/${binName}`);
27
+ const result = spawnSync(binPath, process.argv.slice(2), {
28
+ stdio: "inherit",
29
+ });
30
+ process.exit(result.status ?? 1);
31
+ } catch (e) {
32
+ console.error(`Failed to run hongdown: ${e.message}`);
33
+ process.exit(1);
34
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "hongdown",
3
+ "version": "0.1.0-dev.11+be401b59",
4
+ "type": "module",
5
+ "description": "A Markdown formatter that enforces Hong Minhee's Markdown style conventions",
6
+ "license": "GPL-3.0-or-later",
7
+ "author": "Hong Minhee <hong@minhee.org>",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/dahlia/hongdown.git"
11
+ },
12
+ "homepage": "https://github.com/dahlia/hongdown",
13
+ "keywords": [
14
+ "markdown",
15
+ "formatter",
16
+ "linter",
17
+ "style"
18
+ ],
19
+ "bin": {
20
+ "hongdown": "bin/hongdown.js"
21
+ },
22
+ "files": [
23
+ "bin/",
24
+ "README.md"
25
+ ],
26
+ "engines": {
27
+ "node": ">=18"
28
+ },
29
+ "optionalDependencies": {
30
+ "@hongdown/darwin-arm64": "0.1.0-dev.11+be401b59",
31
+ "@hongdown/darwin-x64": "0.1.0-dev.11+be401b59",
32
+ "@hongdown/linux-arm64": "0.1.0-dev.11+be401b59",
33
+ "@hongdown/linux-x64": "0.1.0-dev.11+be401b59",
34
+ "@hongdown/win32-arm64": "0.1.0-dev.11+be401b59",
35
+ "@hongdown/win32-x64": "0.1.0-dev.11+be401b59"
36
+ }
37
+ }