@thi.ng/hiccup-markdown 2.1.10 → 2.1.13
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/CHANGELOG.md +1 -1
- package/package.json +16 -16
- package/parse.d.ts +1 -1
- package/parse.js +62 -62
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/hiccup-markdown",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.13",
|
|
4
4
|
"description": "Markdown parser & serializer from/to Hiccup format",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -34,24 +34,24 @@
|
|
|
34
34
|
"test": "testament test"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@thi.ng/api": "^8.3.
|
|
38
|
-
"@thi.ng/arrays": "^2.2.
|
|
39
|
-
"@thi.ng/checks": "^3.
|
|
40
|
-
"@thi.ng/defmulti": "^2.1.
|
|
41
|
-
"@thi.ng/errors": "^2.1.
|
|
42
|
-
"@thi.ng/fsm": "^3.1.
|
|
43
|
-
"@thi.ng/hiccup": "^4.2.
|
|
44
|
-
"@thi.ng/strings": "^3.3.
|
|
45
|
-
"@thi.ng/text-canvas": "^2.3.
|
|
46
|
-
"@thi.ng/transducers": "^8.3.
|
|
37
|
+
"@thi.ng/api": "^8.3.7",
|
|
38
|
+
"@thi.ng/arrays": "^2.2.4",
|
|
39
|
+
"@thi.ng/checks": "^3.2.0",
|
|
40
|
+
"@thi.ng/defmulti": "^2.1.7",
|
|
41
|
+
"@thi.ng/errors": "^2.1.7",
|
|
42
|
+
"@thi.ng/fsm": "^3.1.10",
|
|
43
|
+
"@thi.ng/hiccup": "^4.2.8",
|
|
44
|
+
"@thi.ng/strings": "^3.3.5",
|
|
45
|
+
"@thi.ng/text-canvas": "^2.3.4",
|
|
46
|
+
"@thi.ng/transducers": "^8.3.4"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@microsoft/api-extractor": "^7.
|
|
50
|
-
"@thi.ng/testament": "^0.2.
|
|
49
|
+
"@microsoft/api-extractor": "^7.25.0",
|
|
50
|
+
"@thi.ng/testament": "^0.2.8",
|
|
51
51
|
"rimraf": "^3.0.2",
|
|
52
52
|
"tools": "^0.0.1",
|
|
53
|
-
"typedoc": "^0.22.
|
|
54
|
-
"typescript": "^4.
|
|
53
|
+
"typedoc": "^0.22.17",
|
|
54
|
+
"typescript": "^4.7.3"
|
|
55
55
|
},
|
|
56
56
|
"keywords": [
|
|
57
57
|
"ast",
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
"status": "alpha",
|
|
96
96
|
"year": 2018
|
|
97
97
|
},
|
|
98
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "9e516d30a1a537e027a6b3d78bf9121bc5831d31\n"
|
|
99
99
|
}
|
package/parse.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ import type { TagFactories } from "./api.js";
|
|
|
4
4
|
* syntax matchers and state transition handlers. The returned parser
|
|
5
5
|
* itself is only used in `index.ts`.
|
|
6
6
|
*/
|
|
7
|
-
export declare const parse: (_tags?: Partial<TagFactories>
|
|
7
|
+
export declare const parse: (_tags?: Partial<TagFactories>) => import("@thi.ng/transducers").Transducer<string, any[]>;
|
|
8
8
|
//# sourceMappingURL=parse.d.ts.map
|
package/parse.js
CHANGED
|
@@ -94,42 +94,42 @@ const collect = (id) => (ctx, buf) => {
|
|
|
94
94
|
ctx.body += buf.join("");
|
|
95
95
|
return [id];
|
|
96
96
|
};
|
|
97
|
-
const collectHeading = (tag) => (ctx) => [14 /* START */, [tag(ctx.hd, collectChildren(ctx))]];
|
|
98
|
-
const collectAndRestart = (tag) => (ctx) => [14 /* START */, [tag(collectChildren(ctx))]];
|
|
97
|
+
const collectHeading = (tag) => (ctx) => [14 /* State.START */, [tag(ctx.hd, collectChildren(ctx))]];
|
|
98
|
+
const collectAndRestart = (tag) => (ctx) => [14 /* State.START */, [tag(collectChildren(ctx))]];
|
|
99
99
|
const collectBlockQuote = (ctx) => (ctx.children.push(ctx.body, ["br", {}]),
|
|
100
100
|
(ctx.body = ""),
|
|
101
|
-
[0 /* BLOCKQUOTE */]);
|
|
102
|
-
const collectCodeBlock = (tag) => (ctx, body) => [14 /* START */, [tag(ctx.lang, body)]];
|
|
101
|
+
[0 /* State.BLOCKQUOTE */]);
|
|
102
|
+
const collectCodeBlock = (tag) => (ctx, body) => [14 /* State.START */, [tag(ctx.lang, body)]];
|
|
103
103
|
const collectLi = (ctx, tag) => ctx.container.push(tag(collectChildren(ctx)));
|
|
104
104
|
const collectList = (type, list, item) => (ctx) => {
|
|
105
105
|
collectLi(ctx, item);
|
|
106
|
-
return [14 /* START */, [list(type, ctx.container)]];
|
|
106
|
+
return [14 /* State.START */, [list(type, ctx.container)]];
|
|
107
107
|
};
|
|
108
108
|
const collectTD = (tag) => (ctx) => {
|
|
109
109
|
ctx.children.push(ctx.body);
|
|
110
110
|
ctx.container.push(tag(peek(ctx.stack).container.length, ctx.children));
|
|
111
|
-
return transition(ctx, 18 /* TABLE */);
|
|
111
|
+
return transition(ctx, 18 /* State.TABLE */);
|
|
112
112
|
};
|
|
113
113
|
const collectTR = (tag) => (ctx) => {
|
|
114
114
|
const rows = peek(ctx.stack).container;
|
|
115
115
|
rows.push(tag(rows.length, ctx.container));
|
|
116
116
|
ctx.container = [];
|
|
117
|
-
return transition(ctx, 8 /* END_TABLE */);
|
|
117
|
+
return transition(ctx, 8 /* State.END_TABLE */);
|
|
118
118
|
};
|
|
119
119
|
const collectTable = (tag) => (ctx) => {
|
|
120
120
|
const rows = ctx.stack.pop().container;
|
|
121
121
|
rows.splice(1, 1);
|
|
122
|
-
return [14 /* START */, [tag(rows)]];
|
|
122
|
+
return [14 /* State.START */, [tag(rows)]];
|
|
123
123
|
};
|
|
124
124
|
const collectInline = (fn) => pop((ctx, body) => fn(ctx.body + body.trim()));
|
|
125
|
-
const heading = (ctx, body) => ((ctx.hd = body.length), transition(ctx, 9 /* HEADING */));
|
|
125
|
+
const heading = (ctx, body) => ((ctx.hd = body.length), transition(ctx, 9 /* State.HEADING */));
|
|
126
126
|
const matchInline = (id) => [
|
|
127
|
-
str("![", push(id, 10 /* IMG */)),
|
|
128
|
-
str(LINK_LABEL, push(id, 11 /* LINK */)),
|
|
129
|
-
str(STRIKE, push(id, 16 /* STRIKE */)),
|
|
130
|
-
str(STRONG, push(id, 17 /* STRONG */)),
|
|
131
|
-
str(EM, push(id, 3 /* EMPHASIS */)),
|
|
132
|
-
str(CODE, push(id, 1 /* CODE */)),
|
|
127
|
+
str("![", push(id, 10 /* State.IMG */)),
|
|
128
|
+
str(LINK_LABEL, push(id, 11 /* State.LINK */)),
|
|
129
|
+
str(STRIKE, push(id, 16 /* State.STRIKE */)),
|
|
130
|
+
str(STRONG, push(id, 17 /* State.STRONG */)),
|
|
131
|
+
str(EM, push(id, 3 /* State.EMPHASIS */)),
|
|
132
|
+
str(CODE, push(id, 1 /* State.CODE */)),
|
|
133
133
|
];
|
|
134
134
|
const matchLink = (result) => seq([
|
|
135
135
|
untilStr(LINK_LABEL_END, (ctx, body) => ((ctx.title = body), undefined)),
|
|
@@ -140,18 +140,18 @@ const matchPara = (id, next) => alts([
|
|
|
140
140
|
...matchInline(id),
|
|
141
141
|
str(NL, (ctx) => ((ctx.body += " "), [next])),
|
|
142
142
|
], collect(id));
|
|
143
|
-
const newPara = (ctx, buf) => ((ctx.body = buf.join("")), (ctx.children = []), [13 /* PARA */]);
|
|
143
|
+
const newPara = (ctx, buf) => ((ctx.body = buf.join("")), (ctx.children = []), [13 /* State.PARA */]);
|
|
144
144
|
const newParaInline = (next) => (ctx) => {
|
|
145
|
-
ctx.stack.push({ id: 13 /* PARA */, children: [] });
|
|
145
|
+
ctx.stack.push({ id: 13 /* State.PARA */, children: [] });
|
|
146
146
|
return transition(ctx, next);
|
|
147
147
|
};
|
|
148
148
|
const newParaCode = (ctx, x) => ((ctx.body = x[1]),
|
|
149
|
-
ctx.stack.push({ id: 13 /* PARA */, children: [] }),
|
|
150
|
-
[1 /* CODE */]);
|
|
151
|
-
const newList = (ctx) => ((ctx.container = []), transition(ctx, 12 /* LI */));
|
|
152
|
-
const newTable = (ctx) => (ctx.stack.push({ id: 18 /* TABLE */, container: [] }),
|
|
149
|
+
ctx.stack.push({ id: 13 /* State.PARA */, children: [] }),
|
|
150
|
+
[1 /* State.CODE */]);
|
|
151
|
+
const newList = (ctx) => ((ctx.container = []), transition(ctx, 12 /* State.LI */));
|
|
152
|
+
const newTable = (ctx) => (ctx.stack.push({ id: 18 /* State.TABLE */, container: [] }),
|
|
153
153
|
(ctx.container = []),
|
|
154
|
-
transition(ctx, 18 /* TABLE */));
|
|
154
|
+
transition(ctx, 18 /* State.TABLE */));
|
|
155
155
|
/**
|
|
156
156
|
* Main parser / transducer. Defines state map with the various Markdown
|
|
157
157
|
* syntax matchers and state transition handlers. The returned parser
|
|
@@ -160,64 +160,64 @@ const newTable = (ctx) => (ctx.stack.push({ id: 18 /* TABLE */, container: [] })
|
|
|
160
160
|
export const parse = (_tags) => {
|
|
161
161
|
const tags = { ...DEFAULT_TAGS, ..._tags };
|
|
162
162
|
return comp(filter((x) => x !== "\r"), fsm({
|
|
163
|
-
[14 /* START */]: alts([
|
|
164
|
-
whitespace(() => [14 /* START */]),
|
|
163
|
+
[14 /* State.START */]: alts([
|
|
164
|
+
whitespace(() => [14 /* State.START */]),
|
|
165
165
|
repeat(str(HD), 1, Infinity, heading),
|
|
166
|
-
str(BQUOTE, (ctx) => transition(ctx, 0 /* BLOCKQUOTE */)),
|
|
166
|
+
str(BQUOTE, (ctx) => transition(ctx, 0 /* State.BLOCKQUOTE */)),
|
|
167
167
|
str(LI, newList),
|
|
168
168
|
alts([
|
|
169
169
|
seq([str(CODE), not(str(CODE))], newParaCode),
|
|
170
|
-
str(CODEBLOCK, () => [15 /* START_CODEBLOCK */]),
|
|
170
|
+
str(CODEBLOCK, () => [15 /* State.START_CODEBLOCK */]),
|
|
171
171
|
], undefined, (_, next) => next),
|
|
172
172
|
seq([repeat(str(HR), 3, Infinity), str(NL)], () => [
|
|
173
|
-
14 /* START */,
|
|
173
|
+
14 /* State.START */,
|
|
174
174
|
[tags.hr()],
|
|
175
175
|
]),
|
|
176
|
-
str(IMG, newParaInline(10 /* IMG */)),
|
|
177
|
-
str(LINK_LABEL, newParaInline(11 /* LINK */)),
|
|
178
|
-
str(STRONG, newParaInline(17 /* STRONG */)),
|
|
179
|
-
str(STRIKE, newParaInline(16 /* STRIKE */)),
|
|
180
|
-
str(EM, newParaInline(3 /* EMPHASIS */)),
|
|
176
|
+
str(IMG, newParaInline(10 /* State.IMG */)),
|
|
177
|
+
str(LINK_LABEL, newParaInline(11 /* State.LINK */)),
|
|
178
|
+
str(STRONG, newParaInline(17 /* State.STRONG */)),
|
|
179
|
+
str(STRIKE, newParaInline(16 /* State.STRIKE */)),
|
|
180
|
+
str(EM, newParaInline(3 /* State.EMPHASIS */)),
|
|
181
181
|
str(TD, newTable),
|
|
182
182
|
], newPara),
|
|
183
|
-
[13 /* PARA */]: matchPara(13 /* PARA */, 6 /* END_PARA */),
|
|
184
|
-
[6 /* END_PARA */]: alts([
|
|
185
|
-
...matchInline(13 /* PARA */),
|
|
183
|
+
[13 /* State.PARA */]: matchPara(13 /* State.PARA */, 6 /* State.END_PARA */),
|
|
184
|
+
[6 /* State.END_PARA */]: alts([
|
|
185
|
+
...matchInline(13 /* State.PARA */),
|
|
186
186
|
str(NL, collectAndRestart(tags.paragraph)),
|
|
187
|
-
], collect(13 /* PARA */)),
|
|
188
|
-
[0 /* BLOCKQUOTE */]: matchPara(0 /* BLOCKQUOTE */, 4 /* END_BLOCKQUOTE */),
|
|
189
|
-
[4 /* END_BLOCKQUOTE */]: alts([
|
|
190
|
-
...matchInline(0 /* BLOCKQUOTE */),
|
|
187
|
+
], collect(13 /* State.PARA */)),
|
|
188
|
+
[0 /* State.BLOCKQUOTE */]: matchPara(0 /* State.BLOCKQUOTE */, 4 /* State.END_BLOCKQUOTE */),
|
|
189
|
+
[4 /* State.END_BLOCKQUOTE */]: alts([
|
|
190
|
+
...matchInline(0 /* State.BLOCKQUOTE */),
|
|
191
191
|
str(BQUOTE, collectBlockQuote),
|
|
192
192
|
str(NL, collectAndRestart(tags.blockquote)),
|
|
193
|
-
], collect(0 /* BLOCKQUOTE */)),
|
|
194
|
-
[9 /* HEADING */]: matchPara(9 /* HEADING */, 7 /* END_HEADING */),
|
|
195
|
-
[7 /* END_HEADING */]: alts([
|
|
196
|
-
...matchInline(9 /* HEADING */),
|
|
193
|
+
], collect(0 /* State.BLOCKQUOTE */)),
|
|
194
|
+
[9 /* State.HEADING */]: matchPara(9 /* State.HEADING */, 7 /* State.END_HEADING */),
|
|
195
|
+
[7 /* State.END_HEADING */]: alts([
|
|
196
|
+
...matchInline(9 /* State.HEADING */),
|
|
197
197
|
str(NL, collectHeading(tags.heading)),
|
|
198
|
-
], collect(9 /* HEADING */)),
|
|
199
|
-
[15 /* START_CODEBLOCK */]: untilStr(NL, (ctx, lang) => ((ctx.lang = lang), [2 /* CODEBLOCK */])),
|
|
200
|
-
[2 /* CODEBLOCK */]: untilStr(CODEBLOCK_END, collectCodeBlock(tags.codeblock)),
|
|
201
|
-
[12 /* LI */]: matchPara(12 /* LI */, 5 /* END_LI */),
|
|
202
|
-
[5 /* END_LI */]: alts([
|
|
198
|
+
], collect(9 /* State.HEADING */)),
|
|
199
|
+
[15 /* State.START_CODEBLOCK */]: untilStr(NL, (ctx, lang) => ((ctx.lang = lang), [2 /* State.CODEBLOCK */])),
|
|
200
|
+
[2 /* State.CODEBLOCK */]: untilStr(CODEBLOCK_END, collectCodeBlock(tags.codeblock)),
|
|
201
|
+
[12 /* State.LI */]: matchPara(12 /* State.LI */, 5 /* State.END_LI */),
|
|
202
|
+
[5 /* State.END_LI */]: alts([
|
|
203
203
|
str(NL, collectList("ul", tags.list, tags.li)),
|
|
204
204
|
str(LI, (ctx) => (collectLi(ctx, tags.li),
|
|
205
|
-
transition(ctx, 12 /* LI */))),
|
|
206
|
-
], collect(12 /* LI */)),
|
|
207
|
-
[11 /* LINK */]: matchLink(tags.link),
|
|
208
|
-
[10 /* IMG */]: matchLink(tags.img),
|
|
209
|
-
[17 /* STRONG */]: untilStr(STRONG, collectInline(tags.strong)),
|
|
210
|
-
[16 /* STRIKE */]: untilStr(STRIKE, collectInline(tags.strike)),
|
|
211
|
-
[3 /* EMPHASIS */]: untilStr(EM, collectInline(tags.em)),
|
|
212
|
-
[1 /* CODE */]: untilStr(CODE, collectInline(tags.code)),
|
|
213
|
-
[18 /* TABLE */]: alts([
|
|
214
|
-
...matchInline(18 /* TABLE */),
|
|
205
|
+
transition(ctx, 12 /* State.LI */))),
|
|
206
|
+
], collect(12 /* State.LI */)),
|
|
207
|
+
[11 /* State.LINK */]: matchLink(tags.link),
|
|
208
|
+
[10 /* State.IMG */]: matchLink(tags.img),
|
|
209
|
+
[17 /* State.STRONG */]: untilStr(STRONG, collectInline(tags.strong)),
|
|
210
|
+
[16 /* State.STRIKE */]: untilStr(STRIKE, collectInline(tags.strike)),
|
|
211
|
+
[3 /* State.EMPHASIS */]: untilStr(EM, collectInline(tags.em)),
|
|
212
|
+
[1 /* State.CODE */]: untilStr(CODE, collectInline(tags.code)),
|
|
213
|
+
[18 /* State.TABLE */]: alts([
|
|
214
|
+
...matchInline(18 /* State.TABLE */),
|
|
215
215
|
str(TD, collectTD(tags.td)),
|
|
216
216
|
str(NL, collectTR(tags.tr)),
|
|
217
|
-
], collect(18 /* TABLE */)),
|
|
218
|
-
[8 /* END_TABLE */]: alts([
|
|
217
|
+
], collect(18 /* State.TABLE */)),
|
|
218
|
+
[8 /* State.END_TABLE */]: alts([
|
|
219
219
|
str(NL, collectTable(tags.table)),
|
|
220
|
-
str(TD, () => [18 /* TABLE */]),
|
|
220
|
+
str(TD, () => [18 /* State.TABLE */]),
|
|
221
221
|
]),
|
|
222
|
-
}, { stack: [] }, 14 /* START */));
|
|
222
|
+
}, { stack: [] }, 14 /* State.START */));
|
|
223
223
|
};
|