@amamo/mdx 0.1.6 → 0.2.0
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.
- package/dist/config.d.ts +23 -1
- package/dist/config.js +37 -1
- package/dist/index.d.ts +1 -1
- package/package.json +10 -10
package/dist/config.d.ts
CHANGED
|
@@ -23,10 +23,21 @@ export interface ICollectionConfig {
|
|
|
23
23
|
sensitive?: string[];
|
|
24
24
|
slug?: ISlugConfig;
|
|
25
25
|
}
|
|
26
|
+
export interface IMathConfig {
|
|
27
|
+
macros?: Record<string, string>;
|
|
28
|
+
singleDollar?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface IMdxExtensionsConfig {
|
|
31
|
+
footnotes?: boolean;
|
|
32
|
+
headingIds?: boolean;
|
|
33
|
+
taskLists?: boolean;
|
|
34
|
+
}
|
|
26
35
|
export interface IMdxConfig {
|
|
36
|
+
extensions?: IMdxExtensionsConfig;
|
|
27
37
|
gfm?: boolean;
|
|
28
38
|
hardBreaks?: boolean;
|
|
29
39
|
jsxImportSource?: string;
|
|
40
|
+
math?: false | IMathConfig;
|
|
30
41
|
providerImportSource?: string;
|
|
31
42
|
}
|
|
32
43
|
export interface IHighlightConfig {
|
|
@@ -115,7 +126,18 @@ export interface INormalizedConfig {
|
|
|
115
126
|
generatedDirectory: string;
|
|
116
127
|
highlight: INormalizedHighlightConfig;
|
|
117
128
|
manifests: Record<string, INormalizedManifestConfig>;
|
|
118
|
-
mdx:
|
|
129
|
+
mdx: {
|
|
130
|
+
extensions: Required<IMdxExtensionsConfig>;
|
|
131
|
+
gfm: boolean;
|
|
132
|
+
hardBreaks: boolean;
|
|
133
|
+
jsxImportSource: string;
|
|
134
|
+
math: {
|
|
135
|
+
enabled: boolean;
|
|
136
|
+
macros: Record<string, string>;
|
|
137
|
+
singleDollar: boolean;
|
|
138
|
+
};
|
|
139
|
+
providerImportSource: string;
|
|
140
|
+
};
|
|
119
141
|
media: INormalizedMediaConfig;
|
|
120
142
|
root: string;
|
|
121
143
|
}
|
package/dist/config.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
1
2
|
import { existsSync, realpathSync } from 'node:fs';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
const DEFAULT_MEDIA_ATTRIBUTES = {
|
|
@@ -9,6 +10,9 @@ const DEFAULT_MEDIA_ATTRIBUTES = {
|
|
|
9
10
|
track: ['src'],
|
|
10
11
|
video: ['src', 'poster'],
|
|
11
12
|
};
|
|
13
|
+
const MATH_MACRO_NAME = /^\\(?:[A-Za-z@]+|[^\s])$/u;
|
|
14
|
+
const MAX_MATH_MACRO_BYTES = 1024;
|
|
15
|
+
const MAX_MATH_MACROS_BYTES = 16 * 1024;
|
|
12
16
|
function notSerializable(location, reason) {
|
|
13
17
|
throw new TypeError(`AMAMO_CONFIG_NOT_SERIALIZABLE: ${location} ${reason}`);
|
|
14
18
|
}
|
|
@@ -69,6 +73,9 @@ export function defineConfig(config) {
|
|
|
69
73
|
}
|
|
70
74
|
export function normalizeConfig(config) {
|
|
71
75
|
assertPlainData(config, 'config', new WeakSet());
|
|
76
|
+
if (Object.hasOwn(config, 'math')) {
|
|
77
|
+
throw new TypeError('AMAMO_CONFIG_INVALID: math moved to mdx.math');
|
|
78
|
+
}
|
|
72
79
|
if (!config.collections || Object.keys(config.collections).length === 0) {
|
|
73
80
|
throw new TypeError('AMAMO_CONFIG_INVALID: collections must not be empty');
|
|
74
81
|
}
|
|
@@ -89,7 +96,26 @@ export function normalizeConfig(config) {
|
|
|
89
96
|
},
|
|
90
97
|
]));
|
|
91
98
|
const highlight = config.highlight === false ? undefined : config.highlight;
|
|
99
|
+
const math = config.mdx?.math === false ? undefined : config.mdx?.math;
|
|
92
100
|
const media = config.media === false ? undefined : config.media;
|
|
101
|
+
const gfm = config.mdx?.gfm ?? true;
|
|
102
|
+
let macroBytes = 0;
|
|
103
|
+
for (const [name, expansion] of Object.entries(math?.macros ?? {})) {
|
|
104
|
+
if (!name.startsWith('\\')) {
|
|
105
|
+
throw new TypeError(`AMAMO_CONFIG_INVALID: mdx.math.macros.${name} must start with a backslash`);
|
|
106
|
+
}
|
|
107
|
+
if (!MATH_MACRO_NAME.test(name)) {
|
|
108
|
+
throw new TypeError(`AMAMO_CONFIG_INVALID: mdx.math.macros.${name} must be one TeX control sequence`);
|
|
109
|
+
}
|
|
110
|
+
const expansionBytes = Buffer.byteLength(expansion);
|
|
111
|
+
if (expansionBytes > MAX_MATH_MACRO_BYTES) {
|
|
112
|
+
throw new TypeError(`AMAMO_CONFIG_INVALID: mdx.math.macros.${name} exceeds the ${MAX_MATH_MACRO_BYTES}-byte limit`);
|
|
113
|
+
}
|
|
114
|
+
macroBytes += Buffer.byteLength(name) + expansionBytes;
|
|
115
|
+
if (macroBytes > MAX_MATH_MACROS_BYTES) {
|
|
116
|
+
throw new TypeError(`AMAMO_CONFIG_INVALID: mdx.math.macros exceeds the ${MAX_MATH_MACROS_BYTES}-byte total limit`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
93
119
|
return {
|
|
94
120
|
cache: {
|
|
95
121
|
directory: path.resolve(root, config.cache === false
|
|
@@ -116,9 +142,19 @@ export function normalizeConfig(config) {
|
|
|
116
142
|
},
|
|
117
143
|
manifests,
|
|
118
144
|
mdx: {
|
|
119
|
-
|
|
145
|
+
extensions: {
|
|
146
|
+
footnotes: config.mdx?.extensions?.footnotes ?? gfm,
|
|
147
|
+
headingIds: config.mdx?.extensions?.headingIds ?? false,
|
|
148
|
+
taskLists: config.mdx?.extensions?.taskLists ?? gfm,
|
|
149
|
+
},
|
|
150
|
+
gfm,
|
|
120
151
|
hardBreaks: config.mdx?.hardBreaks ?? false,
|
|
121
152
|
jsxImportSource: config.mdx?.jsxImportSource ?? 'react',
|
|
153
|
+
math: {
|
|
154
|
+
enabled: config.mdx?.math !== undefined && config.mdx.math !== false,
|
|
155
|
+
macros: { ...math?.macros },
|
|
156
|
+
singleDollar: math?.singleDollar ?? true,
|
|
157
|
+
},
|
|
122
158
|
providerImportSource: config.mdx?.providerImportSource ?? '',
|
|
123
159
|
},
|
|
124
160
|
media: {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { IAmamoMdxConfig, ICacheConfig, ICollectionConfig, IDerivedConfig, IHighlightConfig, ILocaleConfig, IManifestConfig, IMdxConfig, IMediaConfig, INormalizedConfig, JsonValue, ManifestField, } from './config.js';
|
|
1
|
+
export type { IAmamoMdxConfig, ICacheConfig, ICollectionConfig, IDerivedConfig, IHighlightConfig, ILocaleConfig, IManifestConfig, IMathConfig, IMdxConfig, IMdxExtensionsConfig, IMediaConfig, INormalizedConfig, JsonValue, ManifestField, } from './config.js';
|
|
2
2
|
export { defineConfig, normalizeConfig } from './config.js';
|
|
3
3
|
export type { IBuildResult, ICompiler, ITransformResult } from './compiler.js';
|
|
4
4
|
export { createCompiler } from './compiler.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amamo/mdx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A native MDX content compiler with Vite and Next adapters",
|
|
5
5
|
"homepage": "https://jikkai.github.io/mdx/",
|
|
6
6
|
"license": "MIT",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@amamo/oxlint-config": "1.0.0",
|
|
60
60
|
"@amamo/verso": "1.0.1",
|
|
61
|
-
"@napi-rs/cli": "3.8.
|
|
62
|
-
"@types/node": "26.
|
|
61
|
+
"@napi-rs/cli": "3.8.4",
|
|
62
|
+
"@types/node": "26.2.0",
|
|
63
63
|
"@types/react": "19.2.18",
|
|
64
64
|
"@types/react-dom": "19.2.4",
|
|
65
65
|
"lint-staged": "17.3.0",
|
|
@@ -116,12 +116,12 @@
|
|
|
116
116
|
},
|
|
117
117
|
"packageManager": "pnpm@11.20.0",
|
|
118
118
|
"optionalDependencies": {
|
|
119
|
-
"@amamo/mdx-darwin-arm64": "0.
|
|
120
|
-
"@amamo/mdx-darwin-x64": "0.
|
|
121
|
-
"@amamo/mdx-linux-arm64-gnu": "0.
|
|
122
|
-
"@amamo/mdx-linux-x64-gnu": "0.
|
|
123
|
-
"@amamo/mdx-linux-arm64-musl": "0.
|
|
124
|
-
"@amamo/mdx-linux-x64-musl": "0.
|
|
125
|
-
"@amamo/mdx-win32-x64-msvc": "0.
|
|
119
|
+
"@amamo/mdx-darwin-arm64": "0.2.0",
|
|
120
|
+
"@amamo/mdx-darwin-x64": "0.2.0",
|
|
121
|
+
"@amamo/mdx-linux-arm64-gnu": "0.2.0",
|
|
122
|
+
"@amamo/mdx-linux-x64-gnu": "0.2.0",
|
|
123
|
+
"@amamo/mdx-linux-arm64-musl": "0.2.0",
|
|
124
|
+
"@amamo/mdx-linux-x64-musl": "0.2.0",
|
|
125
|
+
"@amamo/mdx-win32-x64-msvc": "0.2.0"
|
|
126
126
|
}
|
|
127
127
|
}
|