@isdk/mdast-plus 0.1.2 → 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.
Files changed (43) hide show
  1. package/README.cn.md +69 -22
  2. package/README.md +69 -22
  3. package/dist/index.d.mts +564 -199
  4. package/dist/index.d.ts +564 -199
  5. package/dist/index.js +1 -1
  6. package/dist/index.mjs +1 -1
  7. package/docs/README.md +69 -22
  8. package/docs/_media/CONTRIBUTING.md +53 -24
  9. package/docs/_media/README.cn.md +69 -22
  10. package/docs/classes/MdastBasePipeline.md +416 -0
  11. package/docs/classes/MdastPipeline.md +611 -0
  12. package/docs/enumerations/PipelineStage.md +62 -0
  13. package/docs/functions/astCompiler.md +25 -0
  14. package/docs/functions/jsonParser.md +24 -0
  15. package/docs/functions/mdast.md +4 -4
  16. package/docs/globals.md +17 -10
  17. package/docs/interfaces/MdastDataOrigin.md +8 -8
  18. package/docs/interfaces/MdastFormat.md +71 -0
  19. package/docs/interfaces/MdastMark.md +4 -4
  20. package/docs/interfaces/MdastPlugin.md +57 -25
  21. package/docs/interfaces/MdastSub.md +4 -4
  22. package/docs/interfaces/MdastSup.md +4 -4
  23. package/docs/interfaces/ReadabilityOptions.md +33 -0
  24. package/docs/type-aliases/PipelineStageName.md +13 -0
  25. package/docs/variables/DefaultPipelineStage.md +13 -0
  26. package/docs/variables/astFormat.md +15 -0
  27. package/docs/variables/htmlFormat.md +6 -4
  28. package/docs/variables/htmlReadability.md +13 -0
  29. package/docs/variables/htmlReadabilityPlugin.md +27 -0
  30. package/docs/variables/htmlReadabilityPlugins.md +13 -0
  31. package/docs/variables/markdownFormat.md +6 -4
  32. package/docs/variables/restoreReadabilityMetaPlugin.md +49 -0
  33. package/package.json +18 -9
  34. package/docs/classes/FluentProcessor.md +0 -210
  35. package/docs/functions/htmlStringify.md +0 -23
  36. package/docs/functions/markdownCommon.md +0 -23
  37. package/docs/interfaces/ConvertResult.md +0 -39
  38. package/docs/interfaces/MdastAsset.md +0 -41
  39. package/docs/interfaces/MdastFormatDefinition.md +0 -51
  40. package/docs/interfaces/MdastReader.md +0 -41
  41. package/docs/interfaces/MdastTransformer.md +0 -33
  42. package/docs/interfaces/MdastWriter.md +0 -47
  43. package/docs/type-aliases/Stage.md +0 -13
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@isdk/mdast-plus",
3
3
  "description": "A semantic-first Markdown processing toolkit based on unified, remark, and rehype with a Fluent API and staged plugin system.",
4
- "version": "0.1.2",
4
+ "version": "0.2.0",
5
5
  "license": "MIT",
6
6
  "author": "Riceball LEE <snowyu.lee@gmail.com>",
7
7
  "homepage": "https://github.com/isdk/mdast-plus.js",
@@ -22,30 +22,38 @@
22
22
  }
23
23
  },
