hongdown 0.5.0-dev.169 → 0.5.0-dev.193

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 (2) hide show
  1. package/README.md +47 -0
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -100,6 +100,9 @@ hongdown --line-width 100 input.md
100
100
 
101
101
  # Disable word wrapping entirely
102
102
  hongdown --no-line-width input.md
103
+
104
+ # Enable MDX mode for non-.mdx input (.mdx files enable it automatically)
105
+ hongdown --mdx input.md
103
106
  ~~~~
104
107
 
105
108
  ### HTML comment directives
@@ -214,6 +217,7 @@ git_aware = true # Respect .gitignore and skip .git directory (default:
214
217
  # Formatting options
215
218
  line_width = 80 # Maximum line width (min: 8, default: 80); set to false to disable wrapping
216
219
  math = true # Preserve TeX math ($…$ and $$…$$) verbatim (default: true)
220
+ mdx = false # MDX mode: preserve embedded JS/JSX verbatim (default: false)
217
221
 
218
222
  [heading]
219
223
  setext_h1 = true # Use === underline for h1 (default: true)
@@ -464,6 +468,49 @@ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
464
468
  $$
465
469
  ~~~~
466
470
 
471
+ ### MDX
472
+
473
+ MDX documents mix Markdown with JavaScript and JSX. Because the underlying
474
+ CommonMark parser does not understand those constructs, formatting an MDX
475
+ document normally corrupts the embedded code. *MDX mode* (“first, do no harm”)
476
+ detects the JS/JSX constructs and passes them through verbatim, while the
477
+ surrounding Markdown prose is still formatted.
478
+
479
+ Within paragraph text, the constructs Hongdown would otherwise corrupt are
480
+ preserved verbatim — never escaped or punctuation-transformed:
481
+
482
+ - ESM `import`/`export` statements, JSX elements and fragments (`<Tabs …>`,
483
+ `<Chart … />`, `<>…</>`), and `{…}` expressions (including `{/* … */}`
484
+ comments)
485
+ - The embedded JavaScript/JSX is preserved, not reformatted
486
+ - Files with the *.mdx* extension enable MDX mode automatically; for stdin or
487
+ *.md* input, enable it with `--mdx` or `mdx = true` in *.hongdown.toml*
488
+
489
+ ~~~~ mdx
490
+ import { Chart } from "./chart.js";
491
+
492
+ export const meta = { author: "Hong Minhee" };
493
+
494
+ <PackageManagerTabs
495
+ command={{ npm: "npm add @scope/pkg" }}
496
+ />
497
+
498
+ A paragraph of prose is still wrapped and punctuation-transformed, while the
499
+ JSX and imports above are left exactly as written.
500
+ ~~~~
501
+
502
+ A JSX tag that is already valid inline HTML (for example a single `{value}`
503
+ attribute) is left to the underlying parser, which keeps the tag while still
504
+ formatting the element's Markdown children; only tags that break the HTML
505
+ grammar (a `{{…}}` attribute, embedded quotes or spaces, or a multi-line opener)
506
+ are protected as a whole.
507
+
508
+ Some constructs are intentionally left unprotected: anything inside a heading
509
+ (an explicit `{#id}` anchor stays a heading anchor), braces inside inline code
510
+ (`` `{x}` ``), math (`$\frac{1}{2}$`), or link/image syntax, an expression
511
+ containing a regex literal whose context is ambiguous (a `/` immediately after
512
+ `}`), and an ESM object whose body contains a blank line.
513
+
467
514
  ### Links
468
515
 
469
516
  - External URLs are converted to reference-style links
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hongdown",
3
- "version": "0.5.0-dev.169+ea9e5539",
3
+ "version": "0.5.0-dev.193+ee20593d",
4
4
  "type": "module",
5
5
  "description": "A Markdown formatter that enforces Hong Minhee's Markdown style conventions",
6
6
  "license": "GPL-3.0-or-later",
@@ -27,11 +27,11 @@
27
27
  "node": "\u003e=18"
28
28
  },
29
29
  "optionalDependencies": {
30
- "@hongdown/darwin-arm64": "0.5.0-dev.169+ea9e5539",
31
- "@hongdown/darwin-x64": "0.5.0-dev.169+ea9e5539",
32
- "@hongdown/linux-arm64": "0.5.0-dev.169+ea9e5539",
33
- "@hongdown/linux-x64": "0.5.0-dev.169+ea9e5539",
34
- "@hongdown/win32-arm64": "0.5.0-dev.169+ea9e5539",
35
- "@hongdown/win32-x64": "0.5.0-dev.169+ea9e5539"
30
+ "@hongdown/darwin-arm64": "0.5.0-dev.193+ee20593d",
31
+ "@hongdown/darwin-x64": "0.5.0-dev.193+ee20593d",
32
+ "@hongdown/linux-arm64": "0.5.0-dev.193+ee20593d",
33
+ "@hongdown/linux-x64": "0.5.0-dev.193+ee20593d",
34
+ "@hongdown/win32-arm64": "0.5.0-dev.193+ee20593d",
35
+ "@hongdown/win32-x64": "0.5.0-dev.193+ee20593d"
36
36
  }
37
37
  }