@tinta-lang/syntax 0.0.0-stage → 0.1.0-dev.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/LICENSE +21 -0
- package/THIRD_PARTY_NOTICES.txt +13651 -0
- package/dist/directive.d.ts +40 -0
- package/dist/editing.d.ts +46 -0
- package/dist/enrichment.d.ts +5 -0
- package/dist/expression.d.ts +26 -0
- package/dist/image-destinations.d.ts +3 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +10118 -0
- package/dist/parser.d.ts +40 -0
- package/dist/registry.d.ts +144 -0
- package/dist/source.d.ts +28 -0
- package/package.json +280 -3
- package/parser-provenance.json +1419 -0
- package/patches/README.md +5 -0
- package/patches/micromark.patch +84 -0
- package/vendor/@noble/hashes/LICENSE +21 -0
- package/vendor/@noble/hashes/_md.js +209 -0
- package/vendor/@noble/hashes/_u64.js +77 -0
- package/vendor/@noble/hashes/package.json +91 -0
- package/vendor/@noble/hashes/sha2.js +446 -0
- package/vendor/@noble/hashes/utils.js +687 -0
- package/vendor/character-entities/index.js +2132 -0
- package/vendor/character-entities/license +22 -0
- package/vendor/character-entities/package.json +78 -0
- package/vendor/decode-named-character-reference/index.js +19 -0
- package/vendor/decode-named-character-reference/license +22 -0
- package/vendor/decode-named-character-reference/package.json +90 -0
- package/vendor/devlop/lib/default.js +9 -0
- package/vendor/devlop/license +22 -0
- package/vendor/devlop/package.json +80 -0
- package/vendor/longest-streak/index.js +36 -0
- package/vendor/longest-streak/license +22 -0
- package/vendor/longest-streak/package.json +73 -0
- package/vendor/markdown-table/index.js +393 -0
- package/vendor/markdown-table/license +22 -0
- package/vendor/markdown-table/package.json +77 -0
- package/vendor/mdast-util-from-markdown/index.js +2 -0
- package/vendor/mdast-util-from-markdown/lib/index.js +1270 -0
- package/vendor/mdast-util-from-markdown/license +22 -0
- package/vendor/mdast-util-from-markdown/package.json +98 -0
- package/vendor/mdast-util-gfm-strikethrough/index.js +5 -0
- package/vendor/mdast-util-gfm-strikethrough/lib/index.js +133 -0
- package/vendor/mdast-util-gfm-strikethrough/license +22 -0
- package/vendor/mdast-util-gfm-strikethrough/package.json +84 -0
- package/vendor/mdast-util-gfm-table/index.js +2 -0
- package/vendor/mdast-util-gfm-table/lib/index.js +300 -0
- package/vendor/mdast-util-gfm-table/license +22 -0
- package/vendor/mdast-util-gfm-table/package.json +101 -0
- package/vendor/mdast-util-gfm-task-list-item/index.js +4 -0
- package/vendor/mdast-util-gfm-task-list-item/lib/index.js +141 -0
- package/vendor/mdast-util-gfm-task-list-item/license +22 -0
- package/vendor/mdast-util-gfm-task-list-item/package.json +90 -0
- package/vendor/mdast-util-phrasing/index.js +1 -0
- package/vendor/mdast-util-phrasing/lib/index.js +45 -0
- package/vendor/mdast-util-phrasing/license +23 -0
- package/vendor/mdast-util-phrasing/package.json +78 -0
- package/vendor/mdast-util-to-markdown/index.js +3 -0
- package/vendor/mdast-util-to-markdown/lib/configure.js +98 -0
- package/vendor/mdast-util-to-markdown/lib/handle/blockquote.js +40 -0
- package/vendor/mdast-util-to-markdown/lib/handle/break.js +41 -0
- package/vendor/mdast-util-to-markdown/lib/handle/code.js +86 -0
- package/vendor/mdast-util-to-markdown/lib/handle/definition.js +83 -0
- package/vendor/mdast-util-to-markdown/lib/handle/emphasis.js +67 -0
- package/vendor/mdast-util-to-markdown/lib/handle/heading.js +84 -0
- package/vendor/mdast-util-to-markdown/lib/handle/html.js +27 -0
- package/vendor/mdast-util-to-markdown/lib/handle/image-reference.js +78 -0
- package/vendor/mdast-util-to-markdown/lib/handle/image.js +92 -0
- package/vendor/mdast-util-to-markdown/lib/handle/index.js +45 -0
- package/vendor/mdast-util-to-markdown/lib/handle/inline-code.js +86 -0
- package/vendor/mdast-util-to-markdown/lib/handle/link-reference.js +78 -0
- package/vendor/mdast-util-to-markdown/lib/handle/link.js +129 -0
- package/vendor/mdast-util-to-markdown/lib/handle/list-item.js +73 -0
- package/vendor/mdast-util-to-markdown/lib/handle/list.js +107 -0
- package/vendor/mdast-util-to-markdown/lib/handle/paragraph.js +27 -0
- package/vendor/mdast-util-to-markdown/lib/handle/root.js +34 -0
- package/vendor/mdast-util-to-markdown/lib/handle/strong.js +67 -0
- package/vendor/mdast-util-to-markdown/lib/handle/text.js +30 -0
- package/vendor/mdast-util-to-markdown/lib/handle/thematic-break.js +27 -0
- package/vendor/mdast-util-to-markdown/lib/index.js +213 -0
- package/vendor/mdast-util-to-markdown/lib/join.js +56 -0
- package/vendor/mdast-util-to-markdown/lib/unsafe.js +160 -0
- package/vendor/mdast-util-to-markdown/lib/util/association.js +33 -0
- package/vendor/mdast-util-to-markdown/lib/util/character.js +32 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-bullet-ordered.js +25 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-bullet-other.js +42 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-bullet.js +25 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-emphasis.js +25 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-fence.js +25 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-list-item-indent.js +25 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-quote.js +25 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-rule-repetition.js +25 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-rule.js +25 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-strong.js +25 -0
- package/vendor/mdast-util-to-markdown/lib/util/compile-pattern.js +30 -0
- package/vendor/mdast-util-to-markdown/lib/util/container-flow.js +93 -0
- package/vendor/mdast-util-to-markdown/lib/util/container-phrasing.js +704 -0
- package/vendor/mdast-util-to-markdown/lib/util/encode-character-reference.js +11 -0
- package/vendor/mdast-util-to-markdown/lib/util/encode-info.js +82 -0
- package/vendor/mdast-util-to-markdown/lib/util/format-code-as-indented.js +27 -0
- package/vendor/mdast-util-to-markdown/lib/util/format-heading-as-setext.js +39 -0
- package/vendor/mdast-util-to-markdown/lib/util/format-link-as-autolink.js +39 -0
- package/vendor/mdast-util-to-markdown/lib/util/html-kind.js +63 -0
- package/vendor/mdast-util-to-markdown/lib/util/indent-lines.js +40 -0
- package/vendor/mdast-util-to-markdown/lib/util/pattern-in-scope.js +52 -0
- package/vendor/mdast-util-to-markdown/lib/util/safe.js +263 -0
- package/vendor/mdast-util-to-markdown/lib/util/track.js +55 -0
- package/vendor/mdast-util-to-markdown/license +22 -0
- package/vendor/mdast-util-to-markdown/package.json +88 -0
- package/vendor/mdast-util-to-string/index.js +5 -0
- package/vendor/mdast-util-to-string/lib/index.js +108 -0
- package/vendor/mdast-util-to-string/license +22 -0
- package/vendor/mdast-util-to-string/package.json +78 -0
- package/vendor/micromark/index.js +60 -0
- package/vendor/micromark/lib/compile.js +1068 -0
- package/vendor/micromark/lib/constructs.js +85 -0
- package/vendor/micromark/lib/create-tokenizer.js +615 -0
- package/vendor/micromark/lib/initialize/content.js +79 -0
- package/vendor/micromark/lib/initialize/document.js +370 -0
- package/vendor/micromark/lib/initialize/flow.js +58 -0
- package/vendor/micromark/lib/initialize/text.js +216 -0
- package/vendor/micromark/lib/parse.js +56 -0
- package/vendor/micromark/lib/postprocess.js +18 -0
- package/vendor/micromark/lib/preprocess.js +112 -0
- package/vendor/micromark/license +22 -0
- package/vendor/micromark/package.json +87 -0
- package/vendor/micromark-core-commonmark/index.js +22 -0
- package/vendor/micromark-core-commonmark/lib/attention.js +231 -0
- package/vendor/micromark-core-commonmark/lib/autolink.js +233 -0
- package/vendor/micromark-core-commonmark/lib/blank-line.js +61 -0
- package/vendor/micromark-core-commonmark/lib/block-quote.js +143 -0
- package/vendor/micromark-core-commonmark/lib/character-escape.js +64 -0
- package/vendor/micromark-core-commonmark/lib/character-reference.js +149 -0
- package/vendor/micromark-core-commonmark/lib/code-fenced.js +422 -0
- package/vendor/micromark-core-commonmark/lib/code-indented.js +159 -0
- package/vendor/micromark-core-commonmark/lib/code-text.js +225 -0
- package/vendor/micromark-core-commonmark/lib/content.js +163 -0
- package/vendor/micromark-core-commonmark/lib/definition.js +254 -0
- package/vendor/micromark-core-commonmark/lib/hard-break-escape.js +60 -0
- package/vendor/micromark-core-commonmark/lib/heading-atx.js +191 -0
- package/vendor/micromark-core-commonmark/lib/html-flow.js +827 -0
- package/vendor/micromark-core-commonmark/lib/html-text.js +678 -0
- package/vendor/micromark-core-commonmark/lib/label-end.js +561 -0
- package/vendor/micromark-core-commonmark/lib/label-start-image.js +110 -0
- package/vendor/micromark-core-commonmark/lib/label-start-link.js +63 -0
- package/vendor/micromark-core-commonmark/lib/line-ending.js +33 -0
- package/vendor/micromark-core-commonmark/lib/list.js +213 -0
- package/vendor/micromark-core-commonmark/lib/partial-non-lazy-continuation.js +61 -0
- package/vendor/micromark-core-commonmark/lib/setext-underline.js +187 -0
- package/vendor/micromark-core-commonmark/lib/thematic-break.js +102 -0
- package/vendor/micromark-core-commonmark/license +22 -0
- package/vendor/micromark-core-commonmark/package.json +62 -0
- package/vendor/micromark-extension-gfm-strikethrough/index.js +3 -0
- package/vendor/micromark-extension-gfm-strikethrough/lib/html.js +26 -0
- package/vendor/micromark-extension-gfm-strikethrough/lib/syntax.js +142 -0
- package/vendor/micromark-extension-gfm-strikethrough/license +22 -0
- package/vendor/micromark-extension-gfm-strikethrough/package.json +129 -0
- package/vendor/micromark-extension-gfm-table/index.js +2 -0
- package/vendor/micromark-extension-gfm-table/lib/edit-map.js +222 -0
- package/vendor/micromark-extension-gfm-table/lib/html.js +135 -0
- package/vendor/micromark-extension-gfm-table/lib/infer.js +52 -0
- package/vendor/micromark-extension-gfm-table/lib/syntax.js +846 -0
- package/vendor/micromark-extension-gfm-table/license +22 -0
- package/vendor/micromark-extension-gfm-table/package.json +86 -0
- package/vendor/micromark-extension-gfm-task-list-item/index.js +2 -0
- package/vendor/micromark-extension-gfm-task-list-item/lib/html.js +29 -0
- package/vendor/micromark-extension-gfm-task-list-item/lib/syntax.js +158 -0
- package/vendor/micromark-extension-gfm-task-list-item/license +22 -0
- package/vendor/micromark-extension-gfm-task-list-item/package.json +131 -0
- package/vendor/micromark-factory-destination/index.js +206 -0
- package/vendor/micromark-factory-destination/license +22 -0
- package/vendor/micromark-factory-destination/package.json +57 -0
- package/vendor/micromark-factory-label/index.js +148 -0
- package/vendor/micromark-factory-label/license +22 -0
- package/vendor/micromark-factory-label/package.json +60 -0
- package/vendor/micromark-factory-space/index.js +116 -0
- package/vendor/micromark-factory-space/license +22 -0
- package/vendor/micromark-factory-space/package.json +46 -0
- package/vendor/micromark-factory-title/index.js +158 -0
- package/vendor/micromark-factory-title/license +22 -0
- package/vendor/micromark-factory-title/package.json +58 -0
- package/vendor/micromark-factory-whitespace/index.js +44 -0
- package/vendor/micromark-factory-whitespace/license +22 -0
- package/vendor/micromark-factory-whitespace/package.json +57 -0
- package/vendor/micromark-util-character/index.js +246 -0
- package/vendor/micromark-util-character/license +22 -0
- package/vendor/micromark-util-character/package.json +57 -0
- package/vendor/micromark-util-chunked/index.js +81 -0
- package/vendor/micromark-util-chunked/license +22 -0
- package/vendor/micromark-util-chunked/package.json +57 -0
- package/vendor/micromark-util-classify-character/index.js +27 -0
- package/vendor/micromark-util-classify-character/license +22 -0
- package/vendor/micromark-util-classify-character/package.json +59 -0
- package/vendor/micromark-util-combine-extensions/index.js +143 -0
- package/vendor/micromark-util-combine-extensions/license +22 -0
- package/vendor/micromark-util-combine-extensions/package.json +52 -0
- package/vendor/micromark-util-decode-numeric-character-reference/index.js +32 -0
- package/vendor/micromark-util-decode-numeric-character-reference/license +22 -0
- package/vendor/micromark-util-decode-numeric-character-reference/package.json +59 -0
- package/vendor/micromark-util-decode-string/index.js +45 -0
- package/vendor/micromark-util-decode-string/license +22 -0
- package/vendor/micromark-util-decode-string/package.json +63 -0
- package/vendor/micromark-util-edit-map/index.js +225 -0
- package/vendor/micromark-util-edit-map/license +22 -0
- package/vendor/micromark-util-edit-map/package.json +48 -0
- package/vendor/micromark-util-encode/index.js +33 -0
- package/vendor/micromark-util-encode/license +22 -0
- package/vendor/micromark-util-encode/package.json +47 -0
- package/vendor/micromark-util-html-tag-name/index.js +93 -0
- package/vendor/micromark-util-html-tag-name/license +22 -0
- package/vendor/micromark-util-html-tag-name/package.json +47 -0
- package/vendor/micromark-util-normalize-identifier/index.js +33 -0
- package/vendor/micromark-util-normalize-identifier/license +22 -0
- package/vendor/micromark-util-normalize-identifier/package.json +58 -0
- package/vendor/micromark-util-resolve-all/index.js +32 -0
- package/vendor/micromark-util-resolve-all/license +22 -0
- package/vendor/micromark-util-resolve-all/package.json +48 -0
- package/vendor/micromark-util-sanitize-uri/index.js +107 -0
- package/vendor/micromark-util-sanitize-uri/license +22 -0
- package/vendor/micromark-util-sanitize-uri/package.json +59 -0
- package/vendor/micromark-util-subtokenize/index.js +228 -0
- package/vendor/micromark-util-subtokenize/lib/splice-buffer.js +251 -0
- package/vendor/micromark-util-subtokenize/license +22 -0
- package/vendor/micromark-util-subtokenize/package.json +60 -0
- package/vendor/unist-util-is/index.js +7 -0
- package/vendor/unist-util-is/lib/index.js +296 -0
- package/vendor/unist-util-is/license +22 -0
- package/vendor/unist-util-is/package.json +103 -0
- package/vendor/unist-util-stringify-position/index.js +1 -0
- package/vendor/unist-util-stringify-position/lib/index.js +84 -0
- package/vendor/unist-util-stringify-position/license +22 -0
- package/vendor/unist-util-stringify-position/package.json +80 -0
- package/vendor/unist-util-visit/index.js +2 -0
- package/vendor/unist-util-visit/lib/index.js +312 -0
- package/vendor/unist-util-visit/license +22 -0
- package/vendor/unist-util-visit/package.json +108 -0
- package/vendor/unist-util-visit-parents/index.js +2 -0
- package/vendor/unist-util-visit-parents/lib/color.js +7 -0
- package/vendor/unist-util-visit-parents/lib/index.js +399 -0
- package/vendor/unist-util-visit-parents/license +22 -0
- package/vendor/unist-util-visit-parents/package.json +106 -0
- package/vendor/zwitch/index.js +118 -0
- package/vendor/zwitch/license +22 -0
- package/vendor/zwitch/package.json +72 -0
- package/README.md +0 -3
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {
|
|
3
|
+
* Code,
|
|
4
|
+
* InitialConstruct,
|
|
5
|
+
* Initializer,
|
|
6
|
+
* Resolver,
|
|
7
|
+
* State,
|
|
8
|
+
* TokenizeContext
|
|
9
|
+
* } from 'micromark-util-types'
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { EditMap } from 'micromark-util-edit-map';
|
|
13
|
+
export const resolver = {
|
|
14
|
+
resolveAll: createResolver()
|
|
15
|
+
};
|
|
16
|
+
export const string = initializeFactory('string');
|
|
17
|
+
export const text = initializeFactory('text');
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {'string' | 'text'} field
|
|
21
|
+
* Field.
|
|
22
|
+
* @returns {InitialConstruct}
|
|
23
|
+
* Construct.
|
|
24
|
+
*/
|
|
25
|
+
function initializeFactory(field) {
|
|
26
|
+
return {
|
|
27
|
+
resolveAll: createResolver(field === 'text' ? resolveAllLineSuffixes : undefined),
|
|
28
|
+
tokenize: initializeText
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @this {TokenizeContext}
|
|
33
|
+
* Context.
|
|
34
|
+
* @type {Initializer}
|
|
35
|
+
*/
|
|
36
|
+
function initializeText(effects) {
|
|
37
|
+
const self = this;
|
|
38
|
+
const constructs = this.parser.constructs[field];
|
|
39
|
+
const text = effects.attempt(constructs, start, notText);
|
|
40
|
+
return start;
|
|
41
|
+
|
|
42
|
+
/** @type {State} */
|
|
43
|
+
function start(code) {
|
|
44
|
+
return atBreak(code) ? text(code) : notText(code);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** @type {State} */
|
|
48
|
+
function notText(code) {
|
|
49
|
+
if (code === null) {
|
|
50
|
+
effects.consume(code);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
effects.enter("data");
|
|
54
|
+
effects.consume(code);
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** @type {State} */
|
|
59
|
+
function data(code) {
|
|
60
|
+
if (atBreak(code)) {
|
|
61
|
+
effects.exit("data");
|
|
62
|
+
return text(code);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Data.
|
|
66
|
+
effects.consume(code);
|
|
67
|
+
return data;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {Code} code
|
|
72
|
+
* Code.
|
|
73
|
+
* @returns {boolean}
|
|
74
|
+
* Whether the code is a break.
|
|
75
|
+
*/
|
|
76
|
+
function atBreak(code) {
|
|
77
|
+
if (code === null) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
const list = constructs[code];
|
|
81
|
+
let index = -1;
|
|
82
|
+
if (list) {
|
|
83
|
+
// Always populated by defaults.
|
|
84
|
+
|
|
85
|
+
while (++index < list.length) {
|
|
86
|
+
const item = list[index];
|
|
87
|
+
if (!item.previous || item.previous.call(self, self.previous)) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @param {Resolver | undefined} [extraResolver]
|
|
99
|
+
* Resolver.
|
|
100
|
+
* @returns {Resolver}
|
|
101
|
+
* Resolver.
|
|
102
|
+
*/
|
|
103
|
+
function createResolver(extraResolver) {
|
|
104
|
+
return resolveAllText;
|
|
105
|
+
|
|
106
|
+
/** @type {Resolver} */
|
|
107
|
+
function resolveAllText(events, context) {
|
|
108
|
+
let index = -1;
|
|
109
|
+
/** @type {number | undefined} */
|
|
110
|
+
let enter;
|
|
111
|
+
|
|
112
|
+
// A rather boring computation (to merge adjacent `data` events) which
|
|
113
|
+
// improves mm performance by 29%.
|
|
114
|
+
while (++index <= events.length) {
|
|
115
|
+
if (enter === undefined) {
|
|
116
|
+
if (events[index] && events[index][1].type === "data") {
|
|
117
|
+
enter = index;
|
|
118
|
+
index++;
|
|
119
|
+
}
|
|
120
|
+
} else if (!events[index] || events[index][1].type !== "data") {
|
|
121
|
+
// Don’t do anything if there is one data token.
|
|
122
|
+
if (index !== enter + 2) {
|
|
123
|
+
events[enter][1].end = events[index - 1][1].end;
|
|
124
|
+
events.splice(enter + 2, index - enter - 2);
|
|
125
|
+
index = enter + 2;
|
|
126
|
+
}
|
|
127
|
+
enter = undefined;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return extraResolver ? extraResolver(events, context) : events;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* A rather ugly set of instructions which again looks at chunks in the input
|
|
136
|
+
* stream.
|
|
137
|
+
* The reason to do this here is that it is *much* faster to parse in reverse.
|
|
138
|
+
* And that we can’t hook into `null` to split the line suffix before an EOF.
|
|
139
|
+
* To do: figure out if we can make this into a clean utility, or even in core.
|
|
140
|
+
* As it will be useful for GFMs literal autolink extension (and maybe even
|
|
141
|
+
* tables?)
|
|
142
|
+
*
|
|
143
|
+
* @type {Resolver}
|
|
144
|
+
*/
|
|
145
|
+
function resolveAllLineSuffixes(events, context) {
|
|
146
|
+
const editMap = new EditMap();
|
|
147
|
+
let eventIndex = 0; // Skip first.
|
|
148
|
+
|
|
149
|
+
while (++eventIndex <= events.length) {
|
|
150
|
+
if ((eventIndex === events.length || events[eventIndex][1].type === "lineEnding") && events[eventIndex - 1][1].type === "data") {
|
|
151
|
+
const data = events[eventIndex - 1][1];
|
|
152
|
+
const chunks = context.sliceStream(data);
|
|
153
|
+
let index = chunks.length;
|
|
154
|
+
let bufferIndex = -1;
|
|
155
|
+
let size = 0;
|
|
156
|
+
/** @type {boolean | undefined} */
|
|
157
|
+
let tabs;
|
|
158
|
+
while (index--) {
|
|
159
|
+
const chunk = chunks[index];
|
|
160
|
+
if (typeof chunk === 'string') {
|
|
161
|
+
bufferIndex = chunk.length;
|
|
162
|
+
while (chunk.charCodeAt(bufferIndex - 1) === 32) {
|
|
163
|
+
size++;
|
|
164
|
+
bufferIndex--;
|
|
165
|
+
}
|
|
166
|
+
if (bufferIndex) {
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
bufferIndex = -1;
|
|
170
|
+
}
|
|
171
|
+
// Number
|
|
172
|
+
else if (chunk === -2) {
|
|
173
|
+
tabs = true;
|
|
174
|
+
size++;
|
|
175
|
+
} else if (chunk === -1) {
|
|
176
|
+
// Empty
|
|
177
|
+
} else {
|
|
178
|
+
// Replacement character, exit.
|
|
179
|
+
index++;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Allow final trailing whitespace.
|
|
185
|
+
if (context._contentTypeTextTrailing && eventIndex === events.length) {
|
|
186
|
+
size = 0;
|
|
187
|
+
}
|
|
188
|
+
if (size) {
|
|
189
|
+
const token = {
|
|
190
|
+
type: eventIndex === events.length || tabs || size < 2 ? "lineSuffix" : "hardBreakTrailing",
|
|
191
|
+
start: {
|
|
192
|
+
_bufferIndex: index ? bufferIndex : data.start._bufferIndex + bufferIndex,
|
|
193
|
+
_index: data.start._index + index,
|
|
194
|
+
line: data.end.line,
|
|
195
|
+
column: data.end.column - size,
|
|
196
|
+
offset: data.end.offset - size
|
|
197
|
+
},
|
|
198
|
+
end: {
|
|
199
|
+
...data.end
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
data.end = {
|
|
203
|
+
...token.start
|
|
204
|
+
};
|
|
205
|
+
if (data.start.offset === data.end.offset) {
|
|
206
|
+
Object.assign(data, token);
|
|
207
|
+
} else {
|
|
208
|
+
editMap.add(eventIndex, 0, [['enter', token, context], ['exit', token, context]]);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
eventIndex++;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
editMap.consume(events);
|
|
215
|
+
return events;
|
|
216
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {
|
|
3
|
+
* Create,
|
|
4
|
+
* FullNormalizedExtension,
|
|
5
|
+
* InitialConstruct,
|
|
6
|
+
* ParseContext,
|
|
7
|
+
* ParseOptions
|
|
8
|
+
* } from 'micromark-util-types'
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { combineExtensions } from 'micromark-util-combine-extensions';
|
|
12
|
+
import { content } from './initialize/content.js';
|
|
13
|
+
import { document } from './initialize/document.js';
|
|
14
|
+
import { flow } from './initialize/flow.js';
|
|
15
|
+
import { string, text } from './initialize/text.js';
|
|
16
|
+
import * as defaultConstructs from './constructs.js';
|
|
17
|
+
import { createTokenizer } from './create-tokenizer.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {ParseOptions | null | undefined} [options]
|
|
21
|
+
* Configuration (optional).
|
|
22
|
+
* @returns {ParseContext}
|
|
23
|
+
* Parser.
|
|
24
|
+
*/
|
|
25
|
+
export function parse(options) {
|
|
26
|
+
const settings = options || {};
|
|
27
|
+
const constructs = /** @type {FullNormalizedExtension} */
|
|
28
|
+
combineExtensions([defaultConstructs, ...(settings.extensions || [])]);
|
|
29
|
+
|
|
30
|
+
/** @type {ParseContext} */
|
|
31
|
+
const parser = {
|
|
32
|
+
constructs,
|
|
33
|
+
content: create(content),
|
|
34
|
+
defined: [],
|
|
35
|
+
document: create(document),
|
|
36
|
+
flow: create(flow),
|
|
37
|
+
lazy: {},
|
|
38
|
+
string: create(string),
|
|
39
|
+
text: create(text)
|
|
40
|
+
};
|
|
41
|
+
return parser;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {InitialConstruct} initial
|
|
45
|
+
* Construct to start with.
|
|
46
|
+
* @returns {Create}
|
|
47
|
+
* Create a tokenizer.
|
|
48
|
+
*/
|
|
49
|
+
function create(initial) {
|
|
50
|
+
return creator;
|
|
51
|
+
/** @type {Create} */
|
|
52
|
+
function creator(from) {
|
|
53
|
+
return createTokenizer(parser, initial, from, settings.observeTokenizer);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {Event} from 'micromark-util-types'
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { subtokenize } from 'micromark-util-subtokenize';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {Array<Event>} events
|
|
9
|
+
* Events.
|
|
10
|
+
* @returns {Array<Event>}
|
|
11
|
+
* Events.
|
|
12
|
+
*/
|
|
13
|
+
export function postprocess(events) {
|
|
14
|
+
while (!subtokenize(events)) {
|
|
15
|
+
// Empty
|
|
16
|
+
}
|
|
17
|
+
return events;
|
|
18
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {Chunk, Code, Encoding, Value} from 'micromark-util-types'
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @callback Preprocessor
|
|
7
|
+
* Preprocess a value.
|
|
8
|
+
* @param {Value} value
|
|
9
|
+
* Value.
|
|
10
|
+
* @param {Encoding | null | undefined} [encoding]
|
|
11
|
+
* Encoding when `value` is a typed array (optional).
|
|
12
|
+
* @param {boolean | null | undefined} [end=false]
|
|
13
|
+
* Whether this is the last chunk (default: `false`).
|
|
14
|
+
* @returns {Array<Chunk>}
|
|
15
|
+
* Chunks.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const search = /[\0\t\n\r]/g;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @returns {Preprocessor}
|
|
22
|
+
* Preprocess a value.
|
|
23
|
+
*/
|
|
24
|
+
export function preprocess() {
|
|
25
|
+
let column = 1;
|
|
26
|
+
let buffer = '';
|
|
27
|
+
/** @type {boolean | undefined} */
|
|
28
|
+
let start = true;
|
|
29
|
+
/** @type {boolean | undefined} */
|
|
30
|
+
let atCarriageReturn;
|
|
31
|
+
return preprocessor;
|
|
32
|
+
|
|
33
|
+
/** @type {Preprocessor} */
|
|
34
|
+
// eslint-disable-next-line complexity
|
|
35
|
+
function preprocessor(value, encoding, end) {
|
|
36
|
+
value = buffer + (typeof value === 'string' ? value.toString() : new TextDecoder(encoding || undefined).decode(value));
|
|
37
|
+
|
|
38
|
+
/** @type {Array<Chunk>} */
|
|
39
|
+
const chunks = [];
|
|
40
|
+
let startPosition = 0;
|
|
41
|
+
buffer = '';
|
|
42
|
+
if (start) {
|
|
43
|
+
// To do: `markdown-rs` actually parses BOMs (byte order mark).
|
|
44
|
+
if (value.charCodeAt(0) === 65279) {
|
|
45
|
+
startPosition++;
|
|
46
|
+
}
|
|
47
|
+
start = undefined;
|
|
48
|
+
}
|
|
49
|
+
while (startPosition < value.length) {
|
|
50
|
+
search.lastIndex = startPosition;
|
|
51
|
+
const match = search.exec(value);
|
|
52
|
+
const endPosition = match && match.index !== undefined ? match.index : value.length;
|
|
53
|
+
const code = value.charCodeAt(endPosition);
|
|
54
|
+
if (!match) {
|
|
55
|
+
buffer = value.slice(startPosition);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
if (code === 10 && startPosition === endPosition && atCarriageReturn) {
|
|
59
|
+
chunks.push(-3);
|
|
60
|
+
atCarriageReturn = undefined;
|
|
61
|
+
} else {
|
|
62
|
+
if (atCarriageReturn) {
|
|
63
|
+
chunks.push(-5);
|
|
64
|
+
atCarriageReturn = undefined;
|
|
65
|
+
}
|
|
66
|
+
if (startPosition < endPosition) {
|
|
67
|
+
chunks.push(value.slice(startPosition, endPosition));
|
|
68
|
+
column += endPosition - startPosition;
|
|
69
|
+
}
|
|
70
|
+
switch (code) {
|
|
71
|
+
case 0:
|
|
72
|
+
{
|
|
73
|
+
chunks.push(65533);
|
|
74
|
+
column++;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
case 9:
|
|
78
|
+
{
|
|
79
|
+
const next = Math.ceil(column / 4) * 4;
|
|
80
|
+
chunks.push(-2);
|
|
81
|
+
while (column++ < next) {
|
|
82
|
+
chunks.push(-1);
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case 10:
|
|
87
|
+
{
|
|
88
|
+
chunks.push(-4);
|
|
89
|
+
column = 1;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
default:
|
|
93
|
+
{
|
|
94
|
+
atCarriageReturn = true;
|
|
95
|
+
column = 1;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
startPosition = endPosition + 1;
|
|
100
|
+
}
|
|
101
|
+
if (end) {
|
|
102
|
+
if (atCarriageReturn) {
|
|
103
|
+
chunks.push(-5);
|
|
104
|
+
}
|
|
105
|
+
if (buffer) {
|
|
106
|
+
chunks.push(buffer);
|
|
107
|
+
}
|
|
108
|
+
chunks.push(null);
|
|
109
|
+
}
|
|
110
|
+
return chunks;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
(The MIT License)
|
|
2
|
+
|
|
3
|
+
Copyright (c) Titus Wormer <tituswormer@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "micromark",
|
|
3
|
+
"version": "4.0.3",
|
|
4
|
+
"description": "small commonmark compliant markdown parser with positional info and concrete tokens",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"commonmark",
|
|
8
|
+
"compiler",
|
|
9
|
+
"gfm",
|
|
10
|
+
"html",
|
|
11
|
+
"lexer",
|
|
12
|
+
"markdown",
|
|
13
|
+
"markup",
|
|
14
|
+
"md",
|
|
15
|
+
"unified",
|
|
16
|
+
"parse",
|
|
17
|
+
"parser",
|
|
18
|
+
"plugin",
|
|
19
|
+
"process",
|
|
20
|
+
"remark",
|
|
21
|
+
"render",
|
|
22
|
+
"renderer",
|
|
23
|
+
"token",
|
|
24
|
+
"tokenizer"
|
|
25
|
+
],
|
|
26
|
+
"repository": "https://github.com/micromark/micromark/tree/main/packages/micromark",
|
|
27
|
+
"bugs": "https://github.com/micromark/micromark/issues",
|
|
28
|
+
"funding": [
|
|
29
|
+
{
|
|
30
|
+
"type": "GitHub Sponsors",
|
|
31
|
+
"url": "https://github.com/sponsors/unifiedjs"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"type": "OpenCollective",
|
|
35
|
+
"url": "https://opencollective.com/unified"
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
|
39
|
+
"contributors": [
|
|
40
|
+
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
|
|
41
|
+
],
|
|
42
|
+
"sideEffects": false,
|
|
43
|
+
"type": "module",
|
|
44
|
+
"files": [
|
|
45
|
+
"dev/",
|
|
46
|
+
"lib/",
|
|
47
|
+
"index.d.ts.map",
|
|
48
|
+
"index.d.ts",
|
|
49
|
+
"index.js",
|
|
50
|
+
"stream.d.ts.map",
|
|
51
|
+
"stream.d.ts",
|
|
52
|
+
"stream.js"
|
|
53
|
+
],
|
|
54
|
+
"exports": {
|
|
55
|
+
".": {
|
|
56
|
+
"development": "./dev/index.js",
|
|
57
|
+
"default": "./index.js"
|
|
58
|
+
},
|
|
59
|
+
"./stream": {
|
|
60
|
+
"development": "./dev/stream.js",
|
|
61
|
+
"default": "./stream.js"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"@types/debug": "^4.0.0",
|
|
66
|
+
"debug": "^4.0.0",
|
|
67
|
+
"decode-named-character-reference": "^1.0.0",
|
|
68
|
+
"devlop": "^1.0.0",
|
|
69
|
+
"micromark-core-commonmark": "^2.0.0",
|
|
70
|
+
"micromark-factory-space": "^2.0.0",
|
|
71
|
+
"micromark-util-character": "^2.0.0",
|
|
72
|
+
"micromark-util-chunked": "^2.0.0",
|
|
73
|
+
"micromark-util-combine-extensions": "^2.0.0",
|
|
74
|
+
"micromark-util-decode-numeric-character-reference": "^2.0.0",
|
|
75
|
+
"micromark-util-edit-map": "^1.0.0",
|
|
76
|
+
"micromark-util-encode": "^2.0.0",
|
|
77
|
+
"micromark-util-normalize-identifier": "^2.0.0",
|
|
78
|
+
"micromark-util-resolve-all": "^2.0.0",
|
|
79
|
+
"micromark-util-sanitize-uri": "^2.0.0",
|
|
80
|
+
"micromark-util-subtokenize": "^2.0.0",
|
|
81
|
+
"micromark-util-symbol": "^2.0.0",
|
|
82
|
+
"micromark-util-types": "^2.0.0"
|
|
83
|
+
},
|
|
84
|
+
"scripts": {
|
|
85
|
+
"build": "micromark-build"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { attention } from './lib/attention.js';
|
|
2
|
+
export { autolink } from './lib/autolink.js';
|
|
3
|
+
export { blankLine } from './lib/blank-line.js';
|
|
4
|
+
export { blockQuote } from './lib/block-quote.js';
|
|
5
|
+
export { characterEscape } from './lib/character-escape.js';
|
|
6
|
+
export { characterReference } from './lib/character-reference.js';
|
|
7
|
+
export { codeFenced } from './lib/code-fenced.js';
|
|
8
|
+
export { codeIndented } from './lib/code-indented.js';
|
|
9
|
+
export { codeText } from './lib/code-text.js';
|
|
10
|
+
export { content } from './lib/content.js';
|
|
11
|
+
export { definition } from './lib/definition.js';
|
|
12
|
+
export { hardBreakEscape } from './lib/hard-break-escape.js';
|
|
13
|
+
export { headingAtx } from './lib/heading-atx.js';
|
|
14
|
+
export { htmlFlow } from './lib/html-flow.js';
|
|
15
|
+
export { htmlText } from './lib/html-text.js';
|
|
16
|
+
export { labelEnd } from './lib/label-end.js';
|
|
17
|
+
export { labelStartImage } from './lib/label-start-image.js';
|
|
18
|
+
export { labelStartLink } from './lib/label-start-link.js';
|
|
19
|
+
export { lineEnding } from './lib/line-ending.js';
|
|
20
|
+
export { list } from './lib/list.js';
|
|
21
|
+
export { setextUnderline } from './lib/setext-underline.js';
|
|
22
|
+
export { thematicBreak } from './lib/thematic-break.js';
|