@isdk/mdast-plus 0.1.3 → 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/README.cn.md +22 -9
- package/README.md +17 -4
- package/dist/index.d.mts +394 -83
- package/dist/index.d.ts +394 -83
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/docs/README.md +17 -4
- package/docs/_media/CONTRIBUTING.md +21 -13
- package/docs/_media/README.cn.md +22 -9
- package/docs/classes/MdastBasePipeline.md +96 -28
- package/docs/classes/MdastPipeline.md +116 -36
- package/docs/enumerations/PipelineStage.md +6 -6
- package/docs/functions/astCompiler.md +1 -1
- package/docs/functions/jsonParser.md +1 -1
- package/docs/functions/mdast.md +1 -1
- package/docs/globals.md +5 -0
- package/docs/interfaces/MdastDataOrigin.md +4 -4
- package/docs/interfaces/MdastFormat.md +7 -7
- package/docs/interfaces/MdastMark.md +3 -3
- package/docs/interfaces/MdastPlugin.md +38 -6
- package/docs/interfaces/MdastSub.md +3 -3
- package/docs/interfaces/MdastSup.md +3 -3
- package/docs/interfaces/ReadabilityOptions.md +33 -0
- package/docs/type-aliases/PipelineStageName.md +1 -1
- package/docs/variables/DefaultPipelineStage.md +1 -1
- package/docs/variables/astFormat.md +1 -1
- package/docs/variables/htmlFormat.md +1 -1
- package/docs/variables/htmlReadability.md +13 -0
- package/docs/variables/htmlReadabilityPlugin.md +27 -0
- package/docs/variables/htmlReadabilityPlugins.md +13 -0
- package/docs/variables/markdownFormat.md +1 -1
- package/docs/variables/restoreReadabilityMetaPlugin.md +49 -0
- package/package.json +8 -1
package/README.cn.md
CHANGED
|
@@ -71,12 +71,18 @@ const rawAst = await mdast('==高亮内容==').toAST({ stage: 'parse' });
|
|
|
71
71
|
### 高级工作流
|
|
72
72
|
|
|
73
73
|
```typescript
|
|
74
|
-
|
|
74
|
+
import { htmlReadabilityPlugins } from '@isdk/mdast-plus';
|
|
75
|
+
|
|
76
|
+
const vfile = await mdast(myInput)
|
|
75
77
|
.data({ myGlobal: 'value' })
|
|
76
|
-
//
|
|
77
|
-
.
|
|
78
|
+
// 以数组形式在 'compile' 阶段添加多个插件
|
|
79
|
+
.use([pluginA, pluginB])
|
|
80
|
+
// 或在特定阶段添加一组插件
|
|
81
|
+
.useAt('parse', htmlReadabilityPlugins)
|
|
78
82
|
.priority(10) // 比默认插件更晚执行
|
|
79
83
|
.to('html');
|
|
84
|
+
|
|
85
|
+
console.log(vfile.value); // 序列化后的 HTML 字符串
|
|
80
86
|
```
|
|
81
87
|
|
|
82
88
|
### 插件行为
|
|
@@ -125,13 +131,19 @@ const result = await mdast('Hello').to('reverse');
|
|
|
125
131
|
|
|
126
132
|
## 分阶段处理
|
|
127
133
|
|
|
128
|
-
插件根据它们的 `stage` (阶段)
|
|
134
|
+
插件根据它们的 `stage` (阶段)、`order` (顺序) 以及语义约束 (`before`/`after`) 执行:
|
|
135
|
+
|
|
136
|
+
1. **parse** (0): 输入解析 (例如 `remark-parse`)。
|
|
137
|
+
2. **normalize** (100): 清理并规范化树。
|
|
138
|
+
3. **compile** (200): 高级语义转换。
|
|
139
|
+
4. **finalize** (300): 输出前的最后准备 (例如 `rehype-sanitize`)。
|
|
140
|
+
5. **stringify** (400): 输出生成。
|
|
141
|
+
|
|
142
|
+
### 主插件替换 (Main Plugin Replacement)
|
|
143
|
+
|
|
144
|
+
每个阶段可以有一个“主”插件。如果一个插件被标记为 `main: true`,它将 **替换** 该阶段中的第一个插件。这对于在保持管道其余部分不变的情况下更换默认解析器或编译器非常有用。
|
|
129
145
|
|
|
130
|
-
|
|
131
|
-
2. **normalize** (100): 清理并规范化树。
|
|
132
|
-
3. **compile** (200): 高级语义转换。
|
|
133
|
-
4. **finalize** (300): 输出前的最后准备 (例如 `rehype-sanitize`)。
|
|
134
|
-
5. **stringify** (400): 输出生成。
|
|
146
|
+
> **注意**: 每个阶段只允许存在一个主插件。如果多个插件被标记为 main,则只有最后定义的那个会作为替换生效。
|
|
135
147
|
|
|
136
148
|
## 内置核心插件
|
|
137
149
|
|
|
@@ -142,6 +154,7 @@ const result = await mdast('Hello').to('reverse');
|
|
|
142
154
|
| `extract-code-meta` | normalize | 从代码块元数据中解析 `title="foo"`。 |
|
|
143
155
|
| `image-size` | normalize | 从图片 URL 中解析 `#=WxH`。 |
|
|
144
156
|
| `normalize-inline-styles` | normalize | 标准化 `==mark==`、`~sub~` 和 `^sup^`。 |
|
|
157
|
+
| `html-readability` | parse | 使用 Mozilla 的 Readability 从 HTML 中提取主体内容。使用 `htmlReadabilityPlugins` 数组可以简化配置。 |
|
|
145
158
|
|
|
146
159
|
## 贡献
|
|
147
160
|
|
package/README.md
CHANGED
|
@@ -71,12 +71,18 @@ const rawAst = await mdast('==Highlighted==').toAST({ stage: 'parse' });
|
|
|
71
71
|
### Advanced Pipeline
|
|
72
72
|
|
|
73
73
|
```typescript
|
|
74
|
-
|
|
74
|
+
import { htmlReadabilityPlugins } from '@isdk/mdast-plus';
|
|
75
|
+
|
|
76
|
+
const vfile = await mdast(myInput)
|
|
75
77
|
.data({ myGlobal: 'value' })
|
|
76
|
-
// Add
|
|
77
|
-
.
|
|
78
|
+
// Add multiple plugins as an array at the 'compile' stage
|
|
79
|
+
.use([pluginA, pluginB])
|
|
80
|
+
// Or add a set of plugins at a specific stage
|
|
81
|
+
.useAt('parse', htmlReadabilityPlugins)
|
|
78
82
|
.priority(10) // Run later than default plugins
|
|
79
83
|
.to('html');
|
|
84
|
+
|
|
85
|
+
console.log(vfile.value); // The serialized HTML string
|
|
80
86
|
```
|
|
81
87
|
|
|
82
88
|
### Plugin Behavior
|
|
@@ -125,7 +131,7 @@ const result = await mdast('Hello').to('reverse');
|
|
|
125
131
|
|
|
126
132
|
## Staged Processing
|
|
127
133
|
|
|
128
|
-
Plugins are executed based on their `stage` and `
|
|
134
|
+
Plugins are executed based on their `stage`, `order`, and semantic constraints (`before`/`after`):
|
|
129
135
|
|
|
130
136
|
1. **parse** (0): Input parsing (e.g., `remark-parse`).
|
|
131
137
|
2. **normalize** (100): Cleanup and canonicalize the tree.
|
|
@@ -133,6 +139,12 @@ Plugins are executed based on their `stage` and `order`:
|
|
|
133
139
|
4. **finalize** (300): Final preparation before output (e.g. `rehype-sanitize`).
|
|
134
140
|
5. **stringify** (400): Output generation.
|
|
135
141
|
|
|
142
|
+
### Main Plugin Replacement
|
|
143
|
+
|
|
144
|
+
Each stage can have one "main" plugin. If a plugin is marked with `main: true`, it will **replace** the first plugin in that same stage. This is useful for swapping out default parsers or compilers while keeping the rest of the pipeline intact.
|
|
145
|
+
|
|
146
|
+
> **Note**: Only one main plugin is allowed per stage. If multiple plugins are marked as main, only the last one defined will take effect as the replacement.
|
|
147
|
+
|
|
136
148
|
## Core Plugins Included
|
|
137
149
|
|
|
138
150
|
| Plugin | Stage | Description |
|
|
@@ -142,6 +154,7 @@ Plugins are executed based on their `stage` and `order`:
|
|
|
142
154
|
| `extract-code-meta` | normalize | Parses `title="foo"` from code block meta. |
|
|
143
155
|
| `image-size` | normalize | Parses `#=WxH` from image URLs. |
|
|
144
156
|
| `normalize-inline-styles` | normalize | Standardizes `==mark==`, `~sub~`, and `^sup^`. |
|
|
157
|
+
| `html-readability` | parse | Uses Mozilla's Readability to extract main content from HTML. Use `htmlReadabilityPlugins` array for easier setup. |
|
|
145
158
|
|
|
146
159
|
## Contributing
|
|
147
160
|
|