minimark 0.1.0 → 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.md +73 -4
- package/dist/hast.d.mts +3 -3
- package/dist/hast.mjs +5 -5
- package/dist/stringify.mjs +6 -3
- package/package.json +7 -8
package/README.md
CHANGED
|
@@ -70,14 +70,83 @@ console.log(stringify(ast));
|
|
|
70
70
|
|
|
71
71
|
## API
|
|
72
72
|
|
|
73
|
-
### `stringify(node, options?)`
|
|
74
73
|
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
### `visit(tree, predicate, callback)`
|
|
75
|
+
|
|
76
|
+
- `tree`: The minimark tree to visit.
|
|
77
|
+
- `predicate`: A function that returns a boolean indicating whether the node should be visited.
|
|
78
|
+
- `callback`: A function that will be called with the node and its children.
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import { visit } from 'minimark';
|
|
82
|
+
|
|
83
|
+
const ast = [
|
|
84
|
+
type: 'minimal',
|
|
85
|
+
value: [
|
|
86
|
+
['h2', { id: 'documentations' }, '🎨 Documentations'], // ...
|
|
87
|
+
],
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
visit(ast, (node) => node[0] === 'h2', (node) => {
|
|
91
|
+
console.log(node);
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### `textContent(node)`
|
|
96
|
+
|
|
97
|
+
- `node`: The AST node to get the text content of.
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import { textContent } from 'minimark';
|
|
101
|
+
const ast = [
|
|
102
|
+
type: 'minimal',
|
|
103
|
+
value: [
|
|
104
|
+
['h2', { id: 'documentations' }, '🎨 Documentations'], // ...
|
|
105
|
+
],
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
console.log(textContent(ast.value[0])); // "🎨 Documentations"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### `toHast(tree)`
|
|
112
|
+
|
|
113
|
+
- `tree`: The Minimark tree to convert to hast.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { toHast } from 'minimark/hast';
|
|
117
|
+
|
|
118
|
+
const ast = [
|
|
119
|
+
type: 'minimal',
|
|
120
|
+
value: [
|
|
121
|
+
['h2', { id: 'documentations' }, '🎨 Documentations'], // ...
|
|
122
|
+
],
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
const hast = toHast(ast);
|
|
126
|
+
console.log(hast);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### `fromHast(tree)`
|
|
130
|
+
|
|
131
|
+
- `tree`: The hast tree to convert to minimark.
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
|
|
135
|
+
const hast = {
|
|
136
|
+
type: 'root',
|
|
137
|
+
children: [
|
|
138
|
+
{ type: 'element', tag: 'h2', props: { id: 'documentations' }, children: [{ type: 'text', value: '🎨 Documentations' }] },
|
|
139
|
+
],
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const minimark = fromHast(hast);
|
|
143
|
+
console.log(minimark);
|
|
144
|
+
```
|
|
145
|
+
|
|
77
146
|
|
|
78
147
|
## Contributing
|
|
79
148
|
|
|
80
|
-
Contributions are welcome! Please open issues
|
|
149
|
+
Contributions are welcome! Please open issues and submit pull requests.
|
|
81
150
|
|
|
82
151
|
## License
|
|
83
152
|
|
package/dist/hast.d.mts
CHANGED
|
@@ -15,13 +15,13 @@ interface HastNode {
|
|
|
15
15
|
props?: Record<string, unknown>;
|
|
16
16
|
children?: HastNode[];
|
|
17
17
|
}
|
|
18
|
-
declare function
|
|
18
|
+
declare function fromHast(tree: {
|
|
19
19
|
type: 'root';
|
|
20
20
|
children: HastNode[];
|
|
21
21
|
}): MinimarkTree;
|
|
22
|
-
declare function
|
|
22
|
+
declare function toHast(tree: MinimarkTree): {
|
|
23
23
|
type: 'root';
|
|
24
24
|
children: HastNode[];
|
|
25
25
|
};
|
|
26
26
|
//#endregion
|
|
27
|
-
export {
|
|
27
|
+
export { fromHast, toHast };
|
package/dist/hast.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
//#region src/hast.ts
|
|
2
|
-
function
|
|
2
|
+
function fromHast(tree) {
|
|
3
3
|
return {
|
|
4
4
|
type: "minimark",
|
|
5
|
-
value:
|
|
5
|
+
value: tree.children.map(hastToMinimarkNode).filter((v) => v !== void 0)
|
|
6
6
|
};
|
|
7
7
|
}
|
|
8
8
|
function hastToMinimarkNode(input) {
|
|
@@ -15,10 +15,10 @@ function hastToMinimarkNode(input) {
|
|
|
15
15
|
...(input.children || []).map(hastToMinimarkNode).filter((v) => v !== void 0)
|
|
16
16
|
];
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function toHast(tree) {
|
|
19
19
|
return {
|
|
20
20
|
type: "root",
|
|
21
|
-
children:
|
|
21
|
+
children: tree.value.map(minimarkToHastNode)
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
function minimarkToHastNode(input) {
|
|
@@ -36,4 +36,4 @@ function minimarkToHastNode(input) {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
//#endregion
|
|
39
|
-
export {
|
|
39
|
+
export { fromHast, toHast };
|
package/dist/stringify.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
//#region src/utils/index.ts
|
|
2
|
-
function indent(text) {
|
|
3
|
-
return text.split("\n").map((line) =>
|
|
2
|
+
function indent(text, { ignoreFirstLine = false } = {}) {
|
|
3
|
+
return text.split("\n").map((line, index) => {
|
|
4
|
+
if (ignoreFirstLine && index === 0) return line;
|
|
5
|
+
return " " + line;
|
|
6
|
+
}).join("\n");
|
|
4
7
|
}
|
|
5
8
|
function textContent(node) {
|
|
6
9
|
if (typeof node === "string") return node;
|
|
@@ -99,7 +102,7 @@ function li(node, state) {
|
|
|
99
102
|
const input = children.shift();
|
|
100
103
|
prefix += input[1].checked ? "[x] " : "[ ] ";
|
|
101
104
|
}
|
|
102
|
-
const result = children.map((child) => state.one(child, state)
|
|
105
|
+
const result = children.map((child) => state.one(child, state)).join("").trim();
|
|
103
106
|
if (order) state.applyContext({ order: order + 1 });
|
|
104
107
|
return `${prefix}${result}\n`;
|
|
105
108
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "minimark",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"packageManager": "pnpm@
|
|
4
|
+
"version": "0.2.0",
|
|
5
|
+
"packageManager": "pnpm@10.11.0",
|
|
6
6
|
"description": "MiniMark is a minimal representation of Abstract Syntax Trees (AST)",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"repository": {
|
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
"exports": {
|
|
13
13
|
".": "./dist/index.mjs",
|
|
14
14
|
"./hast": "./dist/hast.mjs",
|
|
15
|
-
"./stringify": "./dist/stringify.mjs"
|
|
16
|
-
"./visit": "./dist/visit.mjs"
|
|
15
|
+
"./stringify": "./dist/stringify.mjs"
|
|
17
16
|
},
|
|
18
17
|
"files": [
|
|
19
18
|
"dist"
|
|
@@ -32,10 +31,10 @@
|
|
|
32
31
|
"@nuxt/eslint-config": "^1.4.1",
|
|
33
32
|
"@nuxtjs/mdc": "^0.17.0",
|
|
34
33
|
"@release-it/conventional-changelog": "^10.0.1",
|
|
35
|
-
"eslint": "^9.
|
|
36
|
-
"obuild": "^0.2.
|
|
37
|
-
"release-it": "^19.0.
|
|
34
|
+
"eslint": "^9.28.0",
|
|
35
|
+
"obuild": "^0.2.1",
|
|
36
|
+
"release-it": "^19.0.3",
|
|
38
37
|
"typescript": "^5.8.3",
|
|
39
|
-
"vitest": "^3.
|
|
38
|
+
"vitest": "^3.2.0"
|
|
40
39
|
}
|
|
41
40
|
}
|