@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,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {
|
|
3
|
+
* Code,
|
|
4
|
+
* Construct,
|
|
5
|
+
* Event,
|
|
6
|
+
* Point,
|
|
7
|
+
* Resolver,
|
|
8
|
+
* State,
|
|
9
|
+
* TokenizeContext,
|
|
10
|
+
* Tokenizer,
|
|
11
|
+
* Token
|
|
12
|
+
* } from 'micromark-util-types'
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { push, splice } from 'micromark-util-chunked';
|
|
16
|
+
import { classifyCharacter } from 'micromark-util-classify-character';
|
|
17
|
+
import { resolveAll } from 'micromark-util-resolve-all';
|
|
18
|
+
/** @type {Construct} */
|
|
19
|
+
export const attention = {
|
|
20
|
+
name: 'attention',
|
|
21
|
+
resolveAll: resolveAllAttention,
|
|
22
|
+
tokenize: tokenizeAttention
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Take all events and resolve attention to emphasis or strong.
|
|
27
|
+
*
|
|
28
|
+
* @type {Resolver}
|
|
29
|
+
*/
|
|
30
|
+
// eslint-disable-next-line complexity
|
|
31
|
+
function resolveAllAttention(events, context) {
|
|
32
|
+
let index = -1;
|
|
33
|
+
/** @type {Array<Event>} */
|
|
34
|
+
let nextEvents;
|
|
35
|
+
|
|
36
|
+
// Walk through all events.
|
|
37
|
+
//
|
|
38
|
+
// Note: performance of this is fine on an mb of normal markdown, but it’s
|
|
39
|
+
// a bottleneck for malicious stuff.
|
|
40
|
+
while (++index < events.length) {
|
|
41
|
+
// Find a token that can close.
|
|
42
|
+
if (events[index][0] === 'enter' && events[index][1].type === 'attentionSequence' && events[index][1]._close) {
|
|
43
|
+
let open = index;
|
|
44
|
+
|
|
45
|
+
// Now walk back to find an opener.
|
|
46
|
+
while (open--) {
|
|
47
|
+
// Find a token that can open the closer.
|
|
48
|
+
if (events[open][0] === 'exit' && events[open][1].type === 'attentionSequence' && events[open][1]._open &&
|
|
49
|
+
// If the markers are the same:
|
|
50
|
+
context.sliceSerialize(events[open][1]).charCodeAt(0) === context.sliceSerialize(events[index][1]).charCodeAt(0)) {
|
|
51
|
+
// If the opening can close or the closing can open,
|
|
52
|
+
// and the close size *is not* a multiple of three,
|
|
53
|
+
// but the sum of the opening and closing size *is* multiple of three,
|
|
54
|
+
// then don’t match.
|
|
55
|
+
if ((events[open][1]._close || events[index][1]._open) && (events[index][1].end.offset - events[index][1].start.offset) % 3 && !((events[open][1].end.offset - events[open][1].start.offset + events[index][1].end.offset - events[index][1].start.offset) % 3)) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Number of markers to use from the sequence.
|
|
60
|
+
const use = events[open][1].end.offset - events[open][1].start.offset > 1 && events[index][1].end.offset - events[index][1].start.offset > 1 ? 2 : 1;
|
|
61
|
+
const start = {
|
|
62
|
+
...events[open][1].end
|
|
63
|
+
};
|
|
64
|
+
const end = {
|
|
65
|
+
...events[index][1].start
|
|
66
|
+
};
|
|
67
|
+
movePoint(start, -use);
|
|
68
|
+
movePoint(end, use);
|
|
69
|
+
const openingSequence = {
|
|
70
|
+
type: use > 1 ? "strongSequence" : "emphasisSequence",
|
|
71
|
+
start,
|
|
72
|
+
end: {
|
|
73
|
+
...events[open][1].end
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const closingSequence = {
|
|
77
|
+
type: use > 1 ? "strongSequence" : "emphasisSequence",
|
|
78
|
+
start: {
|
|
79
|
+
...events[index][1].start
|
|
80
|
+
},
|
|
81
|
+
end
|
|
82
|
+
};
|
|
83
|
+
const text = {
|
|
84
|
+
type: use > 1 ? "strongText" : "emphasisText",
|
|
85
|
+
start: {
|
|
86
|
+
...events[open][1].end
|
|
87
|
+
},
|
|
88
|
+
end: {
|
|
89
|
+
...events[index][1].start
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const group = {
|
|
93
|
+
type: use > 1 ? "strong" : "emphasis",
|
|
94
|
+
start: {
|
|
95
|
+
...openingSequence.start
|
|
96
|
+
},
|
|
97
|
+
end: {
|
|
98
|
+
...closingSequence.end
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
events[open][1].end = {
|
|
102
|
+
...openingSequence.start
|
|
103
|
+
};
|
|
104
|
+
events[index][1].start = {
|
|
105
|
+
...closingSequence.end
|
|
106
|
+
};
|
|
107
|
+
nextEvents = [];
|
|
108
|
+
|
|
109
|
+
// If there are more markers in the opening, add them before.
|
|
110
|
+
if (events[open][1].end.offset - events[open][1].start.offset) {
|
|
111
|
+
nextEvents = push(nextEvents, [['enter', events[open][1], context], ['exit', events[open][1], context]]);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Opening.
|
|
115
|
+
nextEvents = push(nextEvents, [['enter', group, context], ['enter', openingSequence, context], ['exit', openingSequence, context], ['enter', text, context]]);
|
|
116
|
+
|
|
117
|
+
// Always populated by defaults.
|
|
118
|
+
|
|
119
|
+
// Between.
|
|
120
|
+
nextEvents = push(nextEvents, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open + 1, index), context));
|
|
121
|
+
|
|
122
|
+
// Closing.
|
|
123
|
+
nextEvents = push(nextEvents, [['exit', text, context], ['enter', closingSequence, context], ['exit', closingSequence, context], ['exit', group, context]]);
|
|
124
|
+
|
|
125
|
+
/** @type {number} */
|
|
126
|
+
let offset = 0;
|
|
127
|
+
|
|
128
|
+
// If there are more markers in the closing, add them after.
|
|
129
|
+
if (events[index][1].end.offset - events[index][1].start.offset) {
|
|
130
|
+
offset = 2;
|
|
131
|
+
nextEvents = push(nextEvents, [['enter', events[index][1], context], ['exit', events[index][1], context]]);
|
|
132
|
+
}
|
|
133
|
+
splice(events, open - 1, index - open + 3, nextEvents);
|
|
134
|
+
index = open + nextEvents.length - offset - 2;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Remove remaining sequences.
|
|
142
|
+
index = -1;
|
|
143
|
+
while (++index < events.length) {
|
|
144
|
+
if (events[index][1].type === 'attentionSequence') {
|
|
145
|
+
events[index][1].type = 'data';
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return events;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @this {TokenizeContext}
|
|
153
|
+
* Context.
|
|
154
|
+
* @type {Tokenizer}
|
|
155
|
+
*/
|
|
156
|
+
function tokenizeAttention(effects, ok) {
|
|
157
|
+
const attentionMarkers = this.parser.constructs.attentionMarkers.null;
|
|
158
|
+
const previous = this.previous;
|
|
159
|
+
const before = classifyCharacter(previous);
|
|
160
|
+
|
|
161
|
+
/** @type {NonNullable<Code>} */
|
|
162
|
+
let marker;
|
|
163
|
+
return start;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Before a sequence.
|
|
167
|
+
*
|
|
168
|
+
* ```markdown
|
|
169
|
+
* > | **
|
|
170
|
+
* ^
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @type {State}
|
|
174
|
+
*/
|
|
175
|
+
function start(code) {
|
|
176
|
+
marker = code;
|
|
177
|
+
effects.enter('attentionSequence');
|
|
178
|
+
return inside(code);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* In a sequence.
|
|
183
|
+
*
|
|
184
|
+
* ```markdown
|
|
185
|
+
* > | **
|
|
186
|
+
* ^^
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* @type {State}
|
|
190
|
+
*/
|
|
191
|
+
function inside(code) {
|
|
192
|
+
if (code === marker) {
|
|
193
|
+
effects.consume(code);
|
|
194
|
+
return inside;
|
|
195
|
+
}
|
|
196
|
+
const token = effects.exit('attentionSequence');
|
|
197
|
+
|
|
198
|
+
// To do: next major: move this to resolver, just like `markdown-rs`.
|
|
199
|
+
const after = classifyCharacter(code);
|
|
200
|
+
|
|
201
|
+
// Always populated by defaults.
|
|
202
|
+
|
|
203
|
+
// Note: `*` and `_` are in `attentionMarkers` through core.
|
|
204
|
+
// They are excluded here as the loosening is meant for markers registered
|
|
205
|
+
// by *other* constructs (such as GFM strikethrough’s `~`).
|
|
206
|
+
const open = !after || after === 2 && before || attentionMarkers.includes(code) && code !== 42 && code !== 95;
|
|
207
|
+
const close = !before || before === 2 && after || attentionMarkers.includes(previous) && previous !== 42 && previous !== 95;
|
|
208
|
+
token._open = Boolean(marker === 42 ? open : open && (before || !close));
|
|
209
|
+
token._close = Boolean(marker === 42 ? close : close && (after || !open));
|
|
210
|
+
return ok(code);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Move a point a bit.
|
|
216
|
+
*
|
|
217
|
+
* Note: `move` only works inside lines! It’s not possible to move past other
|
|
218
|
+
* chunks (replacement characters, tabs, or line endings).
|
|
219
|
+
*
|
|
220
|
+
* @param {Point} point
|
|
221
|
+
* Point.
|
|
222
|
+
* @param {number} offset
|
|
223
|
+
* Amount to move.
|
|
224
|
+
* @returns {undefined}
|
|
225
|
+
* Nothing.
|
|
226
|
+
*/
|
|
227
|
+
function movePoint(point, offset) {
|
|
228
|
+
point.column += offset;
|
|
229
|
+
point.offset += offset;
|
|
230
|
+
point._bufferIndex += offset;
|
|
231
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {
|
|
3
|
+
* Construct,
|
|
4
|
+
* State,
|
|
5
|
+
* TokenizeContext,
|
|
6
|
+
* Tokenizer
|
|
7
|
+
* } from 'micromark-util-types'
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { asciiAlphanumeric, asciiAlpha, asciiAtext, asciiControl } from 'micromark-util-character';
|
|
11
|
+
/** @type {Construct} */
|
|
12
|
+
export const autolink = {
|
|
13
|
+
name: 'autolink',
|
|
14
|
+
tokenize: tokenizeAutolink
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @this {TokenizeContext}
|
|
19
|
+
* Context.
|
|
20
|
+
* @type {Tokenizer}
|
|
21
|
+
*/
|
|
22
|
+
function tokenizeAutolink(effects, ok, nok) {
|
|
23
|
+
let size = 0;
|
|
24
|
+
return start;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Start of an autolink.
|
|
28
|
+
*
|
|
29
|
+
* ```markdown
|
|
30
|
+
* > | a<https://example.com>b
|
|
31
|
+
* ^
|
|
32
|
+
* > | a<user@example.com>b
|
|
33
|
+
* ^
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @type {State}
|
|
37
|
+
*/
|
|
38
|
+
function start(code) {
|
|
39
|
+
effects.enter("autolink");
|
|
40
|
+
effects.enter("autolinkMarker");
|
|
41
|
+
effects.consume(code);
|
|
42
|
+
effects.exit("autolinkMarker");
|
|
43
|
+
effects.enter("autolinkProtocol");
|
|
44
|
+
return open;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* After `<`, at protocol or atext.
|
|
49
|
+
*
|
|
50
|
+
* ```markdown
|
|
51
|
+
* > | a<https://example.com>b
|
|
52
|
+
* ^
|
|
53
|
+
* > | a<user@example.com>b
|
|
54
|
+
* ^
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @type {State}
|
|
58
|
+
*/
|
|
59
|
+
function open(code) {
|
|
60
|
+
if (asciiAlpha(code)) {
|
|
61
|
+
effects.consume(code);
|
|
62
|
+
return schemeOrEmailAtext;
|
|
63
|
+
}
|
|
64
|
+
if (code === 64) {
|
|
65
|
+
return nok(code);
|
|
66
|
+
}
|
|
67
|
+
return emailAtext(code);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* At second byte of protocol or atext.
|
|
72
|
+
*
|
|
73
|
+
* ```markdown
|
|
74
|
+
* > | a<https://example.com>b
|
|
75
|
+
* ^
|
|
76
|
+
* > | a<user@example.com>b
|
|
77
|
+
* ^
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @type {State}
|
|
81
|
+
*/
|
|
82
|
+
function schemeOrEmailAtext(code) {
|
|
83
|
+
// ASCII alphanumeric and `+`, `-`, and `.`.
|
|
84
|
+
if (code === 43 || code === 45 || code === 46 || asciiAlphanumeric(code)) {
|
|
85
|
+
// Count the previous alphabetical from `open` too.
|
|
86
|
+
size = 1;
|
|
87
|
+
return schemeInsideOrEmailAtext(code);
|
|
88
|
+
}
|
|
89
|
+
return emailAtext(code);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* In ambiguous protocol or atext.
|
|
94
|
+
*
|
|
95
|
+
* ```markdown
|
|
96
|
+
* > | a<https://example.com>b
|
|
97
|
+
* ^
|
|
98
|
+
* > | a<user@example.com>b
|
|
99
|
+
* ^
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @type {State}
|
|
103
|
+
*/
|
|
104
|
+
function schemeInsideOrEmailAtext(code) {
|
|
105
|
+
if (code === 58) {
|
|
106
|
+
effects.consume(code);
|
|
107
|
+
size = 0;
|
|
108
|
+
return urlInside;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ASCII alphanumeric and `+`, `-`, and `.`.
|
|
112
|
+
if ((code === 43 || code === 45 || code === 46 || asciiAlphanumeric(code)) && size++ < 32) {
|
|
113
|
+
effects.consume(code);
|
|
114
|
+
return schemeInsideOrEmailAtext;
|
|
115
|
+
}
|
|
116
|
+
size = 0;
|
|
117
|
+
return emailAtext(code);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* After protocol, in URL.
|
|
122
|
+
*
|
|
123
|
+
* ```markdown
|
|
124
|
+
* > | a<https://example.com>b
|
|
125
|
+
* ^
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @type {State}
|
|
129
|
+
*/
|
|
130
|
+
function urlInside(code) {
|
|
131
|
+
if (code === 62) {
|
|
132
|
+
effects.exit("autolinkProtocol");
|
|
133
|
+
effects.enter("autolinkMarker");
|
|
134
|
+
effects.consume(code);
|
|
135
|
+
effects.exit("autolinkMarker");
|
|
136
|
+
effects.exit("autolink");
|
|
137
|
+
return ok;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ASCII control, space, or `<`.
|
|
141
|
+
if (code === null || code === 32 || code === 60 || asciiControl(code)) {
|
|
142
|
+
return nok(code);
|
|
143
|
+
}
|
|
144
|
+
effects.consume(code);
|
|
145
|
+
return urlInside;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* In email atext.
|
|
150
|
+
*
|
|
151
|
+
* ```markdown
|
|
152
|
+
* > | a<user.name@example.com>b
|
|
153
|
+
* ^
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* @type {State}
|
|
157
|
+
*/
|
|
158
|
+
function emailAtext(code) {
|
|
159
|
+
if (code === 64) {
|
|
160
|
+
effects.consume(code);
|
|
161
|
+
return emailAtSignOrDot;
|
|
162
|
+
}
|
|
163
|
+
if (asciiAtext(code)) {
|
|
164
|
+
effects.consume(code);
|
|
165
|
+
return emailAtext;
|
|
166
|
+
}
|
|
167
|
+
return nok(code);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* In label, after at-sign or dot.
|
|
172
|
+
*
|
|
173
|
+
* ```markdown
|
|
174
|
+
* > | a<user.name@example.com>b
|
|
175
|
+
* ^ ^
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* @type {State}
|
|
179
|
+
*/
|
|
180
|
+
function emailAtSignOrDot(code) {
|
|
181
|
+
return asciiAlphanumeric(code) ? emailLabel(code) : nok(code);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* In label, where `.` and `>` are allowed.
|
|
186
|
+
*
|
|
187
|
+
* ```markdown
|
|
188
|
+
* > | a<user.name@example.com>b
|
|
189
|
+
* ^
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* @type {State}
|
|
193
|
+
*/
|
|
194
|
+
function emailLabel(code) {
|
|
195
|
+
if (code === 46) {
|
|
196
|
+
effects.consume(code);
|
|
197
|
+
size = 0;
|
|
198
|
+
return emailAtSignOrDot;
|
|
199
|
+
}
|
|
200
|
+
if (code === 62) {
|
|
201
|
+
// Exit, then change the token type.
|
|
202
|
+
effects.exit("autolinkProtocol").type = "autolinkEmail";
|
|
203
|
+
effects.enter("autolinkMarker");
|
|
204
|
+
effects.consume(code);
|
|
205
|
+
effects.exit("autolinkMarker");
|
|
206
|
+
effects.exit("autolink");
|
|
207
|
+
return ok;
|
|
208
|
+
}
|
|
209
|
+
return emailValue(code);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* In label, where `.` and `>` are *not* allowed.
|
|
214
|
+
*
|
|
215
|
+
* Though, this is also used in `emailLabel` to parse other values.
|
|
216
|
+
*
|
|
217
|
+
* ```markdown
|
|
218
|
+
* > | a<user.name@ex-ample.com>b
|
|
219
|
+
* ^
|
|
220
|
+
* ```
|
|
221
|
+
*
|
|
222
|
+
* @type {State}
|
|
223
|
+
*/
|
|
224
|
+
function emailValue(code) {
|
|
225
|
+
// ASCII alphanumeric or `-`.
|
|
226
|
+
if ((code === 45 || asciiAlphanumeric(code)) && size++ < 63) {
|
|
227
|
+
const next = code === 45 ? emailValue : emailLabel;
|
|
228
|
+
effects.consume(code);
|
|
229
|
+
return next;
|
|
230
|
+
}
|
|
231
|
+
return nok(code);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {
|
|
3
|
+
* Construct,
|
|
4
|
+
* State,
|
|
5
|
+
* TokenizeContext,
|
|
6
|
+
* Tokenizer
|
|
7
|
+
* } from 'micromark-util-types'
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { factorySpace } from 'micromark-factory-space';
|
|
11
|
+
import { markdownLineEnding, markdownSpace } from 'micromark-util-character';
|
|
12
|
+
/** @type {Construct} */
|
|
13
|
+
export const blankLine = {
|
|
14
|
+
partial: true,
|
|
15
|
+
tokenize: tokenizeBlankLine
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @this {TokenizeContext}
|
|
20
|
+
* Context.
|
|
21
|
+
* @type {Tokenizer}
|
|
22
|
+
*/
|
|
23
|
+
function tokenizeBlankLine(effects, ok, nok) {
|
|
24
|
+
return start;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Start of blank line.
|
|
28
|
+
*
|
|
29
|
+
* > 👉 **Note**: `␠` represents a space character.
|
|
30
|
+
*
|
|
31
|
+
* ```markdown
|
|
32
|
+
* > | ␠␠␊
|
|
33
|
+
* ^
|
|
34
|
+
* > | ␊
|
|
35
|
+
* ^
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @type {State}
|
|
39
|
+
*/
|
|
40
|
+
function start(code) {
|
|
41
|
+
return markdownSpace(code) ? factorySpace(effects, after, "linePrefix")(code) : after(code);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* At eof/eol, after optional whitespace.
|
|
46
|
+
*
|
|
47
|
+
* > 👉 **Note**: `␠` represents a space character.
|
|
48
|
+
*
|
|
49
|
+
* ```markdown
|
|
50
|
+
* > | ␠␠␊
|
|
51
|
+
* ^
|
|
52
|
+
* > | ␊
|
|
53
|
+
* ^
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @type {State}
|
|
57
|
+
*/
|
|
58
|
+
function after(code) {
|
|
59
|
+
return code === null || markdownLineEnding(code) ? ok(code) : nok(code);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {
|
|
3
|
+
* Construct,
|
|
4
|
+
* Exiter,
|
|
5
|
+
* State,
|
|
6
|
+
* TokenizeContext,
|
|
7
|
+
* Tokenizer
|
|
8
|
+
* } from 'micromark-util-types'
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { factorySpace } from 'micromark-factory-space';
|
|
12
|
+
import { markdownSpace } from 'micromark-util-character';
|
|
13
|
+
/** @type {Construct} */
|
|
14
|
+
export const blockQuote = {
|
|
15
|
+
continuation: {
|
|
16
|
+
tokenize: tokenizeBlockQuoteContinuation
|
|
17
|
+
},
|
|
18
|
+
exit,
|
|
19
|
+
name: 'blockQuote',
|
|
20
|
+
tokenize: tokenizeBlockQuoteStart
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @this {TokenizeContext}
|
|
25
|
+
* Context.
|
|
26
|
+
* @type {Tokenizer}
|
|
27
|
+
*/
|
|
28
|
+
function tokenizeBlockQuoteStart(effects, ok, nok) {
|
|
29
|
+
const self = this;
|
|
30
|
+
return start;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Start of block quote.
|
|
34
|
+
*
|
|
35
|
+
* ```markdown
|
|
36
|
+
* > | > a
|
|
37
|
+
* ^
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @type {State}
|
|
41
|
+
*/
|
|
42
|
+
function start(code) {
|
|
43
|
+
if (code === 62) {
|
|
44
|
+
const state = self.containerState;
|
|
45
|
+
if (!state.open) {
|
|
46
|
+
effects.enter("blockQuote", {
|
|
47
|
+
_container: true
|
|
48
|
+
});
|
|
49
|
+
state.open = true;
|
|
50
|
+
}
|
|
51
|
+
effects.enter("blockQuotePrefix");
|
|
52
|
+
effects.enter("blockQuoteMarker");
|
|
53
|
+
effects.consume(code);
|
|
54
|
+
effects.exit("blockQuoteMarker");
|
|
55
|
+
return after;
|
|
56
|
+
}
|
|
57
|
+
return nok(code);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* After `>`, before optional whitespace.
|
|
62
|
+
*
|
|
63
|
+
* ```markdown
|
|
64
|
+
* > | > a
|
|
65
|
+
* ^
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @type {State}
|
|
69
|
+
*/
|
|
70
|
+
function after(code) {
|
|
71
|
+
if (markdownSpace(code)) {
|
|
72
|
+
effects.enter("blockQuotePrefixWhitespace");
|
|
73
|
+
effects.consume(code);
|
|
74
|
+
effects.exit("blockQuotePrefixWhitespace");
|
|
75
|
+
effects.exit("blockQuotePrefix");
|
|
76
|
+
return ok;
|
|
77
|
+
}
|
|
78
|
+
effects.exit("blockQuotePrefix");
|
|
79
|
+
return ok(code);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Start of block quote continuation.
|
|
85
|
+
*
|
|
86
|
+
* ```markdown
|
|
87
|
+
* | > a
|
|
88
|
+
* > | > b
|
|
89
|
+
* ^
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @this {TokenizeContext}
|
|
93
|
+
* Context.
|
|
94
|
+
* @type {Tokenizer}
|
|
95
|
+
*/
|
|
96
|
+
function tokenizeBlockQuoteContinuation(effects, ok, nok) {
|
|
97
|
+
const self = this;
|
|
98
|
+
return contStart;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Start of block quote continuation.
|
|
102
|
+
*
|
|
103
|
+
* Also used to parse the first block quote opening.
|
|
104
|
+
*
|
|
105
|
+
* ```markdown
|
|
106
|
+
* | > a
|
|
107
|
+
* > | > b
|
|
108
|
+
* ^
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @type {State}
|
|
112
|
+
*/
|
|
113
|
+
function contStart(code) {
|
|
114
|
+
if (markdownSpace(code)) {
|
|
115
|
+
// Always populated by defaults.
|
|
116
|
+
|
|
117
|
+
return factorySpace(effects, contBefore, "linePrefix", self.parser.constructs.disable.null.includes('codeIndented') ? undefined : 4)(code);
|
|
118
|
+
}
|
|
119
|
+
return contBefore(code);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* At `>`, after optional whitespace.
|
|
124
|
+
*
|
|
125
|
+
* Also used to parse the first block quote opening.
|
|
126
|
+
*
|
|
127
|
+
* ```markdown
|
|
128
|
+
* | > a
|
|
129
|
+
* > | > b
|
|
130
|
+
* ^
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @type {State}
|
|
134
|
+
*/
|
|
135
|
+
function contBefore(code) {
|
|
136
|
+
return effects.attempt(blockQuote, ok, nok)(code);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** @type {Exiter} */
|
|
141
|
+
function exit(effects) {
|
|
142
|
+
effects.exit("blockQuote");
|
|
143
|
+
}
|