@takazudo/mdx-formatter 0.5.0-next.3 → 1.0.1

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 (45) hide show
  1. package/README.md +8 -7
  2. package/dist/browser.d.ts +7 -17
  3. package/dist/browser.js +6 -44
  4. package/dist/index.d.ts +3 -3
  5. package/dist/index.js +7 -26
  6. package/dist/load-config.js +10 -2
  7. package/dist/rust-formatter.d.ts +10 -9
  8. package/dist/rust-formatter.js +46 -24
  9. package/dist/settings.d.ts +0 -1
  10. package/dist/settings.js +0 -9
  11. package/dist/types.d.ts +0 -123
  12. package/dist/utils.js +3 -0
  13. package/package.json +25 -18
  14. package/dist/html-block-formatter.d.ts +0 -46
  15. package/dist/html-block-formatter.js +0 -370
  16. package/dist/hybrid-formatter.d.ts +0 -83
  17. package/dist/hybrid-formatter.js +0 -1150
  18. package/dist/indent-detector.d.ts +0 -62
  19. package/dist/indent-detector.js +0 -358
  20. package/dist/legacy-line-formatter.d.ts +0 -30
  21. package/dist/legacy-line-formatter.js +0 -469
  22. package/dist/mdx-formatter.d.ts +0 -96
  23. package/dist/mdx-formatter.js +0 -1335
  24. package/dist/plugins/docusaurus-admonitions.d.ts +0 -5
  25. package/dist/plugins/docusaurus-admonitions.js +0 -42
  26. package/dist/plugins/fix-autolink-output.d.ts +0 -4
  27. package/dist/plugins/fix-autolink-output.js +0 -24
  28. package/dist/plugins/fix-formatting-issues.d.ts +0 -4
  29. package/dist/plugins/fix-formatting-issues.js +0 -42
  30. package/dist/plugins/fix-paragraph-spacing.d.ts +0 -5
  31. package/dist/plugins/fix-paragraph-spacing.js +0 -96
  32. package/dist/plugins/html-definition-list.d.ts +0 -5
  33. package/dist/plugins/html-definition-list.js +0 -64
  34. package/dist/plugins/japanese-text.d.ts +0 -5
  35. package/dist/plugins/japanese-text.js +0 -79
  36. package/dist/plugins/normalize-lists.d.ts +0 -5
  37. package/dist/plugins/normalize-lists.js +0 -58
  38. package/dist/plugins/preprocess-japanese.d.ts +0 -7
  39. package/dist/plugins/preprocess-japanese.js +0 -15
  40. package/dist/plugins/preserve-image-alt.d.ts +0 -8
  41. package/dist/plugins/preserve-image-alt.js +0 -19
  42. package/dist/plugins/preserve-jsx.d.ts +0 -6
  43. package/dist/plugins/preserve-jsx.js +0 -48
  44. package/dist/specific-formatter.d.ts +0 -30
  45. package/dist/specific-formatter.js +0 -469
package/README.md CHANGED
@@ -1,18 +1,19 @@
1
1
  # @takazudo/mdx-formatter
2
2
 
3
- AST-based markdown and MDX formatter with Japanese text support. Built on top of the unified ecosystem with remark plugins.
3
+ AST-based markdown and MDX formatter with Japanese text support. Powered by a Rust engine (via napi-rs) for fast, reliable formatting.
4
4
 
5
5
  ## Features
6
6
 
7
- - **AST-based formatting** — Uses remark's AST for reliable, structural formatting
7
+ - **Rust-powered** — Native Rust engine via napi-rs, 3-7x faster than pure JS
8
+ - **Hybrid formatter** — Parses AST for analysis, applies edits to original source lines (no lossy round-trip)
8
9
  - **MDX support** — Full support for MDX syntax including JSX components, imports, exports
9
10
  - **Japanese text handling** — Preserves Japanese punctuation and text formatting
10
11
  - **Docusaurus admonitions** — Preserves `:::note`, `:::tip`, `:::warning` etc. syntax
11
- - **HTML block formatting** — Proper indentation for HTML blocks (dl, table, ul, div, etc.) via Prettier
12
+ - **HTML block formatting** — Proper indentation for HTML blocks (dl, table, ul, div, etc.)
12
13
  - **GFM features** — Tables, strikethrough, task lists
