@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,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {
|
|
3
|
+
* Construct,
|
|
4
|
+
* State,
|
|
5
|
+
* TokenizeContext,
|
|
6
|
+
* Tokenizer
|
|
7
|
+
* } from 'micromark-util-types'
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { factorySpaceMinMax } from 'micromark-factory-space';
|
|
11
|
+
import { markdownLineEnding, markdownSpace } from 'micromark-util-character';
|
|
12
|
+
/** @type {Construct} */
|
|
13
|
+
export const codeIndented = {
|
|
14
|
+
name: 'codeIndented',
|
|
15
|
+
tokenize: tokenizeCodeIndented
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** @type {Construct} */
|
|
19
|
+
const furtherStart = {
|
|
20
|
+
partial: true,
|
|
21
|
+
tokenize: tokenizeFurtherStart
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @this {TokenizeContext}
|
|
26
|
+
* Context.
|
|
27
|
+
* @type {Tokenizer}
|
|
28
|
+
*/
|
|
29
|
+
function tokenizeCodeIndented(effects, ok, nok) {
|
|
30
|
+
return start;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Start of code (indented).
|
|
34
|
+
*
|
|
35
|
+
* > **Parsing note**: it is not needed to check if this first line is a
|
|
36
|
+
* > filled line (that it has a non-whitespace character), because blank lines
|
|
37
|
+
* > are parsed already, so we never run into that.
|
|
38
|
+
*
|
|
39
|
+
* ```markdown
|
|
40
|
+
* > | aaa
|
|
41
|
+
* ^
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @type {State}
|
|
45
|
+
*/
|
|
46
|
+
function start(code) {
|
|
47
|
+
// To do: manually check if interrupting like `markdown-rs`.
|
|
48
|
+
|
|
49
|
+
effects.enter("codeIndented");
|
|
50
|
+
return factorySpaceMinMax(effects, atBreak, nok, "linePrefix", 4, 4)(code);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* At a break.
|
|
55
|
+
*
|
|
56
|
+
* ```markdown
|
|
57
|
+
* > | aaa
|
|
58
|
+
* ^ ^
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @type {State}
|
|
62
|
+
*/
|
|
63
|
+
function atBreak(code) {
|
|
64
|
+
if (code === null) {
|
|
65
|
+
return after(code);
|
|
66
|
+
}
|
|
67
|
+
if (markdownLineEnding(code)) {
|
|
68
|
+
return effects.attempt(furtherStart, atBreak, after)(code);
|
|
69
|
+
}
|
|
70
|
+
effects.enter("codeFlowValue");
|
|
71
|
+
return inside(code);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* In code content.
|
|
76
|
+
*
|
|
77
|
+
* ```markdown
|
|
78
|
+
* > | aaa
|
|
79
|
+
* ^^^^
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @type {State}
|
|
83
|
+
*/
|
|
84
|
+
function inside(code) {
|
|
85
|
+
if (code === null || markdownLineEnding(code)) {
|
|
86
|
+
effects.exit("codeFlowValue");
|
|
87
|
+
return atBreak(code);
|
|
88
|
+
}
|
|
89
|
+
effects.consume(code);
|
|
90
|
+
return inside;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** @type {State} */
|
|
94
|
+
function after(code) {
|
|
95
|
+
effects.exit("codeIndented");
|
|
96
|
+
// To do: allow interrupting like `markdown-rs`.
|
|
97
|
+
// Feel free to interrupt.
|
|
98
|
+
// tokenizer.interrupt = false
|
|
99
|
+
return ok(code);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @this {TokenizeContext}
|
|
105
|
+
* Context.
|
|
106
|
+
* @type {Tokenizer}
|
|
107
|
+
*/
|
|
108
|
+
function tokenizeFurtherStart(effects, ok, nok) {
|
|
109
|
+
const self = this;
|
|
110
|
+
return furtherStart;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* At eol, trying to parse another indent.
|
|
114
|
+
*
|
|
115
|
+
* ```markdown
|
|
116
|
+
* > | aaa
|
|
117
|
+
* ^
|
|
118
|
+
* | bbb
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
121
|
+
* @type {State}
|
|
122
|
+
*/
|
|
123
|
+
function furtherStart(code) {
|
|
124
|
+
// To do: improve `lazy` / `pierce` handling.
|
|
125
|
+
// If this is a lazy line, it can’t be code.
|
|
126
|
+
if (self.parser.lazy[self.now().line]) {
|
|
127
|
+
return nok(code);
|
|
128
|
+
}
|
|
129
|
+
if (markdownLineEnding(code)) {
|
|
130
|
+
effects.enter("lineEnding");
|
|
131
|
+
effects.consume(code);
|
|
132
|
+
effects.exit("lineEnding");
|
|
133
|
+
return furtherStart;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// To do: the code here in `micromark-js` is a bit different from
|
|
137
|
+
// `markdown-rs` because there it can attempt spaces.
|
|
138
|
+
// We can’t yet.
|
|
139
|
+
return factorySpaceMinMax(effects, ok, onNotEnoughPrefix, "linePrefix", 4, 4)(code);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* After not enough of a prefix.
|
|
144
|
+
*
|
|
145
|
+
* A following line ending is another (potentially blank) line to try,
|
|
146
|
+
* anything else means this isn’t a continuation.
|
|
147
|
+
*
|
|
148
|
+
* ```markdown
|
|
149
|
+
* > | aaa
|
|
150
|
+
*
|
|
151
|
+
* | bbb
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @type {State}
|
|
155
|
+
*/
|
|
156
|
+
function onNotEnoughPrefix(code) {
|
|
157
|
+
return markdownLineEnding(code) ? furtherStart(code) : nok(code);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {
|
|
3
|
+
* Construct,
|
|
4
|
+
* Previous,
|
|
5
|
+
* Resolver,
|
|
6
|
+
* State,
|
|
7
|
+
* TokenizeContext,
|
|
8
|
+
* Tokenizer,
|
|
9
|
+
* Token
|
|
10
|
+
* } from 'micromark-util-types'
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { markdownLineEnding } from 'micromark-util-character';
|
|
14
|
+
/** @type {Construct} */
|
|
15
|
+
export const codeText = {
|
|
16
|
+
name: 'codeText',
|
|
17
|
+
previous,
|
|
18
|
+
resolve: resolveCodeText,
|
|
19
|
+
tokenize: tokenizeCodeText
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// To do: next major: don’t resolve, like `markdown-rs`.
|
|
23
|
+
/** @type {Resolver} */
|
|
24
|
+
function resolveCodeText(events) {
|
|
25
|
+
let tailExitIndex = events.length - 4;
|
|
26
|
+
let headEnterIndex = 3;
|
|
27
|
+
/** @type {number} */
|
|
28
|
+
let index;
|
|
29
|
+
/** @type {number | undefined} */
|
|
30
|
+
let enter;
|
|
31
|
+
|
|
32
|
+
// If we start and end with an EOL or a space.
|
|
33
|
+
if ((events[headEnterIndex][1].type === "lineEnding" || events[headEnterIndex][1].type === 'space') && (events[tailExitIndex][1].type === "lineEnding" || events[tailExitIndex][1].type === 'space')) {
|
|
34
|
+
index = headEnterIndex;
|
|
35
|
+
|
|
36
|
+
// And we have data.
|
|
37
|
+
while (++index < tailExitIndex) {
|
|
38
|
+
if (events[index][1].type === "codeTextData") {
|
|
39
|
+
// Then we have padding.
|
|
40
|
+
events[headEnterIndex][1].type = "codeTextPadding";
|
|
41
|
+
events[tailExitIndex][1].type = "codeTextPadding";
|
|
42
|
+
headEnterIndex += 2;
|
|
43
|
+
tailExitIndex -= 2;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Merge adjacent spaces and data.
|
|
50
|
+
index = headEnterIndex - 1;
|
|
51
|
+
tailExitIndex++;
|
|
52
|
+
while (++index <= tailExitIndex) {
|
|
53
|
+
if (enter === undefined) {
|
|
54
|
+
if (index !== tailExitIndex && events[index][1].type !== "lineEnding") {
|
|
55
|
+
enter = index;
|
|
56
|
+
}
|
|
57
|
+
} else if (index === tailExitIndex || events[index][1].type === "lineEnding") {
|
|
58
|
+
events[enter][1].type = "codeTextData";
|
|
59
|
+
if (index !== enter + 2) {
|
|
60
|
+
events[enter][1].end = events[index - 1][1].end;
|
|
61
|
+
events.splice(enter + 2, index - enter - 2);
|
|
62
|
+
tailExitIndex -= index - enter - 2;
|
|
63
|
+
index = enter + 2;
|
|
64
|
+
}
|
|
65
|
+
enter = undefined;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return events;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @this {TokenizeContext}
|
|
73
|
+
* Context.
|
|
74
|
+
* @type {Previous}
|
|
75
|
+
*/
|
|
76
|
+
function previous(code) {
|
|
77
|
+
// If there is a previous code, there will always be a tail.
|
|
78
|
+
return code !== 96 || this.events[this.events.length - 1][1].type === "characterEscape";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @this {TokenizeContext}
|
|
83
|
+
* Context.
|
|
84
|
+
* @type {Tokenizer}
|
|
85
|
+
*/
|
|
86
|
+
function tokenizeCodeText(effects, ok, nok) {
|
|
87
|
+
const self = this;
|
|
88
|
+
let sizeOpen = 0;
|
|
89
|
+
/** @type {number} */
|
|
90
|
+
let size;
|
|
91
|
+
/** @type {Token} */
|
|
92
|
+
let token;
|
|
93
|
+
return start;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Start of code (text).
|
|
97
|
+
*
|
|
98
|
+
* ```markdown
|
|
99
|
+
* > | `a`
|
|
100
|
+
* ^
|
|
101
|
+
* > | \`a`
|
|
102
|
+
* ^
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @type {State}
|
|
106
|
+
*/
|
|
107
|
+
function start(code) {
|
|
108
|
+
effects.enter("codeText");
|
|
109
|
+
effects.enter("codeTextSequence");
|
|
110
|
+
return sequenceOpen(code);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* In opening sequence.
|
|
115
|
+
*
|
|
116
|
+
* ```markdown
|
|
117
|
+
* > | `a`
|
|
118
|
+
* ^
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
121
|
+
* @type {State}
|
|
122
|
+
*/
|
|
123
|
+
function sequenceOpen(code) {
|
|
124
|
+
if (code === 96) {
|
|
125
|
+
effects.consume(code);
|
|
126
|
+
sizeOpen++;
|
|
127
|
+
return sequenceOpen;
|
|
128
|
+
}
|
|
129
|
+
effects.exit("codeTextSequence");
|
|
130
|
+
return between(code);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Between something and something else.
|
|
135
|
+
*
|
|
136
|
+
* ```markdown
|
|
137
|
+
* > | `a`
|
|
138
|
+
* ^^
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* @type {State}
|
|
142
|
+
*/
|
|
143
|
+
function between(code) {
|
|
144
|
+
// EOF.
|
|
145
|
+
if (code === null) {
|
|
146
|
+
return nok(code);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// To do: next major: don’t do spaces in resolve, but when compiling,
|
|
150
|
+
// like `markdown-rs`.
|
|
151
|
+
// Tabs don’t work, and virtual spaces don’t make sense.
|
|
152
|
+
if (code === 32) {
|
|
153
|
+
effects.enter('space');
|
|
154
|
+
effects.consume(code);
|
|
155
|
+
effects.exit('space');
|
|
156
|
+
return between;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Closing fence? Could also be data.
|
|
160
|
+
if (code === 96) {
|
|
161
|
+
token = effects.enter("codeTextSequence");
|
|
162
|
+
size = 0;
|
|
163
|
+
return sequenceClose(code);
|
|
164
|
+
}
|
|
165
|
+
if (markdownLineEnding(code)) {
|
|
166
|
+
effects.enter("lineEnding");
|
|
167
|
+
effects.consume(code);
|
|
168
|
+
effects.exit("lineEnding");
|
|
169
|
+
return between;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Data.
|
|
173
|
+
effects.enter("codeTextData");
|
|
174
|
+
return data(code);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* In data.
|
|
179
|
+
*
|
|
180
|
+
* ```markdown
|
|
181
|
+
* > | `a`
|
|
182
|
+
* ^
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* @type {State}
|
|
186
|
+
*/
|
|
187
|
+
function data(code) {
|
|
188
|
+
if (code === null || code === 32 || code === 96 || markdownLineEnding(code)) {
|
|
189
|
+
effects.exit("codeTextData");
|
|
190
|
+
return between(code);
|
|
191
|
+
}
|
|
192
|
+
effects.consume(code);
|
|
193
|
+
return data;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* In closing sequence.
|
|
198
|
+
*
|
|
199
|
+
* ```markdown
|
|
200
|
+
* > | `a`
|
|
201
|
+
* ^
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* @type {State}
|
|
205
|
+
*/
|
|
206
|
+
function sequenceClose(code) {
|
|
207
|
+
// More.
|
|
208
|
+
if (code === 96) {
|
|
209
|
+
effects.consume(code);
|
|
210
|
+
size++;
|
|
211
|
+
return sequenceClose;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Done!
|
|
215
|
+
if (size === sizeOpen) {
|
|
216
|
+
effects.exit("codeTextSequence");
|
|
217
|
+
effects.exit("codeText");
|
|
218
|
+
return ok(code);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// More or less accents: mark as data.
|
|
222
|
+
token.type = "codeTextData";
|
|
223
|
+
return data(code);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {
|
|
3
|
+
* Construct,
|
|
4
|
+
* Resolver,
|
|
5
|
+
* State,
|
|
6
|
+
* TokenizeContext,
|
|
7
|
+
* Tokenizer,
|
|
8
|
+
* Token
|
|
9
|
+
* } from 'micromark-util-types'
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { factorySpace } from 'micromark-factory-space';
|
|
13
|
+
import { markdownLineEnding } from 'micromark-util-character';
|
|
14
|
+
import { subtokenize } from 'micromark-util-subtokenize';
|
|
15
|
+
/**
|
|
16
|
+
* No name because it must not be turned off.
|
|
17
|
+
* @type {Construct}
|
|
18
|
+
*/
|
|
19
|
+
export const content = {
|
|
20
|
+
resolve: resolveContent,
|
|
21
|
+
tokenize: tokenizeContent
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** @type {Construct} */
|
|
25
|
+
const continuationConstruct = {
|
|
26
|
+
partial: true,
|
|
27
|
+
tokenize: tokenizeContinuation
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Content is transparent: it’s parsed right now. That way, definitions are also
|
|
32
|
+
* parsed right now: before text in paragraphs (specifically, media) are parsed.
|
|
33
|
+
*
|
|
34
|
+
* @type {Resolver}
|
|
35
|
+
*/
|
|
36
|
+
function resolveContent(events) {
|
|
37
|
+
subtokenize(events);
|
|
38
|
+
return events;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @this {TokenizeContext}
|
|
43
|
+
* Context.
|
|
44
|
+
* @type {Tokenizer}
|
|
45
|
+
*/
|
|
46
|
+
function tokenizeContent(effects, ok) {
|
|
47
|
+
/** @type {Token | undefined} */
|
|
48
|
+
let previous;
|
|
49
|
+
return chunkStart;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Before a content chunk.
|
|
53
|
+
*
|
|
54
|
+
* ```markdown
|
|
55
|
+
* > | abc
|
|
56
|
+
* ^
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @type {State}
|
|
60
|
+
*/
|
|
61
|
+
function chunkStart(code) {
|
|
62
|
+
effects.enter("content");
|
|
63
|
+
previous = effects.enter("chunkContent", {
|
|
64
|
+
contentType: "content"
|
|
65
|
+
});
|
|
66
|
+
return chunkInside(code);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* In a content chunk.
|
|
71
|
+
*
|
|
72
|
+
* ```markdown
|
|
73
|
+
* > | abc
|
|
74
|
+
* ^^^
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @type {State}
|
|
78
|
+
*/
|
|
79
|
+
function chunkInside(code) {
|
|
80
|
+
if (code === null) {
|
|
81
|
+
return contentEnd(code);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// To do: in `markdown-rs`, each line is parsed on its own, and everything
|
|
85
|
+
// is stitched together resolving.
|
|
86
|
+
if (markdownLineEnding(code)) {
|
|
87
|
+
return effects.check(continuationConstruct, contentContinue, contentEnd)(code);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Data.
|
|
91
|
+
effects.consume(code);
|
|
92
|
+
return chunkInside;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
*
|
|
98
|
+
* @type {State}
|
|
99
|
+
*/
|
|
100
|
+
function contentEnd(code) {
|
|
101
|
+
effects.exit("chunkContent");
|
|
102
|
+
effects.exit("content");
|
|
103
|
+
return ok(code);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
*
|
|
108
|
+
*
|
|
109
|
+
* @type {State}
|
|
110
|
+
*/
|
|
111
|
+
function contentContinue(code) {
|
|
112
|
+
effects.consume(code);
|
|
113
|
+
effects.exit("chunkContent");
|
|
114
|
+
previous.next = effects.enter("chunkContent", {
|
|
115
|
+
contentType: "content",
|
|
116
|
+
previous
|
|
117
|
+
});
|
|
118
|
+
previous = previous.next;
|
|
119
|
+
return chunkInside;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @this {TokenizeContext}
|
|
125
|
+
* Context.
|
|
126
|
+
* @type {Tokenizer}
|
|
127
|
+
*/
|
|
128
|
+
function tokenizeContinuation(effects, ok, nok) {
|
|
129
|
+
const self = this;
|
|
130
|
+
return startLookahead;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
*
|
|
134
|
+
*
|
|
135
|
+
* @type {State}
|
|
136
|
+
*/
|
|
137
|
+
function startLookahead(code) {
|
|
138
|
+
effects.exit("chunkContent");
|
|
139
|
+
effects.enter("lineEnding");
|
|
140
|
+
effects.consume(code);
|
|
141
|
+
effects.exit("lineEnding");
|
|
142
|
+
return factorySpace(effects, prefixed, "linePrefix");
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
*
|
|
147
|
+
*
|
|
148
|
+
* @type {State}
|
|
149
|
+
*/
|
|
150
|
+
function prefixed(code) {
|
|
151
|
+
if (code === null || markdownLineEnding(code)) {
|
|
152
|
+
return nok(code);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Always populated by defaults.
|
|
156
|
+
|
|
157
|
+
const tail = self.events[self.events.length - 1];
|
|
158
|
+
if (!self.parser.constructs.disable.null.includes('codeIndented') && tail && tail[1].type === "linePrefix" && tail[2].sliceSerialize(tail[1], true).length >= 4) {
|
|
159
|
+
return ok(code);
|
|
160
|
+
}
|
|
161
|
+
return effects.interrupt(self.parser.constructs.flow, nok, ok)(code);
|
|
162
|
+
}
|
|
163
|
+
}
|