@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,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {
|
|
3
|
+
* Construct,
|
|
4
|
+
* State,
|
|
5
|
+
* TokenizeContext,
|
|
6
|
+
* Tokenizer
|
|
7
|
+
* } from 'micromark-util-types'
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { factoryDestination } from 'micromark-factory-destination';
|
|
11
|
+
import { factoryLabel } from 'micromark-factory-label';
|
|
12
|
+
import { factorySpace } from 'micromark-factory-space';
|
|
13
|
+
import { factoryTitle } from 'micromark-factory-title';
|
|
14
|
+
import { factoryWhitespace } from 'micromark-factory-whitespace';
|
|
15
|
+
import { markdownLineEndingOrSpace, markdownLineEnding, markdownSpace } from 'micromark-util-character';
|
|
16
|
+
import { normalizeIdentifier } from 'micromark-util-normalize-identifier';
|
|
17
|
+
/** @type {Construct} */
|
|
18
|
+
export const definition = {
|
|
19
|
+
name: 'definition',
|
|
20
|
+
tokenize: tokenizeDefinition
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** @type {Construct} */
|
|
24
|
+
const titleBefore = {
|
|
25
|
+
partial: true,
|
|
26
|
+
tokenize: tokenizeTitleBefore
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @this {TokenizeContext}
|
|
31
|
+
* Context.
|
|
32
|
+
* @type {Tokenizer}
|
|
33
|
+
*/
|
|
34
|
+
function tokenizeDefinition(effects, ok, nok) {
|
|
35
|
+
const self = this;
|
|
36
|
+
/** @type {string} */
|
|
37
|
+
let identifier;
|
|
38
|
+
return start;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* At start of a definition.
|
|
42
|
+
*
|
|
43
|
+
* ```markdown
|
|
44
|
+
* > | [a]: b "c"
|
|
45
|
+
* ^
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @type {State}
|
|
49
|
+
*/
|
|
50
|
+
function start(code) {
|
|
51
|
+
// Do not interrupt paragraphs (but do follow definitions).
|
|
52
|
+
// To do: do `interrupt` the way `markdown-rs` does.
|
|
53
|
+
// To do: parse whitespace the way `markdown-rs` does.
|
|
54
|
+
effects.enter("definition");
|
|
55
|
+
return before(code);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* After optional whitespace, at `[`.
|
|
60
|
+
*
|
|
61
|
+
* ```markdown
|
|
62
|
+
* > | [a]: b "c"
|
|
63
|
+
* ^
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @type {State}
|
|
67
|
+
*/
|
|
68
|
+
function before(code) {
|
|
69
|
+
// To do: parse whitespace the way `markdown-rs` does.
|
|
70
|
+
|
|
71
|
+
return factoryLabel.call(self, effects, labelAfter,
|
|
72
|
+
// Note: we don’t need to reset the way `markdown-rs` does.
|
|
73
|
+
nok, "definitionLabel", "definitionLabelMarker", "definitionLabelString")(code);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* After label.
|
|
78
|
+
*
|
|
79
|
+
* ```markdown
|
|
80
|
+
* > | [a]: b "c"
|
|
81
|
+
* ^
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @type {State}
|
|
85
|
+
*/
|
|
86
|
+
function labelAfter(code) {
|
|
87
|
+
identifier = normalizeIdentifier(self.sliceSerialize(self.events[self.events.length - 1][1]).slice(1, -1));
|
|
88
|
+
if (code === 58) {
|
|
89
|
+
effects.enter("definitionMarker");
|
|
90
|
+
effects.consume(code);
|
|
91
|
+
effects.exit("definitionMarker");
|
|
92
|
+
return markerAfter;
|
|
93
|
+
}
|
|
94
|
+
return nok(code);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* After marker.
|
|
99
|
+
*
|
|
100
|
+
* ```markdown
|
|
101
|
+
* > | [a]: b "c"
|
|
102
|
+
* ^
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @type {State}
|
|
106
|
+
*/
|
|
107
|
+
function markerAfter(code) {
|
|
108
|
+
// Note: whitespace is optional.
|
|
109
|
+
return markdownLineEndingOrSpace(code) ? factoryWhitespace(effects, destinationBefore)(code) : destinationBefore(code);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Before destination.
|
|
114
|
+
*
|
|
115
|
+
* ```markdown
|
|
116
|
+
* > | [a]: b "c"
|
|
117
|
+
* ^
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @type {State}
|
|
121
|
+
*/
|
|
122
|
+
function destinationBefore(code) {
|
|
123
|
+
return factoryDestination(effects, destinationAfter,
|
|
124
|
+
// Note: we don’t need to reset the way `markdown-rs` does.
|
|
125
|
+
nok, "definitionDestination", "definitionDestinationLiteral", "definitionDestinationLiteralMarker", "definitionDestinationRaw", "definitionDestinationString")(code);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* After destination.
|
|
130
|
+
*
|
|
131
|
+
* ```markdown
|
|
132
|
+
* > | [a]: b "c"
|
|
133
|
+
* ^
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @type {State}
|
|
137
|
+
*/
|
|
138
|
+
function destinationAfter(code) {
|
|
139
|
+
return effects.attempt(titleBefore, after, after)(code);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* After definition.
|
|
144
|
+
*
|
|
145
|
+
* ```markdown
|
|
146
|
+
* > | [a]: b
|
|
147
|
+
* ^
|
|
148
|
+
* > | [a]: b "c"
|
|
149
|
+
* ^
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* @type {State}
|
|
153
|
+
*/
|
|
154
|
+
function after(code) {
|
|
155
|
+
return markdownSpace(code) ? factorySpace(effects, afterWhitespace, "whitespace")(code) : afterWhitespace(code);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* After definition, after optional whitespace.
|
|
160
|
+
*
|
|
161
|
+
* ```markdown
|
|
162
|
+
* > | [a]: b
|
|
163
|
+
* ^
|
|
164
|
+
* > | [a]: b "c"
|
|
165
|
+
* ^
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @type {State}
|
|
169
|
+
*/
|
|
170
|
+
function afterWhitespace(code) {
|
|
171
|
+
if (code === null || markdownLineEnding(code)) {
|
|
172
|
+
effects.exit("definition");
|
|
173
|
+
|
|
174
|
+
// Note: we don’t care about uniqueness.
|
|
175
|
+
// It’s likely that that doesn’t happen very frequently.
|
|
176
|
+
// It is more likely that it wastes precious time.
|
|
177
|
+
self.parser.defined.push(identifier);
|
|
178
|
+
|
|
179
|
+
// To do: `markdown-rs` interrupt.
|
|
180
|
+
// // You’d be interrupting.
|
|
181
|
+
// tokenizer.interrupt = true
|
|
182
|
+
return ok(code);
|
|
183
|
+
}
|
|
184
|
+
return nok(code);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @this {TokenizeContext}
|
|
190
|
+
* Context.
|
|
191
|
+
* @type {Tokenizer}
|
|
192
|
+
*/
|
|
193
|
+
function tokenizeTitleBefore(effects, ok, nok) {
|
|
194
|
+
return titleBefore;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* After destination, at whitespace.
|
|
198
|
+
*
|
|
199
|
+
* ```markdown
|
|
200
|
+
* > | [a]: b
|
|
201
|
+
* ^
|
|
202
|
+
* > | [a]: b "c"
|
|
203
|
+
* ^
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* @type {State}
|
|
207
|
+
*/
|
|
208
|
+
function titleBefore(code) {
|
|
209
|
+
return markdownLineEndingOrSpace(code) ? factoryWhitespace(effects, beforeMarker)(code) : nok(code);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* At title.
|
|
214
|
+
*
|
|
215
|
+
* ```markdown
|
|
216
|
+
* | [a]: b
|
|
217
|
+
* > | "c"
|
|
218
|
+
* ^
|
|
219
|
+
* ```
|
|
220
|
+
*
|
|
221
|
+
* @type {State}
|
|
222
|
+
*/
|
|
223
|
+
function beforeMarker(code) {
|
|
224
|
+
return factoryTitle(effects, titleAfter, nok, "definitionTitle", "definitionTitleMarker", "definitionTitleString")(code);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* After title.
|
|
229
|
+
*
|
|
230
|
+
* ```markdown
|
|
231
|
+
* > | [a]: b "c"
|
|
232
|
+
* ^
|
|
233
|
+
* ```
|
|
234
|
+
*
|
|
235
|
+
* @type {State}
|
|
236
|
+
*/
|
|
237
|
+
function titleAfter(code) {
|
|
238
|
+
return markdownSpace(code) ? factorySpace(effects, titleAfterOptionalWhitespace, "whitespace")(code) : titleAfterOptionalWhitespace(code);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* After title, after optional whitespace.
|
|
243
|
+
*
|
|
244
|
+
* ```markdown
|
|
245
|
+
* > | [a]: b "c"
|
|
246
|
+
* ^
|
|
247
|
+
* ```
|
|
248
|
+
*
|
|
249
|
+
* @type {State}
|
|
250
|
+
*/
|
|
251
|
+
function titleAfterOptionalWhitespace(code) {
|
|
252
|
+
return code === null || markdownLineEnding(code) ? ok(code) : nok(code);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {
|
|
3
|
+
* Construct,
|
|
4
|
+
* State,
|
|
5
|
+
* TokenizeContext,
|
|
6
|
+
* Tokenizer
|
|
7
|
+
* } from 'micromark-util-types'
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { markdownLineEnding } from 'micromark-util-character';
|
|
11
|
+
/** @type {Construct} */
|
|
12
|
+
export const hardBreakEscape = {
|
|
13
|
+
name: 'hardBreakEscape',
|
|
14
|
+
tokenize: tokenizeHardBreakEscape
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @this {TokenizeContext}
|
|
19
|
+
* Context.
|
|
20
|
+
* @type {Tokenizer}
|
|
21
|
+
*/
|
|
22
|
+
function tokenizeHardBreakEscape(effects, ok, nok) {
|
|
23
|
+
return start;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Start of a hard break (escape).
|
|
27
|
+
*
|
|
28
|
+
* ```markdown
|
|
29
|
+
* > | a\
|
|
30
|
+
* ^
|
|
31
|
+
* | b
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @type {State}
|
|
35
|
+
*/
|
|
36
|
+
function start(code) {
|
|
37
|
+
effects.enter("hardBreakEscape");
|
|
38
|
+
effects.consume(code);
|
|
39
|
+
return after;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* After `\`, at eol.
|
|
44
|
+
*
|
|
45
|
+
* ```markdown
|
|
46
|
+
* > | a\
|
|
47
|
+
* ^
|
|
48
|
+
* | b
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @type {State}
|
|
52
|
+
*/
|
|
53
|
+
function after(code) {
|
|
54
|
+
if (markdownLineEnding(code)) {
|
|
55
|
+
effects.exit("hardBreakEscape");
|
|
56
|
+
return ok(code);
|
|
57
|
+
}
|
|
58
|
+
return nok(code);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
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 { markdownLineEndingOrSpace, markdownLineEnding, markdownSpace } from 'micromark-util-character';
|
|
14
|
+
import { splice } from 'micromark-util-chunked';
|
|
15
|
+
/** @type {Construct} */
|
|
16
|
+
export const headingAtx = {
|
|
17
|
+
name: 'headingAtx',
|
|
18
|
+
resolve: resolveHeadingAtx,
|
|
19
|
+
tokenize: tokenizeHeadingAtx
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** @type {Resolver} */
|
|
23
|
+
function resolveHeadingAtx(events, context) {
|
|
24
|
+
let contentEnd = events.length - 2;
|
|
25
|
+
let contentStart = 3;
|
|
26
|
+
|
|
27
|
+
// Prefix whitespace, part of the opening.
|
|
28
|
+
if (events[contentStart][1].type === "whitespace") {
|
|
29
|
+
contentStart += 2;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Suffix whitespace, part of the closing.
|
|
33
|
+
if (contentEnd - 2 > contentStart && events[contentEnd][1].type === "whitespace") {
|
|
34
|
+
contentEnd -= 2;
|
|
35
|
+
}
|
|
36
|
+
if (events[contentEnd][1].type === "atxHeadingSequence" && (contentStart === contentEnd - 1 || contentEnd - 4 > contentStart && events[contentEnd - 2][1].type === "whitespace")) {
|
|
37
|
+
contentEnd -= contentStart + 1 === contentEnd ? 2 : 4;
|
|
38
|
+
}
|
|
39
|
+
if (contentEnd > contentStart) {
|
|
40
|
+
const content = {
|
|
41
|
+
type: "atxHeadingText",
|
|
42
|
+
start: events[contentStart][1].start,
|
|
43
|
+
end: events[contentEnd][1].end
|
|
44
|
+
};
|
|
45
|
+
const text = {
|
|
46
|
+
type: "chunkText",
|
|
47
|
+
start: events[contentStart][1].start,
|
|
48
|
+
end: events[contentEnd][1].end,
|
|
49
|
+
contentType: "text"
|
|
50
|
+
};
|
|
51
|
+
splice(events, contentStart, contentEnd - contentStart + 1, [['enter', content, context], ['enter', text, context], ['exit', text, context], ['exit', content, context]]);
|
|
52
|
+
}
|
|
53
|
+
return events;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @this {TokenizeContext}
|
|
58
|
+
* Context.
|
|
59
|
+
* @type {Tokenizer}
|
|
60
|
+
*/
|
|
61
|
+
function tokenizeHeadingAtx(effects, ok, nok) {
|
|
62
|
+
let size = 0;
|
|
63
|
+
return start;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Start of a heading (atx).
|
|
67
|
+
*
|
|
68
|
+
* ```markdown
|
|
69
|
+
* > | ## aa
|
|
70
|
+
* ^
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @type {State}
|
|
74
|
+
*/
|
|
75
|
+
function start(code) {
|
|
76
|
+
// To do: parse indent like `markdown-rs`.
|
|
77
|
+
effects.enter("atxHeading");
|
|
78
|
+
return before(code);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* After optional whitespace, at `#`.
|
|
83
|
+
*
|
|
84
|
+
* ```markdown
|
|
85
|
+
* > | ## aa
|
|
86
|
+
* ^
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @type {State}
|
|
90
|
+
*/
|
|
91
|
+
function before(code) {
|
|
92
|
+
effects.enter("atxHeadingSequence");
|
|
93
|
+
return sequenceOpen(code);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* In opening sequence.
|
|
98
|
+
*
|
|
99
|
+
* ```markdown
|
|
100
|
+
* > | ## aa
|
|
101
|
+
* ^
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @type {State}
|
|
105
|
+
*/
|
|
106
|
+
function sequenceOpen(code) {
|
|
107
|
+
if (code === 35 && size++ < 6) {
|
|
108
|
+
effects.consume(code);
|
|
109
|
+
return sequenceOpen;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Always at least one `#`.
|
|
113
|
+
if (code === null || markdownLineEndingOrSpace(code)) {
|
|
114
|
+
effects.exit("atxHeadingSequence");
|
|
115
|
+
return atBreak(code);
|
|
116
|
+
}
|
|
117
|
+
return nok(code);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* After something, before something else.
|
|
122
|
+
*
|
|
123
|
+
* ```markdown
|
|
124
|
+
* > | ## aa
|
|
125
|
+
* ^
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @type {State}
|
|
129
|
+
*/
|
|
130
|
+
function atBreak(code) {
|
|
131
|
+
if (code === 35) {
|
|
132
|
+
effects.enter("atxHeadingSequence");
|
|
133
|
+
return sequenceFurther(code);
|
|
134
|
+
}
|
|
135
|
+
if (code === null || markdownLineEnding(code)) {
|
|
136
|
+
effects.exit("atxHeading");
|
|
137
|
+
// To do: interrupt like `markdown-rs`.
|
|
138
|
+
// // Feel free to interrupt.
|
|
139
|
+
// tokenizer.interrupt = false
|
|
140
|
+
return ok(code);
|
|
141
|
+
}
|
|
142
|
+
if (markdownSpace(code)) {
|
|
143
|
+
return factorySpace(effects, atBreak, "whitespace")(code);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// To do: generate `data` tokens, add the `text` token later.
|
|
147
|
+
// Needs edit map, see: `markdown.rs`.
|
|
148
|
+
effects.enter("atxHeadingText");
|
|
149
|
+
return data(code);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* In further sequence (after whitespace).
|
|
154
|
+
*
|
|
155
|
+
* Could be normal “visible” hashes in the heading or a final sequence.
|
|
156
|
+
*
|
|
157
|
+
* ```markdown
|
|
158
|
+
* > | ## aa ##
|
|
159
|
+
* ^
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* @type {State}
|
|
163
|
+
*/
|
|
164
|
+
function sequenceFurther(code) {
|
|
165
|
+
if (code === 35) {
|
|
166
|
+
effects.consume(code);
|
|
167
|
+
return sequenceFurther;
|
|
168
|
+
}
|
|
169
|
+
effects.exit("atxHeadingSequence");
|
|
170
|
+
return atBreak(code);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* In text.
|
|
175
|
+
*
|
|
176
|
+
* ```markdown
|
|
177
|
+
* > | ## aa
|
|
178
|
+
* ^
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
181
|
+
* @type {State}
|
|
182
|
+
*/
|
|
183
|
+
function data(code) {
|
|
184
|
+
if (code === null || code === 35 || markdownLineEndingOrSpace(code)) {
|
|
185
|
+
effects.exit("atxHeadingText");
|
|
186
|
+
return atBreak(code);
|
|
187
|
+
}
|
|
188
|
+
effects.consume(code);
|
|
189
|
+
return data;
|
|
190
|
+
}
|
|
191
|
+
}
|