minimark 0.0.1
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/LICENSE +21 -0
- package/README.md +56 -0
- package/dist/bundle.mjs +246 -0
- package/dist/bundle.mjs.map +1 -0
- package/dist/index.mjs +273 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) minimark
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# minimark
|
|
2
|
+
|
|
3
|
+
A utility for converting Abstract Syntax Trees (AST) into string representations.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Converts AST nodes to readable strings
|
|
8
|
+
- Supports various AST formats
|
|
9
|
+
- Easy to use and extend
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install minimark
|
|
15
|
+
# or
|
|
16
|
+
yarn add minimark
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import { stringify } from 'minimark';
|
|
23
|
+
|
|
24
|
+
const ast = [
|
|
25
|
+
type: 'minimal',
|
|
26
|
+
value: [
|
|
27
|
+
['h2', { id: 'documentations' }, '🎨 Documentations'],
|
|
28
|
+
['ul', {}, [
|
|
29
|
+
['li', {}, ['a', { href: '/nuxt/getting-started' }, 'Nuxt v3']],
|
|
30
|
+
['li', {}, ['a', { href: '/content/getting-started' }, 'Nuxt Content v3']],
|
|
31
|
+
]],
|
|
32
|
+
],
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
console.log(stringify(ast));
|
|
36
|
+
// Output:
|
|
37
|
+
// # Documentations
|
|
38
|
+
//
|
|
39
|
+
// - [Nuxt v3](https://nuxt.com/docs/getting-started)
|
|
40
|
+
// - [Nuxt Content v3](https://content.nuxtjs.org/getting-started)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## API
|
|
44
|
+
|
|
45
|
+
### `stringify(node, options?)`
|
|
46
|
+
|
|
47
|
+
- `node`: The AST node to stringify.
|
|
48
|
+
- `options`: (Optional) Configuration options.
|
|
49
|
+
|
|
50
|
+
## Contributing
|
|
51
|
+
|
|
52
|
+
Contributions are welcome! Please open issues or submit pull requests.
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
MIT
|
package/dist/bundle.mjs
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
function indent(text) {
|
|
2
|
+
return text.split('\n').map(line => ' ' + line).join('\n');
|
|
3
|
+
}
|
|
4
|
+
function text(node) {
|
|
5
|
+
if (typeof node === 'string') {
|
|
6
|
+
return node;
|
|
7
|
+
}
|
|
8
|
+
const [_, attributes, ...children] = node;
|
|
9
|
+
return children.map(child => text(child)).join('');
|
|
10
|
+
}
|
|
11
|
+
function htmlAttributes(attributes) {
|
|
12
|
+
return Object.entries(attributes)
|
|
13
|
+
.map(([key, value]) => `${key}="${value}"`)
|
|
14
|
+
.join(' ');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function code(node, _) {
|
|
18
|
+
return `\`${text(node)}\``;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function pre(node, state) {
|
|
22
|
+
const [_, attributes, ...children] = node;
|
|
23
|
+
const language = (attributes.language || '');
|
|
24
|
+
const filename = attributes.filename ? ' [' + attributes.filename + ']' : '';
|
|
25
|
+
const result = '```' + language + filename + (attributes.meta || '') + '\n'
|
|
26
|
+
+ String(node[1]?.code || children.join('')).trim()
|
|
27
|
+
+ '\n```';
|
|
28
|
+
return result + state.blockSeparator;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function hr(_, state) {
|
|
32
|
+
return '---' + state.blockSeparator;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// h1, h2, h3, h4, h5, h6
|
|
36
|
+
function heading(node, state) {
|
|
37
|
+
const [tag, _, ...children] = node;
|
|
38
|
+
const level = Number(tag.slice(1));
|
|
39
|
+
return '#'.repeat(level) + ' ' + children.join('') + state.context.blockSeparator;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function p(node, state) {
|
|
43
|
+
const children = node.slice(2);
|
|
44
|
+
return children.map(child => state.one(child, state)).join('') + state.context.blockSeparator;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// TODO: support title & attributes
|
|
48
|
+
function a(node, state) {
|
|
49
|
+
const [_, attributes] = node;
|
|
50
|
+
const content = state.flow(node, state);
|
|
51
|
+
return `[${content}](${attributes.href})`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function ul(node, state) {
|
|
55
|
+
const children = node.slice(2);
|
|
56
|
+
const revert = state.applyContext({ list: true, order: false });
|
|
57
|
+
let result = children.map(child => state.one(child, state)).join('')
|
|
58
|
+
.trim();
|
|
59
|
+
if (revert.list) {
|
|
60
|
+
result = '\n' + indent(result);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
result = result + state.context.blockSeparator;
|
|
64
|
+
}
|
|
65
|
+
state.applyContext(revert);
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function ol(node, state) {
|
|
70
|
+
const children = node.slice(2);
|
|
71
|
+
const revert = state.applyContext({ list: true, order: 1 });
|
|
72
|
+
let result = children.map(child => state.one(child, state)).join('').trim();
|
|
73
|
+
if (revert.list) {
|
|
74
|
+
result = '\n' + indent(result);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
result = result + state.context.blockSeparator;
|
|
78
|
+
}
|
|
79
|
+
state.applyContext(revert);
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function li(node, state) {
|
|
84
|
+
const children = node.slice(2);
|
|
85
|
+
const order = state.context.order;
|
|
86
|
+
const prefix = order ? `${order}. ` : '- ';
|
|
87
|
+
const result = children.map(child => state.one(child, state).trimEnd()).join('').trim();
|
|
88
|
+
if (order) {
|
|
89
|
+
state.applyContext({ order: order + 1 });
|
|
90
|
+
}
|
|
91
|
+
return `${prefix}${result}\n`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function html(node, state) {
|
|
95
|
+
const [tag, attributes, ...children] = node;
|
|
96
|
+
const inline = children.every(child => typeof child === 'string');
|
|
97
|
+
// Do not modify context if we are already in html mode
|
|
98
|
+
const revert = !state.context.html ? state.applyContext({ html: true }) : null;
|
|
99
|
+
const content = children.map(child => state.one(child, state))
|
|
100
|
+
.join('').trim();
|
|
101
|
+
// Revert, only if we modified the context
|
|
102
|
+
revert && state.applyContext(revert);
|
|
103
|
+
const attrs = Object.keys(attributes).length > 0
|
|
104
|
+
? ` ${htmlAttributes(attributes)}`
|
|
105
|
+
: '';
|
|
106
|
+
return inline
|
|
107
|
+
? `<${tag}${attrs}>${content}</${tag}>`
|
|
108
|
+
: `<${tag}${attrs}>\n${indent(content)}\n</${tag}>` + state.context.blockSeparator;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function strong(node, _) {
|
|
112
|
+
return `**${text(node)}**`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function emphesis(node, _) {
|
|
116
|
+
return `*${text(node)}*`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function blockquote(node, state) {
|
|
120
|
+
const children = node.slice(2);
|
|
121
|
+
const content = children.map((child) => state.one(child, state))
|
|
122
|
+
.join('')
|
|
123
|
+
.trim()
|
|
124
|
+
.split('\n')
|
|
125
|
+
.map((line) => `> ${line}`)
|
|
126
|
+
.join('\n');
|
|
127
|
+
return content + state.context.blockSeparator;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function img(node, _) {
|
|
131
|
+
const [tag, attrs] = node;
|
|
132
|
+
return ``;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function del(node, _) {
|
|
136
|
+
return `~~${text(node)}~~`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function mdc(node, state) {
|
|
140
|
+
const [tag, attributes, ...children] = node;
|
|
141
|
+
if (tag === 'table') {
|
|
142
|
+
return html(node, state);
|
|
143
|
+
}
|
|
144
|
+
const inline = children.every(child => typeof child === 'string');
|
|
145
|
+
const content = children.map(child => state.one(child, state))
|
|
146
|
+
.join('').trim();
|
|
147
|
+
const attrs = Object.keys(attributes).length > 0
|
|
148
|
+
? `{${htmlAttributes(attributes)}}`
|
|
149
|
+
: '';
|
|
150
|
+
if (tag === 'span') {
|
|
151
|
+
return `[${content}]${attrs}`;
|
|
152
|
+
}
|
|
153
|
+
return inline
|
|
154
|
+
? `:${tag}${content && `[${content}]`}${attrs}`
|
|
155
|
+
: `::${tag}${attrs}\n${content}\n::` + state.context.blockSeparator;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const handlers = {
|
|
159
|
+
code,
|
|
160
|
+
pre,
|
|
161
|
+
hr,
|
|
162
|
+
h1: heading,
|
|
163
|
+
h2: heading,
|
|
164
|
+
h3: heading,
|
|
165
|
+
h4: heading,
|
|
166
|
+
h5: heading,
|
|
167
|
+
h6: heading,
|
|
168
|
+
p,
|
|
169
|
+
a,
|
|
170
|
+
ul,
|
|
171
|
+
ol,
|
|
172
|
+
li,
|
|
173
|
+
html,
|
|
174
|
+
strong,
|
|
175
|
+
em: emphesis,
|
|
176
|
+
blockquote,
|
|
177
|
+
img,
|
|
178
|
+
del,
|
|
179
|
+
mdc
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
function one(node, state) {
|
|
183
|
+
if (typeof node === 'string') {
|
|
184
|
+
return node;
|
|
185
|
+
}
|
|
186
|
+
if (state.context.html) {
|
|
187
|
+
return state.handlers.html(node, state);
|
|
188
|
+
}
|
|
189
|
+
let nodeHandler = state.context.handlers?.[node[0]] || state.handlers[node[0]];
|
|
190
|
+
if (nodeHandler) {
|
|
191
|
+
return nodeHandler(node, state);
|
|
192
|
+
}
|
|
193
|
+
return state.context.format === 'markdown/mdc'
|
|
194
|
+
? state.handlers.mdc(node, state)
|
|
195
|
+
: state.handlers.html(node, state);
|
|
196
|
+
}
|
|
197
|
+
function flow(node, state) {
|
|
198
|
+
const [_, attributes, ...children] = node;
|
|
199
|
+
let result = '';
|
|
200
|
+
for (const child of children) {
|
|
201
|
+
result += one(child, state);
|
|
202
|
+
}
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
205
|
+
function createState(ctx = {}) {
|
|
206
|
+
const context = {
|
|
207
|
+
blockSeparator: '\n\n',
|
|
208
|
+
format: 'markdown/mdc',
|
|
209
|
+
handlers: {}, // user defined node handlers
|
|
210
|
+
...ctx,
|
|
211
|
+
};
|
|
212
|
+
return {
|
|
213
|
+
handlers,
|
|
214
|
+
context,
|
|
215
|
+
flow,
|
|
216
|
+
one,
|
|
217
|
+
applyContext: (edit) => {
|
|
218
|
+
const revert = {};
|
|
219
|
+
for (const [key, value] of Object.entries(edit)) {
|
|
220
|
+
revert[key] = context[key];
|
|
221
|
+
context[key] = value;
|
|
222
|
+
}
|
|
223
|
+
return revert;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const defaultOptions = {
|
|
229
|
+
format: 'markdown/mdc',
|
|
230
|
+
removeLastStyle: true
|
|
231
|
+
};
|
|
232
|
+
function stringify(node, options = {}) {
|
|
233
|
+
options = { ...defaultOptions, ...options };
|
|
234
|
+
const _state = createState(options);
|
|
235
|
+
const children = node.value;
|
|
236
|
+
const lastIndex = children.length - 1;
|
|
237
|
+
return children.map((child, index) => {
|
|
238
|
+
if (index === lastIndex && options.removeLastStyle && child[0] === 'style') {
|
|
239
|
+
return '';
|
|
240
|
+
}
|
|
241
|
+
return one(child, _state);
|
|
242
|
+
}).join('').trim() + '\n';
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export { stringify };
|
|
246
|
+
//# sourceMappingURL=bundle.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.mjs","sources":["../../src/utils.ts","../../src/handlers/code.ts","../../src/handlers/pre.ts","../../src/handlers/hr.ts","../../src/handlers/heading.ts","../../src/handlers/p.ts","../../src/handlers/a.ts","../../src/handlers/ul.ts","../../src/handlers/ol.ts","../../src/handlers/li.ts","../../src/handlers/html.ts","../../src/handlers/strong.ts","../../src/handlers/emphesis.ts","../../src/handlers/blockquote.ts","../../src/handlers/img.ts","../../src/handlers/del.ts","../../src/handlers/mdc.ts","../../src/handlers/index.ts","../../src/state.ts","../../src/index.ts"],"sourcesContent":["import type { MinimalNode } from \"@nuxt/content\"\n\nexport function indent(text: string) {\n return text.split('\\n').map(line => ' ' + line).join('\\n')\n}\n\nexport function text(node: MinimalNode): string {\n if (typeof node === 'string') {\n return node as string\n }\n const [_, attributes, ...children] = node\n\n return children.map(child => text(child)).join('')\n}\n\nexport function htmlAttributes(attributes: Record<string, any>) {\n return Object.entries(attributes)\n .map(([key, value]) => `${key}=\"${value}\"`)\n .join(' ')\n}","import { MinimalElement } from \"@nuxt/content\"\nimport { State } from \"../types\"\nimport { text } from \"../utils\"\n\nexport function code(node: MinimalElement, _: State) {\n return `\\`${text(node)}\\``\n}\n","import { MinimalElement } from \"@nuxt/content\"\nimport { State } from \"../types\"\n\nexport function pre(node: MinimalElement, state: State) {\n const [_, attributes, ...children] = node\n \n const language = (attributes.language || '')\n const filename = attributes.filename ? ' [' + attributes.filename + ']' : ''\n\n const result = '```' + language + filename + (attributes.meta || '') + '\\n'\n + String(node[1]?.code || children.join('')).trim()\n + '\\n```'\n \n return result + state.blockSeparator\n}","import { State } from \"../types\"\nimport { MinimalElement } from \"@nuxt/content\"\n\nexport function hr(_: MinimalElement, state: State) {\n return '---' + state.blockSeparator\n}","import { MinimalElement } from \"@nuxt/content\"\nimport { State } from \"../types\"\n\n// h1, h2, h3, h4, h5, h6\nexport function heading(node: MinimalElement, state: State) {\n const [tag, _, ...children] = node\n\n const level = Number(tag.slice(1))\n \n return '#'.repeat(level) + ' ' + children.join('') + state.context.blockSeparator\n}","import { MinimalElement, MinimalNode } from \"@nuxt/content\"\nimport { State } from \"../types\"\n\nexport function p(node: MinimalElement, state: State) {\n const children = node.slice(2) as MinimalNode[]\n \n return children.map(child => state.one(child, state)).join('') + state.context.blockSeparator\n}","import { State } from \"../types\"\nimport { MinimalElement } from \"@nuxt/content\"\n\n// TODO: support title & attributes\nexport function a(node: MinimalElement, state: State) {\n const [_, attributes] = node\n\n const content = state.flow(node, state)\n\n return `[${content}](${attributes.href})`\n}","import { State } from \"../types\"\nimport { MinimalElement, MinimalNode } from \"@nuxt/content\"\nimport { indent } from \"../utils\"\n\nexport function ul(node: MinimalElement, state: State) {\n const children = node.slice(2) as MinimalNode[]\n\n const revert = state.applyContext({ list: true, order: false })\n\n let result = children.map(child => state.one(child, state)).join('')\n .trim()\n\n if (revert.list) {\n result = '\\n' + indent(result)\n } else {\n result = result + state.context.blockSeparator\n }\n\n state.applyContext(revert)\n\n return result\n}","import { State } from \"../types\"\nimport { MinimalElement, MinimalNode } from \"@nuxt/content\"\nimport { indent } from \"../utils\"\n\nexport function ol(node: MinimalElement, state: State) {\n const children = node.slice(2) as MinimalNode[]\n\n const revert = state.applyContext({ list: true, order: 1 })\n\n let result = children.map(child => state.one(child, state)).join('').trim()\n\n if (revert.list) {\n result = '\\n' + indent(result)\n } else {\n result = result + state.context.blockSeparator\n }\n\n state.applyContext(revert)\n\n return result\n}","import { State } from \"../types\"\nimport { MinimalElement, MinimalNode } from \"@nuxt/content\"\n\nexport function li(node: MinimalElement, state: State) {\n const children = node.slice(2) as MinimalNode[]\n\n const order = state.context.order\n\n const prefix = order ? `${order}. ` : '- '\n const result = children.map(child => state.one(child, state).trimEnd()).join('').trim()\n\n if (order) {\n state.applyContext({ order: order + 1 })\n }\n\n return `${prefix}${result}\\n`\n}","import { MinimalElement } from \"@nuxt/content\"\nimport { State } from \"../types\"\nimport { htmlAttributes, indent } from \"../utils\"\n\nexport function html(node: MinimalElement, state: State) {\n const [tag, attributes, ...children] = node\n\n const inline = children.every(child => typeof child === 'string')\n\n // Do not modify context if we are already in html mode\n const revert = !state.context.html ? state.applyContext({ html: true }) : null\n\n const content = children.map(child => state.one(child, state))\n .join('').trim()\n\n \n // Revert, only if we modified the context\n revert && state.applyContext(revert)\n\n const attrs = Object.keys(attributes).length > 0 \n ? ` ${htmlAttributes(attributes)}` \n : ''\n\n return inline\n ? `<${tag}${attrs}>${content}</${tag}>`\n : `<${tag}${attrs}>\\n${indent(content)}\\n</${tag}>` + state.context.blockSeparator\n}","import { MinimalElement } from \"@nuxt/content\"\nimport { State } from \"../types\"\nimport { text } from \"../utils\"\n\nexport function strong(node: MinimalElement, _: State) {\n return `**${text(node)}**`\n}","import { MinimalElement } from \"@nuxt/content\"\nimport { State } from \"../types\"\nimport { text } from \"../utils\"\n\nexport function emphesis(node: MinimalElement, _: State) {\n return `*${text(node)}*`\n}","import { MinimalElement, MinimalNode } from '@nuxt/content'\nimport { State } from '../types'\n\nexport function blockquote(node: MinimalElement, state: State) {\n const children = node.slice(2) as MinimalNode[]\n\n const content = children.map((child) => state.one(child, state))\n .join('')\n .trim()\n .split('\\n')\n .map((line) => `> ${line}`)\n .join('\\n')\n\n return content + state.context.blockSeparator\n}","import { MinimalElement } from '@nuxt/content'\nimport { State } from '../types'\n\nexport function img(node: MinimalElement, _: State) {\n const [tag, attrs] = node\n\n return ``\n}","import { MinimalElement } from '@nuxt/content'\nimport { State } from '../types'\nimport { text } from '../utils'\n\nexport function del(node: MinimalElement, _: State) {\n return `~~${text(node)}~~`\n}","import { MinimalElement } from \"@nuxt/content\"\nimport { State } from \"../types\"\nimport { htmlAttributes, indent } from \"../utils\"\nimport { html } from \"./html\"\n\nexport function mdc(node: MinimalElement, state: State) {\n const [tag, attributes, ...children] = node\n\n if (tag === 'table') {\n return html(node, state)\n }\n\n const inline = children.every(child => typeof child === 'string')\n const content = children.map(child => state.one(child, state))\n .join('').trim()\n\n\n const attrs = Object.keys(attributes).length > 0 \n ? `{${htmlAttributes(attributes)}}` \n : ''\n\n if (tag === 'span') {\n return `[${content}]${attrs}`\n }\n\n return inline\n ? `:${tag}${content && `[${content}]`}${attrs}`\n : `::${tag}${attrs}\\n${content}\\n::` + state.context.blockSeparator \n}","import { code } from './code'\nimport { pre } from './pre'\nimport { hr } from './hr'\nimport { heading } from './heading'\nimport { p } from './p'\nimport { a } from './a'\nimport { ul } from './ul'\nimport { ol } from './ol'\nimport { li } from './li'\nimport { html } from './html'\nimport { strong } from './strong'\nimport { emphesis } from './emphesis'\nimport { blockquote } from './blockquote'\nimport { img } from './img'\nimport { del } from './del'\nimport { mdc } from './mdc'\n\nexport const handlers = {\n code,\n pre,\n hr,\n h1: heading,\n h2: heading,\n h3: heading,\n h4: heading,\n h5: heading,\n h6: heading,\n p,\n a,\n ul,\n ol,\n li,\n html,\n strong,\n em: emphesis,\n blockquote,\n img,\n del,\n mdc\n}","import { MinimalElement, MinimalNode } from \"@nuxt/content\"\nimport { handlers } from \"./handlers\"\nimport type { State } from \"./types\"\n\nexport function one(node: MinimalNode, state: State) {\n if (typeof node === 'string') {\n return node\n }\n if (state.context.html) {\n return state.handlers.html(node, state)\n }\n\n let nodeHandler = state.context.handlers?.[node[0]] || state.handlers[node[0]]\n if (nodeHandler) {\n return nodeHandler(node, state)\n }\n\n return state.context.format === 'markdown/mdc'\n ? state.handlers.mdc(node, state)\n : state.handlers.html(node, state)\n}\n\nexport function flow(node: MinimalElement, state: State) {\n const [_, attributes, ...children] = node\n\n let result = ''\n for (const child of children) {\n result += one(child, state)\n }\n \n return result\n}\n\nexport function createState(ctx: Record<string, any> = {}): State {\n const context = {\n blockSeparator: '\\n\\n',\n format: 'markdown/mdc',\n handlers: {}, // user defined node handlers\n ...ctx,\n } as Record<string, any>\n \n return {\n handlers,\n context,\n flow,\n one,\n applyContext: (edit: Record<string, any>) => {\n const revert = {} as Record<string, any>\n \n for (const [key, value] of Object.entries(edit)) {\n revert[key] = context[key]\n context[key] = value\n }\n \n return revert\n }\n }\n}\n\n\nexport const state: State = {\n handlers,\n context: {} as Record<string, any>,\n flow,\n one,\n applyContext: (edit: Record<string, any>) => {\n const revert = {} as Record<string, any>\n\n for (const [key, value] of Object.entries(edit)) {\n revert[key] = state.context[key]\n state.context[key] = value\n }\n\n return revert\n }\n}","import { MinimalElement, MinimalTree } from \"@nuxt/content\"\nimport { createState, one, state } from \"./state\"\nimport { StringifyOptions } from \"./types\"\n\nconst defaultOptions: Partial<StringifyOptions> = {\n format: 'markdown/mdc',\n removeLastStyle: true\n}\n\nexport function stringify(node: MinimalTree, options: Partial<StringifyOptions> = {}) {\n options = { ...defaultOptions, ...options }\n\n const _state = createState(options)\n\n const children = node.value\n\n const lastIndex = children.length - 1\n\n return children.map((child, index) => {\n if (index === lastIndex && options.removeLastStyle && child[0] === 'style') {\n return ''\n }\n return one(child, _state)\n }).join('').trim() + '\\n'\n}"],"names":[],"mappings":"AAEM,SAAU,MAAM,CAAC,IAAY,EAAA;IACjC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;AAC7D;AAEM,SAAU,IAAI,CAAC,IAAiB,EAAA;AACpC,IAAA,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;AAC5B,QAAA,OAAO,IAAc;;IAEvB,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC,GAAG,IAAI;AAEzC,IAAA,OAAO,QAAQ,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;AACpD;AAEM,SAAU,cAAc,CAAC,UAA+B,EAAA;AAC5D,IAAA,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU;AAC7B,SAAA,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAG,EAAA,GAAG,CAAK,EAAA,EAAA,KAAK,GAAG;SACzC,IAAI,CAAC,GAAG,CAAC;AACd;;ACfgB,SAAA,IAAI,CAAC,IAAoB,EAAE,CAAQ,EAAA;AACjD,IAAA,OAAO,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI;AAC5B;;ACHgB,SAAA,GAAG,CAAC,IAAoB,EAAE,KAAY,EAAA;IACpD,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC,GAAG,IAAI;IAEzC,MAAM,QAAQ,IAAI,UAAU,CAAC,QAAQ,IAAI,EAAE,CAAC;AAC5C,IAAA,MAAM,QAAQ,GA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C,OAAO,CAAC;AAEnC,IAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK;AAE3B,IAAA,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC;IAErC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,KAAI;AACnC,QAAA,IAAI,KAAK,KAAK,SAAS,IAAI,OAAO,CAAC,eAAe,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE;AAC1E,YAAA,OAAO,EAAE;;AAEX,QAAA,OAAO,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC;KAC1B,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,IAAI;AAC3B;;;;"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
function indent(text) {
|
|
2
|
+
return text.split('\n').map(line => ' ' + line).join('\n');
|
|
3
|
+
}
|
|
4
|
+
function text(node) {
|
|
5
|
+
if (typeof node === 'string') {
|
|
6
|
+
return node;
|
|
7
|
+
}
|
|
8
|
+
const [_, attributes, ...children] = node;
|
|
9
|
+
return children.map(child => text(child)).join('');
|
|
10
|
+
}
|
|
11
|
+
function htmlAttributes(attributes) {
|
|
12
|
+
return Object.entries(attributes)
|
|
13
|
+
.map(([key, value]) => `${key}="${value}"`)
|
|
14
|
+
.join(' ');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function code(node, _) {
|
|
18
|
+
return `\`${text(node)}\``;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function pre(node, state) {
|
|
22
|
+
const [_, attributes, ...children] = node;
|
|
23
|
+
const language = (attributes.language || '');
|
|
24
|
+
const filename = attributes.filename ? ' [' + attributes.filename + ']' : '';
|
|
25
|
+
const result = '```' + language + filename + (attributes.meta || '') + '\n'
|
|
26
|
+
+ String(node[1]?.code || children.join('')).trim()
|
|
27
|
+
+ '\n```';
|
|
28
|
+
return result + state.context.blockSeparator;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function hr(_, state) {
|
|
32
|
+
return '---' + state.context.blockSeparator;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// h1, h2, h3, h4, h5, h6
|
|
36
|
+
function heading(node, state) {
|
|
37
|
+
const [tag, _, ...children] = node;
|
|
38
|
+
const level = Number(tag.slice(1));
|
|
39
|
+
return '#'.repeat(level) + ' ' + children.join('') + state.context.blockSeparator;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function p(node, state) {
|
|
43
|
+
const children = node.slice(2);
|
|
44
|
+
return children.map(child => state.one(child, state)).join('') + state.context.blockSeparator;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// TODO: support title & attributes
|
|
48
|
+
function a(node, state) {
|
|
49
|
+
const [_, attributes] = node;
|
|
50
|
+
const content = state.flow(node, state);
|
|
51
|
+
return `[${content}](${attributes.href})`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function ul(node, state) {
|
|
55
|
+
const children = node.slice(2);
|
|
56
|
+
const revert = state.applyContext({ list: true, order: false });
|
|
57
|
+
let result = children.map(child => state.one(child, state)).join('')
|
|
58
|
+
.trim();
|
|
59
|
+
if (revert.list) {
|
|
60
|
+
result = '\n' + indent(result);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
result = result + state.context.blockSeparator;
|
|
64
|
+
}
|
|
65
|
+
state.applyContext(revert);
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function ol(node, state) {
|
|
70
|
+
const children = node.slice(2);
|
|
71
|
+
const revert = state.applyContext({ list: true, order: 1 });
|
|
72
|
+
let result = children.map(child => state.one(child, state)).join('').trim();
|
|
73
|
+
if (revert.list) {
|
|
74
|
+
result = '\n' + indent(result);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
result = result + state.context.blockSeparator;
|
|
78
|
+
}
|
|
79
|
+
state.applyContext(revert);
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function li(node, state) {
|
|
84
|
+
let children = node.slice(2);
|
|
85
|
+
const order = state.context.order;
|
|
86
|
+
let prefix = order ? `${order}. ` : '- ';
|
|
87
|
+
const className = node[1].className && Array.isArray(node[1].className)
|
|
88
|
+
? node[1].className.join(' ')
|
|
89
|
+
: String(node[1].className);
|
|
90
|
+
const taskList = className.includes('task-list-item');
|
|
91
|
+
if (taskList) {
|
|
92
|
+
const input = children.shift();
|
|
93
|
+
prefix += input[1].checked ? '[x] ' : '[ ] ';
|
|
94
|
+
}
|
|
95
|
+
const result = children.map(child => state.one(child, state).trimEnd()).join('').trim();
|
|
96
|
+
if (order) {
|
|
97
|
+
state.applyContext({ order: order + 1 });
|
|
98
|
+
}
|
|
99
|
+
return `${prefix}${result}\n`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const selfCloseTags = ['br', 'hr', 'img', 'input', 'link', 'meta', 'source', 'track', 'wbr'];
|
|
103
|
+
function html(node, state, parent) {
|
|
104
|
+
const [tag, attributes, ...children] = cleanup(node);
|
|
105
|
+
const inline = parent?.[0] === 'p' && children.every(child => typeof child === 'string');
|
|
106
|
+
// Do not modify context if we are already in html mode
|
|
107
|
+
const revert = !state.context.html ? state.applyContext({ html: true }) : null;
|
|
108
|
+
const content = children.map(child => state.one(child, state, node))
|
|
109
|
+
.join('').trim();
|
|
110
|
+
// Revert, only if we modified the context
|
|
111
|
+
revert && state.applyContext(revert);
|
|
112
|
+
const attrs = Object.keys(attributes).length > 0
|
|
113
|
+
? ` ${htmlAttributes(attributes)}`
|
|
114
|
+
: '';
|
|
115
|
+
if (selfCloseTags.includes(tag)) {
|
|
116
|
+
return `<${tag}${attrs} />` + (inline ? '' : state.context.blockSeparator);
|
|
117
|
+
}
|
|
118
|
+
return inline
|
|
119
|
+
? `<${tag}${attrs}>${content}</${tag}>`
|
|
120
|
+
: `<${tag}${attrs}>\n${indent(content)}\n</${tag}>` + state.context.blockSeparator;
|
|
121
|
+
}
|
|
122
|
+
function cleanup(node) {
|
|
123
|
+
const [tag, attributes, ...children] = node;
|
|
124
|
+
if (tag === 'pre') {
|
|
125
|
+
return [
|
|
126
|
+
tag,
|
|
127
|
+
{
|
|
128
|
+
language: attributes.language,
|
|
129
|
+
},
|
|
130
|
+
attributes.code || text(node)
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
return node;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function strong(node, _) {
|
|
137
|
+
return `**${text(node)}**`;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function emphesis(node, _) {
|
|
141
|
+
return `*${text(node)}*`;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function blockquote(node, state) {
|
|
145
|
+
const children = node.slice(2);
|
|
146
|
+
const content = children.map((child) => state.one(child, state))
|
|
147
|
+
.join('')
|
|
148
|
+
.trim()
|
|
149
|
+
.split('\n')
|
|
150
|
+
.map((line) => `> ${line}`)
|
|
151
|
+
.join('\n');
|
|
152
|
+
return content + state.context.blockSeparator;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function img(node, _) {
|
|
156
|
+
const [tag, attrs] = node;
|
|
157
|
+
return ``;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function del(node, _) {
|
|
161
|
+
return `~~${text(node)}~~`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function mdc(node, state) {
|
|
165
|
+
const [tag, attributes, ...children] = node;
|
|
166
|
+
if (tag === 'table') {
|
|
167
|
+
return html(node, state);
|
|
168
|
+
}
|
|
169
|
+
const inline = children.every(child => typeof child === 'string');
|
|
170
|
+
const content = children.map(child => state.one(child, state))
|
|
171
|
+
.join('').trim();
|
|
172
|
+
const attrs = Object.keys(attributes).length > 0
|
|
173
|
+
? `{${htmlAttributes(attributes)}}`
|
|
174
|
+
: '';
|
|
175
|
+
if (tag === 'span') {
|
|
176
|
+
return `[${content}]${attrs}`;
|
|
177
|
+
}
|
|
178
|
+
return inline
|
|
179
|
+
? `:${tag}${content && `[${content}]`}${attrs}`
|
|
180
|
+
: `::${tag}${attrs}\n${content}\n::` + state.context.blockSeparator;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const handlers = {
|
|
184
|
+
code,
|
|
185
|
+
pre,
|
|
186
|
+
hr,
|
|
187
|
+
h1: heading,
|
|
188
|
+
h2: heading,
|
|
189
|
+
h3: heading,
|
|
190
|
+
h4: heading,
|
|
191
|
+
h5: heading,
|
|
192
|
+
h6: heading,
|
|
193
|
+
p,
|
|
194
|
+
a,
|
|
195
|
+
ul,
|
|
196
|
+
ol,
|
|
197
|
+
li,
|
|
198
|
+
html,
|
|
199
|
+
strong,
|
|
200
|
+
em: emphesis,
|
|
201
|
+
blockquote,
|
|
202
|
+
img,
|
|
203
|
+
del,
|
|
204
|
+
mdc
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
function one(node, state, parent) {
|
|
208
|
+
if (typeof node === 'string') {
|
|
209
|
+
return node;
|
|
210
|
+
}
|
|
211
|
+
if (state.context.html) {
|
|
212
|
+
return state.handlers.html(node, state, parent);
|
|
213
|
+
}
|
|
214
|
+
let nodeHandler = state.context.handlers?.[node[0]] || state.handlers[node[0]];
|
|
215
|
+
if (nodeHandler) {
|
|
216
|
+
return nodeHandler(node, state, parent);
|
|
217
|
+
}
|
|
218
|
+
return state.context.format === 'markdown/mdc'
|
|
219
|
+
? state.handlers.mdc(node, state, parent)
|
|
220
|
+
: state.handlers.html(node, state, parent);
|
|
221
|
+
}
|
|
222
|
+
function flow(node, state, parent) {
|
|
223
|
+
const children = node.slice(2);
|
|
224
|
+
let result = '';
|
|
225
|
+
for (const child of children) {
|
|
226
|
+
result += one(child, state, node);
|
|
227
|
+
}
|
|
228
|
+
return result;
|
|
229
|
+
}
|
|
230
|
+
function createState(ctx = {}) {
|
|
231
|
+
const context = {
|
|
232
|
+
blockSeparator: '\n\n',
|
|
233
|
+
format: 'markdown/mdc',
|
|
234
|
+
handlers: {}, // user defined node handlers
|
|
235
|
+
...ctx,
|
|
236
|
+
// Enable html mode for text/html format
|
|
237
|
+
html: ctx.format === 'text/html'
|
|
238
|
+
};
|
|
239
|
+
return {
|
|
240
|
+
handlers,
|
|
241
|
+
context,
|
|
242
|
+
flow,
|
|
243
|
+
one,
|
|
244
|
+
applyContext: (edit) => {
|
|
245
|
+
const revert = {};
|
|
246
|
+
for (const [key, value] of Object.entries(edit)) {
|
|
247
|
+
revert[key] = context[key];
|
|
248
|
+
context[key] = value;
|
|
249
|
+
}
|
|
250
|
+
return revert;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const defaultOptions = {
|
|
256
|
+
format: 'markdown/mdc',
|
|
257
|
+
removeLastStyle: true
|
|
258
|
+
};
|
|
259
|
+
function stringify(node, options = {}) {
|
|
260
|
+
options = { ...defaultOptions, ...options };
|
|
261
|
+
const _state = createState(options);
|
|
262
|
+
const children = node.value;
|
|
263
|
+
const lastIndex = children.length - 1;
|
|
264
|
+
return children.map((child, index) => {
|
|
265
|
+
if (index === lastIndex && options.removeLastStyle && child[0] === 'style') {
|
|
266
|
+
return '';
|
|
267
|
+
}
|
|
268
|
+
return one(child, _state);
|
|
269
|
+
}).join('').trim() + '\n';
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export { stringify };
|
|
273
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/utils.ts","../../src/handlers/code.ts","../../src/handlers/pre.ts","../../src/handlers/hr.ts","../../src/handlers/heading.ts","../../src/handlers/p.ts","../../src/handlers/a.ts","../../src/handlers/ul.ts","../../src/handlers/ol.ts","../../src/handlers/li.ts","../../src/handlers/html.ts","../../src/handlers/strong.ts","../../src/handlers/emphesis.ts","../../src/handlers/blockquote.ts","../../src/handlers/img.ts","../../src/handlers/del.ts","../../src/handlers/mdc.ts","../../src/handlers/index.ts","../../src/state.ts","../../src/stringify.ts"],"sourcesContent":["import type { MinimarkNode } from \"./types\"\n\nexport function indent(text: string) {\n return text.split('\\n').map(line => ' ' + line).join('\\n')\n}\n\nexport function text(node: MinimarkNode): string {\n if (typeof node === 'string') {\n return node as string\n }\n const [_, attributes, ...children] = node\n\n return children.map(child => text(child)).join('')\n}\n\nexport function htmlAttributes(attributes: Record<string, any>) {\n return Object.entries(attributes)\n .map(([key, value]) => `${key}=\"${value}\"`)\n .join(' ')\n}","import type { State, MinimarkElement } from \"../types\"\nimport { text } from \"../utils\"\n\nexport function code(node: MinimarkElement, _: State) {\n return `\\`${text(node)}\\``\n}\n","import type { State, MinimarkElement } from \"../types\"\n\nexport function pre(node: MinimarkElement, state: State) {\n const [_, attributes, ...children] = node\n \n const language = (attributes.language || '')\n const filename = attributes.filename ? ' [' + attributes.filename + ']' : ''\n\n const result = '```' + language + filename + (attributes.meta || '') + '\\n'\n + String(node[1]?.code || children.join('')).trim()\n + '\\n```'\n \n return result + state.context.blockSeparator\n}","import type { State, MinimarkElement } from \"../types\"\n\nexport function hr(_: MinimarkElement, state: State) {\n return '---' + state.context.blockSeparator\n}","import type { State, MinimarkElement } from \"../types\"\n\n// h1, h2, h3, h4, h5, h6\nexport function heading(node: MinimarkElement, state: State) {\n const [tag, _, ...children] = node\n\n const level = Number(tag.slice(1))\n \n return '#'.repeat(level) + ' ' + children.join('') + state.context.blockSeparator\n}","import type { State, MinimarkElement, MinimarkNode } from \"../types\"\n\nexport function p(node: MinimarkElement, state: State) {\n const children = node.slice(2) as MinimarkNode[]\n \n return children.map(child => state.one(child, state)).join('') + state.context.blockSeparator\n}","import type { State, MinimarkElement } from \"../types\"\n\n// TODO: support title & attributes\nexport function a(node: MinimarkElement, state: State) {\n const [_, attributes] = node\n\n const content = state.flow(node, state)\n\n return `[${content}](${attributes.href})`\n}","import type { State, MinimarkElement, MinimarkNode } from \"../types\"\nimport { indent } from \"../utils\"\n\nexport function ul(node: MinimarkElement, state: State) {\n const children = node.slice(2) as MinimarkNode[]\n\n const revert = state.applyContext({ list: true, order: false })\n\n let result = children.map(child => state.one(child, state)).join('')\n .trim()\n\n if (revert.list) {\n result = '\\n' + indent(result)\n } else {\n result = result + state.context.blockSeparator\n }\n\n state.applyContext(revert)\n\n return result\n}","import type { State, MinimarkElement, MinimarkNode } from \"../types\"\nimport { indent } from \"../utils\"\n\nexport function ol(node: MinimarkElement, state: State) {\n const children = node.slice(2) as MinimarkNode[]\n\n const revert = state.applyContext({ list: true, order: 1 })\n\n let result = children.map(child => state.one(child, state)).join('').trim()\n\n if (revert.list) {\n result = '\\n' + indent(result)\n } else {\n result = result + state.context.blockSeparator\n }\n\n state.applyContext(revert)\n\n return result\n}","import type { State, MinimarkElement, MinimarkNode } from \"../types\"\n\nexport function li(node: MinimarkElement, state: State) {\n let children = node.slice(2) as MinimarkNode[]\n\n const order = state.context.order\n let prefix = order ? `${order}. ` : '- '\n\n const className = (node[1].className as string) && Array.isArray(node[1].className)\n ? node[1].className.join(' ')\n : String(node[1].className)\n\n const taskList = className.includes('task-list-item')\n \n if (taskList) {\n const input = children.shift() as MinimarkElement\n prefix += input[1].checked ? '[x] ' : '[ ] '\n }\n\n const result = children.map(child => state.one(child, state).trimEnd()).join('').trim()\n\n if (order) {\n state.applyContext({ order: order + 1 })\n }\n\n return `${prefix}${result}\\n`\n}","import type { State, MinimarkElement } from \"../types\"\nimport { htmlAttributes, indent, text } from \"../utils\"\n\nconst selfCloseTags = ['br', 'hr', 'img', 'input', 'link', 'meta', 'source', 'track', 'wbr']\n\nexport function html(node: MinimarkElement, state: State, parent?: MinimarkElement) {\n const [tag, attributes, ...children] = cleanup(node)\n\n const inline = parent?.[0] === 'p' && children.every(child => typeof child === 'string')\n const isSelfClose = selfCloseTags.includes(tag as string)\n\n // Do not modify context if we are already in html mode\n const revert = !state.context.html ? state.applyContext({ html: true }) : null\n\n const content = children.map(child => state.one(child, state, node))\n .join('').trim()\n\n // Revert, only if we modified the context\n revert && state.applyContext(revert)\n\n const attrs = Object.keys(attributes).length > 0 \n ? ` ${htmlAttributes(attributes)}` \n : ''\n\n if (selfCloseTags.includes(tag as string)) {\n return `<${tag}${attrs} />` + (inline ? '' : state.context.blockSeparator)\n }\n\n return inline\n ? `<${tag}${attrs}>${content}</${tag}>`\n : `<${tag}${attrs}>\\n${indent(content)}\\n</${tag}>` + state.context.blockSeparator\n}\n\nfunction cleanup(node: MinimarkElement): MinimarkElement {\n const [tag, attributes, ...children] = node\n\n if (tag === 'pre') {\n return [\n tag,\n {\n language: attributes.language,\n },\n attributes.code || text(node)\n ] as unknown as MinimarkElement\n }\n \n\n return node\n}","import type { State, MinimarkElement } from \"../types\"\nimport { text } from \"../utils\"\n\nexport function strong(node: MinimarkElement, _: State) {\n return `**${text(node)}**`\n}","import type { State, MinimarkElement } from \"../types\"\nimport { text } from \"../utils\"\n\nexport function emphesis(node: MinimarkElement, _: State) {\n return `*${text(node)}*`\n}","import type { State, MinimarkElement, MinimarkNode } from '../types'\n\nexport function blockquote(node: MinimarkElement, state: State) {\n const children = node.slice(2) as MinimarkNode[]\n\n const content = children.map((child) => state.one(child, state))\n .join('')\n .trim()\n .split('\\n')\n .map((line) => `> ${line}`)\n .join('\\n')\n\n return content + state.context.blockSeparator\n}","import type { State, MinimarkElement } from '../types'\n\nexport function img(node: MinimarkElement, _: State) {\n const [tag, attrs] = node\n\n return ``\n}","import type { State, MinimarkElement } from '../types'\nimport { text } from '../utils'\n\nexport function del(node: MinimarkElement, _: State) {\n return `~~${text(node)}~~`\n}","import type { State, MinimarkElement } from \"../types\"\nimport { htmlAttributes, indent } from \"../utils\"\nimport { html } from \"./html\"\n\nexport function mdc(node: MinimarkElement, state: State) {\n const [tag, attributes, ...children] = node\n\n if (tag === 'table') {\n return html(node, state)\n }\n\n const inline = children.every(child => typeof child === 'string')\n const content = children.map(child => state.one(child, state))\n .join('').trim()\n\n\n const attrs = Object.keys(attributes).length > 0 \n ? `{${htmlAttributes(attributes)}}` \n : ''\n\n if (tag === 'span') {\n return `[${content}]${attrs}`\n }\n\n return inline\n ? `:${tag}${content && `[${content}]`}${attrs}`\n : `::${tag}${attrs}\\n${content}\\n::` + state.context.blockSeparator \n}","import { code } from './code'\nimport { pre } from './pre'\nimport { hr } from './hr'\nimport { heading } from './heading'\nimport { p } from './p'\nimport { a } from './a'\nimport { ul } from './ul'\nimport { ol } from './ol'\nimport { li } from './li'\nimport { html } from './html'\nimport { strong } from './strong'\nimport { emphesis } from './emphesis'\nimport { blockquote } from './blockquote'\nimport { img } from './img'\nimport { del } from './del'\nimport { mdc } from './mdc'\n\nexport const handlers = {\n code,\n pre,\n hr,\n h1: heading,\n h2: heading,\n h3: heading,\n h4: heading,\n h5: heading,\n h6: heading,\n p,\n a,\n ul,\n ol,\n li,\n html,\n strong,\n em: emphesis,\n blockquote,\n img,\n del,\n mdc\n}","import { handlers } from \"./handlers\"\nimport type { State, MinimarkElement, MinimarkNode } from \"./types\"\n\nexport function one(node: MinimarkNode, state: State, parent?: MinimarkElement) {\n if (typeof node === 'string') {\n return node\n }\n\n if (state.context.html) {\n return state.handlers.html(node, state, parent)\n }\n\n let nodeHandler = state.context.handlers?.[node[0]] || state.handlers[node[0]]\n if (nodeHandler) {\n return nodeHandler(node, state, parent)\n }\n\n return state.context.format === 'markdown/mdc'\n ? state.handlers.mdc(node, state, parent)\n : state.handlers.html(node, state, parent)\n}\n\nexport function flow(node: MinimarkElement, state: State, parent?: MinimarkElement) {\n const children = node.slice(2) as MinimarkElement[]\n\n let result = ''\n for (const child of children) {\n result += one(child, state, node)\n }\n \n return result\n}\n\nexport function createState(ctx: Record<string, any> = {}): State {\n const context = {\n blockSeparator: '\\n\\n',\n format: 'markdown/mdc',\n handlers: {}, // user defined node handlers\n ...ctx,\n // Enable html mode for text/html format\n html: ctx.format === 'text/html'\n } as Record<string, any>\n \n return {\n handlers,\n context,\n flow,\n one,\n applyContext: (edit: Record<string, any>) => {\n const revert = {} as Record<string, any>\n \n for (const [key, value] of Object.entries(edit)) {\n revert[key] = context[key]\n context[key] = value\n }\n \n return revert\n }\n }\n}\n\n\nexport const state: State = {\n handlers,\n context: {\n blockSeparator: '\\n\\n',\n format: 'markdown/mdc',\n handlers: {}, // user defined node handlers\n },\n flow,\n one,\n applyContext: (edit: Record<string, any>) => {\n const revert = {} as Record<string, any>\n\n for (const [key, value] of Object.entries(edit)) {\n revert[key] = state.context[key]\n state.context[key] = value\n }\n\n return revert\n }\n}","import { createState, one } from \"./state\"\nimport { StringifyOptions, MinimarkTree } from \"./types\"\n\nconst defaultOptions: Partial<StringifyOptions> = {\n format: 'markdown/mdc',\n removeLastStyle: true\n}\n\nexport function stringify(node: MinimarkTree, options: Partial<StringifyOptions> = {}) {\n options = { ...defaultOptions, ...options }\n\n const _state = createState(options)\n\n const children = node.value\n\n const lastIndex = children.length - 1\n\n return children.map((child, index) => {\n if (index === lastIndex && options.removeLastStyle && child[0] === 'style') {\n return ''\n }\n return one(child, _state)\n }).join('').trim() + '\\n'\n}"],"names":[],"mappings":"AAEM,SAAU,MAAM,CAAC,IAAY,EAAA;IACjC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;AAC7D;AAEM,SAAU,IAAI,CAAC,IAAkB,EAAA;AACrC,IAAA,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;AAC5B,QAAA,OAAO,IAAc;;IAEvB,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC,GAAG,IAAI;AAEzC,IAAA,OAAO,QAAQ,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;AACpD;AAEM,SAAU,cAAc,CAAC,UAA+B,EAAA;AAC5D,IAAA,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU;AAC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T",
|
|
6
|
+
"description": "MiniMark is a minimal representation of Abstract Syntax Trees (AST)",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "vitest",
|
|
9
|
+
"prepack": "rollup -c",
|
|
10
|
+
"lint": "eslint .",
|
|
11
|
+
"test": "vitest run",
|
|
12
|
+
"test:watch": "vitest watch",
|
|
13
|
+
"test:types": "vue-tsc --noEmit",
|
|
14
|
+
"verify": "npm run lint && npm run test",
|
|
15
|
+
"release": "release-it"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@nuxt/content": "^3.5.1",
|
|
19
|
+
"@nuxt/eslint-config": "^1.4.1",
|
|
20
|
+
"@nuxtjs/mdc": "^0.17.0",
|
|
21
|
+
"@release-it/conventional-changelog": "^10.0.1",
|
|
22
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
23
|
+
"@rollup/plugin-typescript": "^11.1.2",
|
|
24
|
+
"eslint": "^9.27.0",
|
|
25
|
+
"rollup": "^4.0.0",
|
|
26
|
+
"tslib": "^2.8.1",
|
|
27
|
+
"vitest": "^3.1.4"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
32
|
+
"exports": {
|
|
33
|
+
".": "./dist/index.mjs"
|
|
34
|
+
},
|
|
35
|
+
"packageManager": "pnpm@9.15.9+sha512.68046141893c66fad01c079231128e9afb89ef87e2691d69e4d40eee228988295fd4682181bae55b58418c3a253bde65a505ec7c5f9403ece5cc3cd37dcf2531",
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"release-it": "^19.0.2"
|
|
38
|
+
}
|
|
39
|
+
}
|