13
14
  - **YAML frontmatter** — Formatting with safe value pre-processing
14
15
  - **CLI and API** — Use as command-line tool or import as library
15
- - **Browser export** — `@takazudo/mdx-formatter/browser` for Vite/WebView/Tauri builds
16
+ - **WASM support** — Browser-compatible WASM build available
16
17
  - **Configurable** — 10 independently toggleable rules via config file or API
17
18
 
18
19
  ## Installation
@@ -77,16 +78,16 @@ Full documentation at **[takazudomodular.com/pj/mdx-formatter](https://takazudom
77
78
  - [Architecture](https://takazudomodular.com/pj/mdx-formatter/docs/architecture) — Hybrid formatter approach, Rust rewrite strategy
78
79
  - [Changelog](https://takazudomodular.com/pj/mdx-formatter/docs/changelog) — Release history
79
80
 
80
- ## Rust Rewrite (Experimental)
81
+ ## Architecture
81
82
 
82
- An experimental Rust implementation using [markdown-rs](https://github.com/wooorm/markdown-rs) and [napi-rs](https://napi.rs/) is in progress at `crates/`. See [Architecture: Rust Rewrite](https://takazudomodular.com/pj/mdx-formatter/docs/architecture/rust-rewrite) for details.
83
+ The formatting engine is written in Rust using [markdown-rs](https://github.com/wooorm/markdown-rs) and [napi-rs](https://napi.rs/). The npm package loads the native Rust module at runtime. A standalone CLI binary and WASM build for browsers are also available. See [Architecture](https://takazudomodular.com/pj/mdx-formatter/docs/architecture) for details.
83
84
 
84
85
  ## Development
85
86
 
86
87
  ```bash
87
88
  pnpm install # Install dependencies
88
89
  pnpm build # Compile TypeScript
89
- pnpm test # Run tests (274 tests)
90
+ pnpm test # Run tests (207 tests)
90
91
  pnpm test:watch # Watch mode
91
92
  pnpm test:coverage # Coverage report
92
93
  pnpm lint # ESLint check
package/dist/browser.d.ts CHANGED
@@ -1,22 +1,12 @@
1
1
  /**
2
2
  * Browser-safe entry point for mdx-formatter.
3
3
  *
4
- * Unlike the main entry point (`index.ts`), this module does NOT import
5
- * `load-config.ts` and therefore avoids pulling in Node's `fs` and `path`.
6
- * Use this export (`@takazudo/mdx-formatter/browser`) when bundling for
7
- * Vite, webpack, or any browser environment.
4
+ * Note: In browser environments, use the WASM module directly instead.
5
+ * This export is kept for API compatibility but requires the napi native
6
+ * module to be available (Node.js only).
8
7
  *
9
- * By default, `formatHtmlBlocksInMdx` is **disabled** in browser mode because
10
- * that rule depends on prettier, which is a Node.js dependency. If the code
11
- * path is never reached, bundlers can tree-shake the prettier import away.
8
+ * For true browser usage, see the WASM package at
9
+ * `crates/mdx-formatter-wasm/` or the doc site playground.
12
10
  */
13
- import { detectMdx } from './detect-mdx.js';
14
- import type { FormatterSettings, DeepPartial } from './types.js';
15
- export { detectMdx };
16
- /**
17
- * Format markdown/MDX content in browser environments.
18
- *
19
- * Uses browser-safe defaults (formatHtmlBlocksInMdx disabled).
20
- * Pass an optional `settings` object to override individual rules.
21
- */
22
- export declare function format(content: string, settings?: DeepPartial<FormatterSettings>): Promise<string>;
11
+ export { format, detectMdx } from './index.js';
12
+ export type { FormatterSettings, DeepPartial } from './types.js';
package/dist/browser.js CHANGED
@@ -1,49 +1,11 @@
1
1
  /**
2
2
  * Browser-safe entry point for mdx-formatter.
3
3
  *
4
- * Unlike the main entry point (`index.ts`), this module does NOT import
5
- * `load-config.ts` and therefore avoids pulling in Node's `fs` and `path`.
6
- * Use this export (`@takazudo/mdx-formatter/browser`) when bundling for
7
- * Vite, webpack, or any browser environment.
4
+ * Note: In browser environments, use the WASM module directly instead.
5
+ * This export is kept for API compatibility but requires the napi native
6
+ * module to be available (Node.js only).
8
7
  *
9
- * By default, `formatHtmlBlocksInMdx` is **disabled** in browser mode because
10
- * that rule depends on prettier, which is a Node.js dependency. If the code
11
- * path is never reached, bundlers can tree-shake the prettier import away.
8
+ * For true browser usage, see the WASM package at
9
+ * `crates/mdx-formatter-wasm/` or the doc site playground.
12
10
  */
13
- import { MdxFormatter } from './mdx-formatter.js';
14
- import { detectMdx } from './detect-mdx.js';
15
- import { formatterSettings } from './settings.js';
16
- import { deepCloneSettings, deepMerge } from './utils.js';
17
- export { detectMdx };
18
- const MAX_ITERATIONS = 3;
19
- // Browser-safe defaults: disable formatHtmlBlocksInMdx (requires prettier/Node.js)
20
- const browserDefaults = {
21
- ...formatterSettings,
22
- formatHtmlBlocksInMdx: {
23
- ...formatterSettings.formatHtmlBlocksInMdx,
24
- enabled: false,
25
- },
26
- };
27
- /**
28
- * Format markdown/MDX content in browser environments.
29
- *
30
- * Uses browser-safe defaults (formatHtmlBlocksInMdx disabled).
31
- * Pass an optional `settings` object to override individual rules.
32
- */
33
- export async function format(content, settings = {}) {
34
- const merged = deepMerge(deepCloneSettings(browserDefaults), settings);
35
- try {
36
- let result = content;
37
- for (let i = 0; i < MAX_ITERATIONS; i++) {
38
- const formatter = new MdxFormatter(result, merged);
39
- const formatted = await formatter.format();
40
- if (formatted === result)
41
- break;
42
- result = formatted;
43
- }
44
- return result;
45
- }
46
- catch {
47
- return content;
48
- }
49
- }
11
+ export { format, detectMdx } from './index.js';
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  /**
2
- * Main entry point for the markdown formatter
3
- * Uses MdxFormatter for AST-based formatting
2
+ * Main entry point for mdx-formatter.
3
+ * Uses the Rust napi formatter as the sole formatting engine.
4
4
  */
5
5
  import { detectMdx } from './detect-mdx.js';
6
6
  import type { FormatOptions } from './types.js';
7
7
  export { detectMdx };
8
8
  /**
9
- * Format markdown/MDX content using hybrid AST approach
9
+ * Format markdown/MDX content using the Rust formatter.
10
10
  */
11
11
  export declare function format(content: string, options?: FormatOptions): Promise<string>;
12
12
  /**
package/dist/index.js CHANGED
@@ -1,37 +1,19 @@
1
1
  /**
2
- * Main entry point for the markdown formatter
3
- * Uses MdxFormatter for AST-based formatting
2
+ * Main entry point for mdx-formatter.
3
+ * Uses the Rust napi formatter as the sole formatting engine.
4
4
  */
5
5
  import { promises as fs } from 'fs';
6
- import { MdxFormatter } from './mdx-formatter.js';
7
6
  import { loadConfig } from './load-config.js';
8
7
  import { detectMdx } from './detect-mdx.js';
8
+ import { nativeFormat } from './rust-formatter.js';
9
9
  export { detectMdx };
10
10
  /**
11
- * Format markdown/MDX content using hybrid AST approach
11
+ * Format markdown/MDX content using the Rust formatter.
12
12
  */
13
13
  export async function format(content, options = {}) {
14
- try {
15
- const settings = loadConfig(options);
16
- let result = content;
17
- // Some rule interactions (e.g., list indent normalization + addEmptyLinesInBlockJsx)
18
- // may require multiple passes to converge. 3 iterations is sufficient for all known
19
- // cases (most files converge in 1, edge cases in 2).
20
- const MAX_ITERATIONS = 3;
21
- for (let i = 0; i < MAX_ITERATIONS; i++) {
22
- const formatter = new MdxFormatter(result, settings);
23
- const formatted = await formatter.format();
24
- if (formatted === result)
25
- break;
26
- result = formatted;
27
- }
28
- return result;
29
- }
30
- catch {
31
- // Silently return original content if formatting fails
32
- // This is expected for files with certain JSX patterns that remark-mdx doesn't like
33
- return content;
34
- }
14
+ const settings = loadConfig(options);
15
+ const settingsJson = JSON.stringify(settings);
16
+ return nativeFormat(content, settingsJson);
35
17
  }
36
18
  /**
37
19
  * Format a file and write it back if changed
@@ -53,7 +35,6 @@ export async function checkFile(filePath, options = {}) {
53
35
  const formatted = await format(content, options);
54
36
  return content !== formatted;
55
37
  }
56
- // Export all functions
57
38
  export default {
58
39
  format,
59
40
  formatFile,
@@ -25,7 +25,11 @@ function findConfigFile(configPath) {
25
25
  if (configPath) {
26
26
  try {
27
27
  const content = readFileSync(resolve(configPath), 'utf-8');
28
- return JSON.parse(content);
28
+ const parsed = JSON.parse(content);
29
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
30
+ return null;
31
+ }
32
+ return parsed;
29
33
  }
30
34
  catch {
31
35
  return null;
@@ -34,7 +38,11 @@ function findConfigFile(configPath) {
34
38
  // Try .mdx-formatter.json in cwd
35
39
  try {
36
40
  const content = readFileSync(resolve('.mdx-formatter.json'), 'utf-8');
37
- return JSON.parse(content);
41
+ const parsed = JSON.parse(content);
42
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
43
+ return null;
44
+ }
45
+ return parsed;
38
46
  }
39
47
  catch {
40
48
  // Not found, try package.json
@@ -1,15 +1,16 @@
1
1
  /**
2
- * Wrapper for the Rust napi formatter.
3
- * This module loads the native Rust formatter compiled via napi-rs
4
- * and exposes the same format() API as the TypeScript implementation.
2
+ * Rust napi formatter loader.
3
+ * Loads the native Rust formatter compiled via napi-rs.
4
+ * This is the sole formatting engine no TypeScript fallback.
5
5
  */
6
- import type { FormatOptions } from './types.js';
6
+ type NativeFormat = (content: string, settingsJson: string) => string;
7
7
  /**
8
- * Check if the Rust formatter is available
8
+ * The native format function. Loaded once at module init.
9
+ * Throws if the native module is not available.
9
10
  */
10
- export declare function isRustFormatterAvailable(): boolean;
11
+ export declare const nativeFormat: NativeFormat;
11
12
  /**
12
- * Format markdown/MDX content using the Rust formatter
13
- * API-compatible with the TypeScript format() function
13
+ * Check if the Rust formatter is available
14
14
  */
15
- export declare function format(content: string, options?: FormatOptions): Promise<string>;
15
+ export declare function isRustFormatterAvailable(): boolean;
16
+ export {};
@@ -1,35 +1,57 @@
1
1
  /**
2
- * Wrapper for the Rust napi formatter.
3
- * This module loads the native Rust formatter compiled via napi-rs
4
- * and exposes the same format() API as the TypeScript implementation.
2
+ * Rust napi formatter loader.
3
+ * Loads the native Rust formatter compiled via napi-rs.
4
+ * This is the sole formatting engine no TypeScript fallback.
5
5
  */
6
6
  import { createRequire } from 'module';
7
- import { loadConfig } from './load-config.js';
7
+ import { platform, arch } from 'os';
8
8
  const require = createRequire(import.meta.url);
9
- // Try to load the native module
10
- let nativeFormat = null;
11
- try {
12
- const native = require('../crates/mdx-formatter-napi/mdx-formatter-napi.node');
13
- nativeFormat = native.format;
9
+ function getPackageName() {
10
+ const platformName = platform();
11
+ const archName = arch();
12
+ const platformMap = {
13
+ darwin: {
14
+ arm64: '@takazudo/mdx-formatter-darwin-arm64',
15
+ x64: '@takazudo/mdx-formatter-darwin-x64',
16
+ },
17
+ linux: {
18
+ x64: '@takazudo/mdx-formatter-linux-x64-gnu',
19
+ },
20
+ win32: {
21
+ x64: '@takazudo/mdx-formatter-win32-x64-msvc',
22
+ },
23
+ };
24
+ return platformMap[platformName]?.[archName] ?? '';
14
25
  }
15
- catch {
16
- // Native module not available - not built yet or wrong platform
26
+ function loadNativeModule() {
27
+ // Try platform-specific npm package first
28
+ const packageName = getPackageName();
29
+ if (packageName) {
30
+ try {
31
+ const native = require(packageName);
32
+ return native.format;
33
+ }
34
+ catch {
35
+ // Platform package not installed, try local build
36
+ }
37
+ }
38
+ // Try local build
39
+ try {
40
+ const native = require('../crates/mdx-formatter-napi/mdx-formatter-napi.node');
41
+ return native.format;
42
+ }
43
+ catch {
44
+ throw new Error('Rust native module not available. Build it with: pnpm build:rust');
45
+ }
17
46
  }
18
47
  /**
19
- * Check if the Rust formatter is available
48
+ * The native format function. Loaded once at module init.
49
+ * Throws if the native module is not available.
20
50
  */
21
- export function isRustFormatterAvailable() {
22
- return nativeFormat !== null;
23
- }
51
+ export const nativeFormat = loadNativeModule();
24
52
  /**
25
- * Format markdown/MDX content using the Rust formatter
26
- * API-compatible with the TypeScript format() function
53
+ * Check if the Rust formatter is available
27
54
  */
28
- export async function format(content, options = {}) {
29
- if (!nativeFormat) {
30
- throw new Error('Rust formatter not available. Build it first with: cd crates/mdx-formatter-napi && cargo build');
31
- }
32
- const settings = loadConfig(options);
33
- const settingsJson = JSON.stringify(settings);
34
- return nativeFormat(content, settingsJson);
55
+ export function isRustFormatterAvailable() {
56
+ return true; // If we got here, the module loaded successfully
35
57
  }
@@ -4,4 +4,3 @@
4
4
  */
5
5
  import type { FormatterSettings } from './types.js';
6
6
  export declare const formatterSettings: FormatterSettings;
7
- export declare function getEnabledRules(): Partial<FormatterSettings>;
package/dist/settings.js CHANGED
@@ -83,12 +83,3 @@ export const formatterSettings = {
83
83
  minConfidence: 0.7, // Minimum confidence score to use detected indentation
84
84
  },
85
85
  };
86
- // Export function to get only enabled rules
87
- export function getEnabledRules() {
88
- return Object.entries(formatterSettings)
89
- .filter(([_, config]) => config.enabled)
90
- .reduce((acc, [key, config]) => {
91
- acc[key] = config;
92
- return acc;
93
- }, {});
94
- }
package/dist/types.d.ts CHANGED
@@ -1,68 +1,6 @@
1
1
  /**
2
2
  * Core type definitions for mdx-formatter
3
3
  */
4
- import type { Node, Parent, Position } from 'unist';
5
- import type { Root } from 'mdast';
6
- export type { Node, Parent, Position, Root };
7
- /**
8
- * Common AST node interfaces used across plugins
9
- */
10
- export interface ParentNode extends Node {
11
- children: Node[];
12
- }
13
- export interface TextNode extends Node {
14
- type: 'text';
15
- value: string;
16
- }
17
- export interface HeadingNode extends Node {
18
- type: 'heading';
19
- children: Node[];
20
- }
21
- export interface HtmlNode extends Node {
22
- value?: string;
23
- }
24
- export interface ListNode extends Node {
25
- type: 'list';
26
- ordered?: boolean;
27
- start?: number | null;
28
- spread?: boolean;
29
- children: ListItemNode[];
30
- }
31
- export interface ListItemNode extends Node {
32
- type: 'listItem';
33
- spread?: boolean;
34
- data?: Record<string, unknown>;
35
- }
36
- /**
37
- * MDX JSX attribute value expression node
38
- */
39
- export interface MdxJsxAttributeValueExpression {
40
- type: 'mdxJsxAttributeValueExpression';
41
- value?: string;
42
- position?: Position;
43
- data?: {
44
- estree?: unknown;
45
- };
46
- }
47
- /**
48
- * MDX JSX attribute node
49
- */
50
- export interface MdxJsxAttribute {
51
- type: 'mdxJsxAttribute';
52
- name: string;
53
- value: string | MdxJsxAttributeValueExpression | null | undefined;
54
- }
55
- /**
56
- * MDX JSX element node (flow or text)
57
- */
58
- export interface MdxJsxElement extends Node {
59
- type: 'mdxJsxFlowElement' | 'mdxJsxTextElement';
60
- name: string | null;
61
- attributes: MdxJsxAttribute[];
62
- children: Node[];
63
- selfClosing?: boolean;
64
- data?: Record<string, unknown>;
65
- }
66
4
  /**
67
5
  * Individual formatter setting rule configurations
68
6
  */
@@ -157,64 +95,3 @@ export interface FormatOptions {
157
95
  export type DeepPartial<T> = {
158
96
  [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
159
97
  };
160
- /**
161
- * Formatter operation types used in MdxFormatter
162
- */
163
- export type FormatterOperation = {
164
- type: 'insertLine';
165
- startLine: number;
166
- content: string;
167
- } | {
168
- type: 'replaceLines';
169
- startLine: number;
170
- endLine: number;
171
- lines: string[];
172
- } | {
173
- type: 'indentLine';
174
- startLine: number;
175
- indent: string;
176
- } | {
177
- type: 'fixListIndent';
178
- startLine: number;
179
- indent: string;
180
- } | {
181
- type: 'replaceHtmlBlock';
182
- startLine: number;
183
- endLine: number;
184
- content: string;
185
- };
186
- /**
187
- * Position map entry for line/character mapping
188
- */
189
- export interface PositionMapEntry {
190
- line: number;
191
- start: number;
192
- end: number;
193
- }
194
- /**
195
- * Indent detector interface (for duck-typed fallback)
196
- */
197
- export interface IndentDetectorLike {
198
- getIndentSize(): number;
199
- getIndentType(): string;
200
- getIndentString(): string;
201
- getConfidence(): number;
202
- formatWithIndent(text: string, level: number): string;
203
- }
204
- /**
205
- * Indent detection statistics
206
- */
207
- export interface IndentStats {
208
- totalLines: number;
209
- indentedLines: number;
210
- patterns: Record<string, number>;
211
- tabLines: number;
212
- spaceLines: number;
213
- }
214
- /**
215
- * Indent pattern entry
216
- */
217
- export interface IndentPattern {
218
- type: 'tab' | 'space';
219
- size: number;
220
- }
package/dist/utils.js CHANGED
@@ -29,6 +29,9 @@ export function deepCloneSettings(obj) {
29
29
  export function deepMerge(target, source) {
30
30
  const result = deepCloneSettings(target);
31
31
  for (const key of Object.keys(source)) {
32
+ if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
33
+ continue;
34
+ }
32
35
  const sourceVal = source[key];
33
36
  const targetVal = result[key];
34
37
  if (sourceVal &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takazudo/mdx-formatter",
3
- "version": "0.5.0-next.3",
3
+ "version": "1.0.1",
4
4
  "description": "AST-based markdown and MDX formatter with Japanese text support",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -38,8 +38,13 @@
38
38
  "check": "prettier --check . && eslint .",
39
39
  "check:fix": "prettier --write . && eslint --fix .",
40
40
  "test:rust": "vitest run --config vitest.rust.config.ts",
41
- "build:rust": "cd crates/mdx-formatter-napi && cargo build",
42
- "build:rust:release": "cd crates/mdx-formatter-napi && cargo build --release",
41
+ "test:rust-passthrough": "vitest run --config vitest.rust-passthrough.config.ts",
42
+ "build:rust": ". \"$HOME/.cargo/env\" && cargo build -p mdx-formatter-napi && cp target/debug/libmdx_formatter_napi.so crates/mdx-formatter-napi/mdx-formatter-napi.node",
43
+ "build:rust:release": ". \"$HOME/.cargo/env\" && cargo build -p mdx-formatter-napi --release && cp target/release/libmdx_formatter_napi.so crates/mdx-formatter-napi/mdx-formatter-napi.node",
44
+ "benchmark": "npx tsx benchmark/run.ts",
45
+ "build:wasm": ". \"$HOME/.cargo/env\" && wasm-pack build crates/mdx-formatter-wasm --target web --out-dir ../../wasm/pkg",
46
+ "build:wasm:bundler": ". \"$HOME/.cargo/env\" && wasm-pack build crates/mdx-formatter-wasm --target bundler --out-dir ../../wasm/pkg-bundler",
47
+ "build:wasm:doc": ". \"$HOME/.cargo/env\" && wasm-pack build crates/mdx-formatter-wasm --target web --out-dir ../../doc/src/wasm-pkg && mkdir -p doc/public/wasm && cp doc/src/wasm-pkg/mdx_formatter_wasm_bg.wasm doc/public/wasm/",
43
48
  "b4push": "./scripts/run-b4push.sh",
44
49
  "doc:start": "pnpm --dir doc start",
45
50
  "prepublishOnly": "tsc && vitest run"
@@ -70,33 +75,35 @@
70
75
  "chalk": "^5.3.0",
71
76
  "commander": "^14.0.3",
72
77
  "glob": "^13.0.1",
73
- "js-yaml": "^4.1.1",
74
- "prettier": "^3.8.0",
75
- "remark": "^15.0.1",
76
- "remark-directive": "^3.0.0",
77
- "remark-frontmatter": "^5.0.0",
78
- "remark-gfm": "^4.0.0",
79
- "remark-mdx": "^3.0.0",
80
- "remark-parse": "^11.0.0",
81
- "remark-stringify": "^11.0.0",
82
- "unified": "^11.0.4",
83
- "unist-util-visit": "^5.0.0"
78
+ "js-yaml": "^4.1.1"
84
79
  },
85
80
  "devDependencies": {
86
- "@types/hast": "^3.0.4",
87
81
  "@types/js-yaml": "^4.0.9",
88
- "@types/mdast": "^4.0.4",
89
82
  "@types/node": "^25.2.1",
90
- "@types/unist": "^3.0.3",
91
83
  "@vitest/coverage-v8": "^4.0.17",
92
84
  "eslint": "^9.39.2",
93
85
  "lefthook": "^2.1.4",
86
+ "prettier": "^3.8.1",
94
87
  "typescript": "^5.9.3",
95
88
  "typescript-eslint": "^8.54.0",
96
- "vfile": "^6.0.3",
97
89
  "vitest": "^4.0.17"
98
90
  },
91
+ "optionalDependencies": {
92
+ "@takazudo/mdx-formatter-darwin-arm64": "1.0.0",
93
+ "@takazudo/mdx-formatter-darwin-x64": "1.0.0",
94
+ "@takazudo/mdx-formatter-linux-x64-gnu": "1.0.0",
95
+ "@takazudo/mdx-formatter-win32-x64-msvc": "1.0.0"
96
+ },
99
97
  "engines": {
100
98
  "node": ">=18.0.0"
99
+ },
100
+ "napi": {
101
+ "binaryName": "mdx-formatter-napi",
102
+ "targets": [
103
+ "aarch64-apple-darwin",
104
+ "x86_64-apple-darwin",
105
+ "x86_64-unknown-linux-gnu",
106
+ "x86_64-pc-windows-msvc"
107
+ ]
101
108
  }
102
109
  }
@@ -1,46 +0,0 @@
1
- /**
2
- * HTML Block Formatter
3
- * Formats HTML blocks within MDX content using Prettier or built-in formatting
4
- */
5
- import type { FormatHtmlBlocksInMdxSetting } from './types.js';
6
- export declare class HtmlBlockFormatter {
7
- private settings;
8
- private readonly htmlElements;
9
- constructor(settings?: Partial<FormatHtmlBlocksInMdxSetting>);
10
- /**
11
- * Check if a tag name is an HTML element (not a JSX component)
12
- */
13
- isHtmlElement(tagName: string): boolean;
14
- /**
15
- * Format HTML content using Prettier
16
- */
17
- formatWithPrettier(html: string): Promise<string>;
18
- /**
19
- * Extract HTML block from position in original content
20
- */
21
- extractHtmlBlock(content: string, startPos: {
22
- line: number;
23
- column: number;
24
- }, endPos: {
25
- line: number;
26
- column: number;
27
- }): string;
28
- /**
29
- * Find matching closing tag for an opening tag
30
- */
31
- findMatchingClosingTag(content: string, startIndex: number, tagName: string): number;
32
- /**
33
- * Format MDX content with HTML block formatting
34
- */
35
- format(content: string): Promise<string>;
36
- /**
37
- * Replace HTML block in content with formatted version
38
- */
39
- replaceHtmlBlock(content: string, startPos: {
40
- line: number;
41
- column: number;
42
- }, endPos: {
43
- line: number;
44
- column: number;
45
- }, replacement: string): string;
46
- }