24
24
  "dependencies": {
25
+ "@mozilla/readability": "^0.6.0",
25
26
  "ajv": "^8.17.1",
26
27
  "ajv-formats": "^3.0.1",
27
- "lodash-es": "^4.17.22",
28
- "mdast-util-to-hast": "^13.2.1",
28
+ "hast-util-from-dom": "^5.0.1",
29
+ "hast-util-from-html": "^2.0.3",
29
30
  "hast-util-to-mdast": "^10.1.2",
31
+ "lodash-es": "^4.17.22",
30
32
  "mdast-util-directive": "^3.1.0",
31
33
  "mdast-util-gfm": "^3.1.0",
32
34
  "mdast-util-math": "^3.0.0",
35
+ "mdast-util-to-hast": "^13.2.1",
36
+ "rehype-parse": "^9.0.1",
37
+ "rehype-remark": "^10.0.1",
38
+ "rehype-sanitize": "^6.0.0",
39
+ "rehype-stringify": "^10.0.1",
33
40
  "remark-directive": "^4.0.0",
34
41
  "remark-frontmatter": "^5.0.0",
35
42
  "remark-gfm": "^4.0.1",
36
43
  "remark-math": "^6.0.0",
37
44
  "remark-parse": "^11.0.0",
38
- "remark-stringify": "^11.0.0",
39
- "rehype-parse": "^9.0.1",
40
- "rehype-stringify": "^10.0.1",
41
- "rehype-remark": "^10.0.1",
42
45
  "remark-rehype": "^11.1.2",
43
- "rehype-sanitize": "^6.0.0",
46
+ "remark-stringify": "^11.0.0",
44
47
  "shell-quote": "^1.8.3",
45
48
  "unified": "^11.0.5",
46
49
  "unist-util-select": "^5.1.0",
47
50
  "unist-util-visit": "^5.0.0",
48
- "util-ex": "^2.4.0"
51
+ "util-ex": "^2.4.0",
52
+ "vfile": "^6.0.3",
53
+ "yaml": "^2.8.2"
54
+ },
55
+ "peerDependencies": {
56
+ "jsdom": "^27.3.0"
49
57
  },
