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 CHANGED
@@ -70,14 +70,83 @@ console.log(stringify(ast));
70
70
 
71
71
  ## API
72
72
 
73
- ### `stringify(node, options?)`
74
73
 
75
- - `node`: The AST node to stringify.
76
- - `options`: (Optional) Configuration options.
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 or submit pull requests.
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 hastToMinimark(input: {
18
+ declare function fromHast(tree: {
19
19
  type: 'root';
20
20
  children: HastNode[];
21
21
  }): MinimarkTree;
22
- declare function minimarkToHast(input: MinimarkTree): {
22
+ declare function toHast(tree: MinimarkTree): {
23
23
  type: 'root';
24
24
  children: HastNode[];
25
25
  };
26
26
  //#endregion
27
- export { hastToMinimark, minimarkToHast };
27
+ export { fromHast, toHast };
package/dist/hast.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  //#region src/hast.ts
2
- function hastToMinimark(input) {
2
+ function fromHast(tree) {
3
3
  return {
4
4
  type: "minimark",
5
- value: input.children.map(hastToMinimarkNode).filter((v) => v !== void 0)
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 minimarkToHast(input) {
18
+ function toHast(tree) {
19
19
  return {
20
20
  type: "root",
21
- children: input.value.map(minimarkToHastNode)
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 { hastToMinimark, minimarkToHast };
39
+ export { fromHast, toHast };
@@ -1,6 +1,9 @@
1
1
  //#region src/utils/index.ts
2
- function indent(text) {
3
- return text.split("\n").map((line) => " " + line).join("\n");
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).trimEnd()).join("").trim();
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.1.0",
5
- "packageManager": "pnpm@9.15.9+sha512.68046141893c66fad01c079231128e9afb89ef87e2691d69e4d40eee228988295fd4682181bae55b58418c3a253bde65a505ec7c5f9403ece5cc3cd37dcf2531",
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.27.0",
36
- "obuild": "^0.2.0",
37
- "release-it": "^19.0.2",
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.1.4"
38
+ "vitest": "^3.2.0"
40
39
  }
41
40
  }