50
58
  "devDependencies": {
51
59
  "@antfu/eslint-config": "^4.10.1",
@@ -61,6 +69,7 @@
61
69
  "eslint": "^9.34.0",
62
70
  "eslint-config-prettier": "^10.1.8",
63
71
  "eslint-plugin-tsdoc": "^0.4.0",
72
+ "jsdom": "^27.3.0",
64
73
  "json-schema-to-typescript": "^15.0.4",
65
74
  "prettier": "^3.6.2",
66
75
  "terser": "^5.44.0",
@@ -1,210 +0,0 @@
1
- [**@isdk/mdast-plus**](../README.md)
2
-
3
- ***
4
-
5
- [@isdk/mdast-plus](../globals.md) / FluentProcessor
6
-
7
- # Class: FluentProcessor
8
-
9
- Defined in: [packages/mdast-plus/src/pipeline.ts:20](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/pipeline.ts#L20)
10
-
11
- Fluent processor for mdast transformations.
12
- Allows chaining configuration and finally converting to a target format.
13
-
14
- ## Constructors
15
-
16
- ### Constructor
17
-
18
- > **new FluentProcessor**(`input`): `FluentProcessor`
19
-
20
- Defined in: [packages/mdast-plus/src/pipeline.ts:54](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/pipeline.ts#L54)
21
-
22
- Creates a new FluentProcessor instance.
23
-
24
- #### Parameters
25
-
26
- ##### input
27
-
28
- `any`
29
-
30
- The input content (string or mdast tree)
31
-
32
- #### Returns
33
-
34
- `FluentProcessor`
35
-
36
- ## Properties
37
-
38
- ### formats
39
-
40
- > `static` **formats**: `Record`\<`string`, [`MdastFormatDefinition`](../interfaces/MdastFormatDefinition.md)\>
41
-
42
- Defined in: [packages/mdast-plus/src/pipeline.ts:22](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/pipeline.ts#L22)
43
-
44
- Map of registered format definitions
45
-
46
- ## Methods
47
-
48
- ### data()
49
-
50
- > **data**(`data`): `this`
51
-
52
- Defined in: [packages/mdast-plus/src/pipeline.ts:88](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/pipeline.ts#L88)
53
-
54
- Merges global data into the processor.
55
-
56
- #### Parameters
57
-
58
- ##### data
59
-
60
- `Record`\<`string`, `any`\>
61
-
62
- Key-value pairs to store in global data
63
-
64
- #### Returns
65
-
66
- `this`
67
-
68
- ***
69
-
70
- ### from()
71
-
72
- > **from**(`format`): `this`
73
-
74
- Defined in: [packages/mdast-plus/src/pipeline.ts:70](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/pipeline.ts#L70)
75
-
76
- Specifies the input format.
77
-
78
- #### Parameters
79
-
80
- ##### format
81
-
82
- `string`
83
-
84
- The input format name (default: 'markdown')
85
-
86
- #### Returns
87
-
88
- `this`
89
-
90
- ***
91
-
92
- ### to()
93
-
94
- > **to**(`format`): `Promise`\<[`ConvertResult`](../interfaces/ConvertResult.md)\<`string`\>\>
95
-
96
- Defined in: [packages/mdast-plus/src/pipeline.ts:98](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/pipeline.ts#L98)
97
-
98
- Converts the input content to the specified format.
99
-
100
- #### Parameters
101
-
102
- ##### format
103
-
104
- `string`
105
-
106
- The output format name
107
-
108
- #### Returns
109
-
110
- `Promise`\<[`ConvertResult`](../interfaces/ConvertResult.md)\<`string`\>\>
111
-
112
- A promise resolving to the conversion result (content and assets)
113
-
114
- ***
115
-
116
- ### toAST()
117
-
118
- > **toAST**(): `Promise`\<`Root`\>
119
-
120
- Defined in: [packages/mdast-plus/src/pipeline.ts:180](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/pipeline.ts#L180)
121
-
122
- Helper to get the processed mdast tree.
123
-
124
- #### Returns
125
-
126
- `Promise`\<`Root`\>
127
-
128
- A promise resolving to the mdast Root node
129
-
130
- ***
131
-
132
- ### toHTML()
133
-
134
- > **toHTML**(): `Promise`\<`string`\>
135
-
136
- Defined in: [packages/mdast-plus/src/pipeline.ts:171](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/pipeline.ts#L171)
137
-
138
- Helper to convert content to HTML.
139
-
140
- #### Returns
141
-
142
- `Promise`\<`string`\>
143
-
144
- A promise resolving to the HTML string
145
-
146
- ***
147
-
148
- ### toMarkdown()
149
-
150
- > **toMarkdown**(): `Promise`\<`string`\>
151
-
152
- Defined in: [packages/mdast-plus/src/pipeline.ts:162](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/pipeline.ts#L162)
153
-
154
- Helper to convert content to Markdown.
155
-
156
- #### Returns
157
-
158
- `Promise`\<`string`\>
159
-
160
- A promise resolving to the Markdown string
161
-
162
- ***
163
-
164
- ### use()
165
-
166
- > **use**(`plugin`): `this`
167
-
168
- Defined in: [packages/mdast-plus/src/pipeline.ts:79](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/pipeline.ts#L79)
169
-
170
- Adds a plugin to the processing pipeline.
171
-
172
- #### Parameters
173
-
174
- ##### plugin
175
-
176
- [`MdastPlugin`](../interfaces/MdastPlugin.md)
177
-
178
- The mdast plugin to use
179
-
180
- #### Returns
181
-
182
- `this`
183
-
184
- ***
185
-
186
- ### registerFormat()
187
-
188
- > `static` **registerFormat**(`name`, `definition`): `void`
189
-
190
- Defined in: [packages/mdast-plus/src/pipeline.ts:40](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/pipeline.ts#L40)
191
-
192
- Registers a new format definition.
193
-
194
- #### Parameters
195
-
196
- ##### name
197
-
198
- `string`
199
-
200
- The name of the format (e.g., 'docx')
201
-
202
- ##### definition
203
-
204
- [`MdastFormatDefinition`](../interfaces/MdastFormatDefinition.md)
205
-
206
- The format definition containing parse/stringify logic
207
-
208
- #### Returns
209
-
210
- `void`
@@ -1,23 +0,0 @@
1
- [**@isdk/mdast-plus**](../README.md)
2
-
3
- ***
4
-
5
- [@isdk/mdast-plus](../globals.md) / htmlStringify
6
-
7
- # Function: htmlStringify()
8
-
9
- > **htmlStringify**(`this`): `void`
10
-
11
- Defined in: [packages/mdast-plus/src/formats/html.ts:12](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/formats/html.ts#L12)
12
-
13
- Standard compiler/stringifier for HTML.
14
-
15
- ## Parameters
16
-
17
- ### this
18
-
19
- `any`
20
-
21
- ## Returns
22
-
23
- `void`
@@ -1,23 +0,0 @@
1
- [**@isdk/mdast-plus**](../README.md)
2
-
3
- ***
4
-
5
- [@isdk/mdast-plus](../globals.md) / markdownCommon
6
-
7
- # Function: markdownCommon()
8
-
9
- > **markdownCommon**(`this`): `void`
10
-
11
- Defined in: [packages/mdast-plus/src/formats/markdown.ts:13](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/formats/markdown.ts#L13)
12
-
13
- Common remark configuration for Markdown.
14
-
15
- ## Parameters
16
-
17
- ### this
18
-
19
- `any`
20
-
21
- ## Returns
22
-
23
- `void`
@@ -1,39 +0,0 @@
1
- [**@isdk/mdast-plus**](../README.md)
2
-
3
- ***
4
-
5
- [@isdk/mdast-plus](../globals.md) / ConvertResult
6
-
7
- # Interface: ConvertResult\<T\>
8
-
9
- Defined in: [packages/mdast-plus/src/types.ts:50](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/types.ts#L50)
10
-
11
- Result of a conversion process.
12
-
13
- ## Type Parameters
14
-
15
- ### T
16
-
17
- `T` = `string`
18
-
19
- The type of the main content (default: string)
20
-
21
- ## Properties
22
-
23
- ### assets
24
-
25
- > **assets**: [`MdastAsset`](MdastAsset.md)[]
26
-
27
- Defined in: [packages/mdast-plus/src/types.ts:54](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/types.ts#L54)
28
-
29
- Extracted assets
30
-
31
- ***
32
-
33
- ### content
34
-
35
- > **content**: `T`
36
-
37
- Defined in: [packages/mdast-plus/src/types.ts:52](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/types.ts#L52)
38
-
39
- The converted content
@@ -1,41 +0,0 @@
1
- [**@isdk/mdast-plus**](../README.md)
2
-
3
- ***
4
-
5
- [@isdk/mdast-plus](../globals.md) / MdastAsset
6
-
7
- # Interface: MdastAsset
8
-
9
- Defined in: [packages/mdast-plus/src/types.ts:37](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/types.ts#L37)
10
-
11
- Represents an asset (e.g., image) extracted during processing.
12
-
13
- ## Properties
14
-
15
- ### bytes
16
-
17
- > **bytes**: `Uint8Array`
18
-
19
- Defined in: [packages/mdast-plus/src/types.ts:43](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/types.ts#L43)
20
-
21
- Raw content as bytes
22
-
23
- ***
24
-
25
- ### contentType
26
-
27
- > **contentType**: `string`
28
-
29
- Defined in: [packages/mdast-plus/src/types.ts:41](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/types.ts#L41)
30
-
31
- MIME type of the asset
32
-
33
- ***
34
-
35
- ### path
36
-
37
- > **path**: `string`
38
-
39
- Defined in: [packages/mdast-plus/src/types.ts:39](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/types.ts#L39)
40
-
41
- Relative path or identifier for the asset
@@ -1,51 +0,0 @@
1
- [**@isdk/mdast-plus**](../README.md)
2
-
3
- ***
4
-
5
- [@isdk/mdast-plus](../globals.md) / MdastFormatDefinition
6
-
7
- # Interface: MdastFormatDefinition
8
-
9
- Defined in: [packages/mdast-plus/src/types.ts:27](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/types.ts#L27)
10
-
11
- Definition for an mdast format (parser/stringifier).
12
-
13
- ## Properties
14
-
15
- ### parse()?
16
-
17
- > `optional` **parse**: (`processor`) => `void`
18
-
19
- Defined in: [packages/mdast-plus/src/types.ts:29](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/types.ts#L29)
20
-
21
- Function to register parser plugins
22
-
23
- #### Parameters
24
-
25
- ##### processor
26
-
27
- `any`
28
-
29
- #### Returns
30
-
31
- `void`
32
-
33
- ***
34
-
35
- ### stringify()?
36
-
37
- > `optional` **stringify**: (`processor`) => `void`
38
-
39
- Defined in: [packages/mdast-plus/src/types.ts:31](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/types.ts#L31)
40
-
41
- Function to register stringifier plugins
42
-
43
- #### Parameters
44
-
45
- ##### processor
46
-
47
- `any`
48
-
49
- #### Returns
50
-
51
- `void`
@@ -1,41 +0,0 @@
1
- [**@isdk/mdast-plus**](../README.md)
2
-
3
- ***
4
-
5
- [@isdk/mdast-plus](../globals.md) / MdastReader
6
-
7
- # Interface: MdastReader\<I\>
8
-
9
- Defined in: [packages/mdast-plus/src/types.ts:131](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/types.ts#L131)
10
-
11
- Interface for reading input into an mdast tree.
12
-
13
- ## Type Parameters
14
-
15
- ### I
16
-
17
- `I`
18
-
19
- Input type
20
-
21
- ## Methods
22
-
23
- ### read()
24
-
25
- > **read**(`input`): `Promise`\<`Root`\>
26
-
27
- Defined in: [packages/mdast-plus/src/types.ts:136](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/types.ts#L136)
28
-
29
- Reads input and returns an mdast Root node.
30
-
31
- #### Parameters
32
-
33
- ##### input
34
-
35
- `I`
36
-
37
- The input to read
38
-
39
- #### Returns
40
-
41
- `Promise`\<`Root`\>
@@ -1,33 +0,0 @@
1
- [**@isdk/mdast-plus**](../README.md)
2
-
3
- ***
4
-
5
- [@isdk/mdast-plus](../globals.md) / MdastTransformer
6
-
7
- # Interface: MdastTransformer
8
-
9
- Defined in: [packages/mdast-plus/src/types.ts:142](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/types.ts#L142)
10
-
11
- Interface for transforming an mdast tree.
12
-
13
- ## Methods
14
-
15
- ### transform()
16
-
17
- > **transform**(`tree`): `Promise`\<\{ `assets?`: [`MdastAsset`](MdastAsset.md)[]; `tree`: `Root`; \}\>
18
-
19
- Defined in: [packages/mdast-plus/src/types.ts:147](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/types.ts#L147)
20
-
21
- Transforms the given mdast tree.
22
-
23
- #### Parameters
24
-
25
- ##### tree
26
-
27
- `Root`
28
-
29
- The Root node to transform
30
-
31
- #### Returns
32
-
33
- `Promise`\<\{ `assets?`: [`MdastAsset`](MdastAsset.md)[]; `tree`: `Root`; \}\>
@@ -1,47 +0,0 @@
1
- [**@isdk/mdast-plus**](../README.md)
2
-
3
- ***
4
-
5
- [@isdk/mdast-plus](../globals.md) / MdastWriter
6
-
7
- # Interface: MdastWriter\<Output\>
8
-
9
- Defined in: [packages/mdast-plus/src/types.ts:154](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/types.ts#L154)
10
-
11
- Interface for writing an mdast tree to an output format.
12
-
13
- ## Type Parameters
14
-
15
- ### Output
16
-
17
- `Output` = `string`
18
-
19
- Output type (default: string)
20
-
21
- ## Methods
22
-
23
- ### write()
24
-
25
- > **write**(`tree`, `assets?`): `Promise`\<[`ConvertResult`](ConvertResult.md)\<`Output`\>\>
26
-
27
- Defined in: [packages/mdast-plus/src/types.ts:160](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/types.ts#L160)
28
-
29
- Writes the mdast tree to the target output.
30
-
31
- #### Parameters
32
-
33
- ##### tree
34
-
35
- `Root`
36
-
37
- The Root node to write
38
-
39
- ##### assets?
40
-
41
- [`MdastAsset`](MdastAsset.md)[]
42
-
43
- Optional assets to include
44
-
45
- #### Returns
46
-
47
- `Promise`\<[`ConvertResult`](ConvertResult.md)\<`Output`\>\>
@@ -1,13 +0,0 @@
1
- [**@isdk/mdast-plus**](../README.md)
2
-
3
- ***
4
-
5
- [@isdk/mdast-plus](../globals.md) / Stage
6
-
7
- # Type Alias: Stage
8
-
9
- > **Stage** = `"normalize"` \| `"compile"` \| `"finalize"`
10
-
11
- Defined in: [packages/mdast-plus/src/types.ts:8](https://github.com/isdk/mdast-plus.js/blob/75ee549d3fb31ef4bc1b4a6b3307f6368072874e/src/types.ts#L8)
12
-
13
- Stages for mdast-plus pipeline processing.