@tabnas/markdown 0.6.2 → 0.7.2

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/dist/inline.d.ts CHANGED
@@ -1,5 +1,245 @@
1
1
  import { MdNode } from './node.ts';
2
2
  import type { ParserOptions, RefMap } from './options.ts';
3
+ /** One `*`, `_` or `~` run on the delimiter stack (§6.4). */
4
+ type Delimiter = {
5
+ /** Character code of the delimiter character. */
6
+ cc: number;
7
+ /** Delimiters still unused; drops as pairs are consumed. */
8
+ numdelims: number;
9
+ /** Run length as originally scanned — what the rule of three is computed on. */
10
+ origdelims: number;
11
+ node: MdNode;
12
+ previous: Delimiter | null;
13
+ next: Delimiter | null;
14
+ canOpen: boolean;
15
+ canClose: boolean;
16
+ };
17
+ /** One `[` or `![` on the bracket stack (§6.3). */
18
+ type Bracket = {
19
+ node: MdNode;
20
+ previous: Bracket | null;
21
+ /** Top of the delimiter stack when this bracket opened — the emphasis floor. */
22
+ previousDelimiter: Delimiter | null;
23
+ /** Offset of the `[` in the subject. */
24
+ index: number;
25
+ image: boolean;
26
+ /** Cleared on earlier openers once a link is built: no links in links. */
27
+ active: boolean;
28
+ /** Another bracket opened after this one, so its text contains a `[`. */
29
+ bracketAfter: boolean;
30
+ };
31
+ export type DelimScan = {
32
+ numdelims: number;
33
+ canOpen: boolean;
34
+ canClose: boolean;
35
+ };
36
+ /**
37
+ * The whole code point ending at `end`, so an astral character is classified
38
+ * as one character by the flanking rules rather than as a lone surrogate.
39
+ * Start of subject counts as a line ending (§6.4).
40
+ */
41
+ export declare function codePointBefore(subject: string, end: number): string;
42
+ /** The whole code point at `i`; end of subject counts as a line ending. */
43
+ export declare function codePointAt(subject: string, i: number): string;
44
+ /** End of the run of spaces starting at `pos`. */
45
+ export declare function skipInitialSpaces(subject: string, pos: number): number;
46
+ /** End of "spaces, and at most one line ending" starting at `pos` (§6.3). */
47
+ export declare function matchSpnl(subject: string, pos: number): number;
48
+ export type CodeSpanScan = {
49
+ closed: true;
50
+ end: number;
51
+ literal: string;
52
+ } | {
53
+ closed: false;
54
+ end: number;
55
+ ticks: string;
56
+ };
57
+ /**
58
+ * §6.3: a code span runs from a backtick string to the next backtick string
59
+ * of *exactly* the same length. `closed: false` reports an unmatched opener,
60
+ * which is literal text; null means no backtick run starts at `pos`.
61
+ */
62
+ export declare function scanCodeSpan(subject: string, pos: number): CodeSpanScan | null;
63
+ export type EscapeScan = {
64
+ kind: 'linebreak' | 'char' | 'literal';
65
+ literal: string;
66
+ end: number;
67
+ };
68
+ /**
69
+ * §6.1/§6.7: a backslash escape, with `pos` at the backslash. Always
70
+ * succeeds: a backslash before anything unescapable is a literal backslash.
71
+ * The `linebreak` form consumes the following line's leading spaces.
72
+ */
73
+ export declare function scanEscape(subject: string, pos: number): EscapeScan;
74
+ export type AngleAutolinkScan = {
75
+ dest: string;
76
+ label: string;
77
+ end: number;
78
+ };
79
+ /** §6.5: an email or URI autolink in angle brackets. */
80
+ export declare function scanAngleAutolink(subject: string, pos: number): AngleAutolinkScan | null;
81
+ /** §6.6: a raw HTML tag (open, close, comment, PI, declaration or CDATA). */
82
+ export declare function scanHtmlTag(subject: string, pos: number): {
83
+ raw: string;
84
+ end: number;
85
+ } | null;
86
+ /** §6.2: an entity or numeric character reference, decoded. */
87
+ export declare function scanEntity(subject: string, pos: number): {
88
+ literal: string;
89
+ end: number;
90
+ } | null;
91
+ /**
92
+ * §6.4: classify the run of `cc` starting at `pos` without consuming it.
93
+ *
94
+ * A run is left-flanking iff it is not followed by Unicode whitespace and
95
+ * either not followed by Unicode punctuation or else preceded by whitespace
96
+ * or punctuation; right-flanking is the mirror image. `_` additionally may
97
+ * not open inside a word (rules 2, 4, 6, 8), which is what keeps
98
+ * `snake_case_words` intact; `*` has no such restriction.
99
+ */
100
+ export declare function scanDelimiterRun(subject: string, pos: number, cc: number): DelimScan | null;
101
+ /**
102
+ * §6.7/§6.8: how a line ending resolves, given the literal of the text node
103
+ * immediately before it. Two or more trailing spaces make a hard break;
104
+ * `trim` says the trailing spaces must be dropped from that node either way.
105
+ */
106
+ export declare function classifyBreak(prevTextLiteral: string | null): {
107
+ hard: boolean;
108
+ trim: boolean;
109
+ };
110
+ /** §6.3: a link title at `pos`, without its delimiters, unescaped. */
111
+ export declare function scanLinkTitle(subject: string, pos: number): {
112
+ title: string;
113
+ end: number;
114
+ } | null;
115
+ /**
116
+ * §6.3: a link destination at `pos` — either `<...>`, or a bare run with
117
+ * balanced unescaped parentheses and no ASCII control characters or spaces.
118
+ *
119
+ * The destination is backslash-unescaped and entity-decoded, but **not**
120
+ * percent-encoded: `[l](/ä)` yields `/ä`, not `/%C3%A4`. Encoding is a
121
+ * rendering concern and `html.ts` applies `normalizeURI` when it writes the
122
+ * attribute; the public AST promises the decoded form.
123
+ */
124
+ export declare function scanLinkDestination(subject: string, pos: number): {
125
+ dest: string;
126
+ end: number;
127
+ } | null;
128
+ /**
129
+ * §4.7/§6.3: a link label at `pos`, including brackets. `rawLength` is what
130
+ * was consumed; `length` is 0 when the label is too long to be valid (§4.7:
131
+ * at most 999 characters between the brackets).
132
+ */
133
+ export declare function scanLinkLabel(subject: string, pos: number): {
134
+ rawLength: number;
135
+ length: number;
136
+ } | null;
137
+ export type LinkTailScan = {
138
+ dest: string;
139
+ title: string | null;
140
+ end: number;
141
+ };
142
+ /**
143
+ * §6.3: the `(destination "title")` tail of an inline link, with `pos` just
144
+ * after the `]`. Null unless the whole tail — through the closing paren —
145
+ * is present.
146
+ */
147
+ export declare function scanInlineLinkTail(subject: string, pos: number): LinkTailScan | null;
148
+ export declare class InlineParser {
149
+ subject: string;
150
+ pos: number;
151
+ delimiters: Delimiter | null;
152
+ brackets: Bracket | null;
153
+ refmap: RefMap;
154
+ options: ParserOptions;
155
+ constructor(refmap: RefMap, options: ParserOptions);
156
+ /** Character code at `pos`, or -1 at the end of the subject. */
157
+ peek(): number;
158
+ /** Match a sticky regex at `pos`; on success advance past it. */
159
+ match(re: RegExp): string | null;
160
+ /** Spaces, and at most one line ending, between the parts of a link. */
161
+ spnl(): void;
162
+ /**
163
+ * The whole code point ending at `end`, so an astral character is
164
+ * classified as one character by the flanking rules rather than as a lone
165
+ * surrogate. Start of subject counts as a line ending (§6.4).
166
+ */
167
+ charBefore(end: number): string;
168
+ /** The whole code point at `i`; end of subject counts as a line ending. */
169
+ charAtPos(i: number): string;
170
+ /**
171
+ * A code span runs from a backtick string to the next backtick string of
172
+ * *exactly* the same length. Unmatched opening backticks are literal text.
173
+ */
174
+ parseBackticks(block: MdNode): boolean;
175
+ parseBackslash(block: MdNode): boolean;
176
+ parseAutolink(block: MdNode): boolean;
177
+ makeAutolink(destination: string, label: string): MdNode;
178
+ parseHtmlTag(block: MdNode): boolean;
179
+ /** Classify the run of `cc` starting at `pos` without consuming it. */
180
+ scanDelims(cc: number): DelimScan | null;
181
+ /** Emit a delimiter run as text and push it on the delimiter stack. */
182
+ handleDelim(cc: number, block: MdNode): boolean;
183
+ removeDelimiter(delim: Delimiter): void;
184
+ /**
185
+ * The spec's "process emphasis" procedure. `stackBottom` is the floor: for
186
+ * the whole-block call it is null, and for the inlines of a link it is the
187
+ * delimiter that was on top when the link's `[` opened.
188
+ */
189
+ processEmphasis(stackBottom: Delimiter | null): void;
190
+ /** Link title without its delimiters, unescaped; null if none here. */
191
+ parseLinkTitle(): string | null;
192
+ /**
193
+ * Link destination: either `<...>`, or a bare run with balanced unescaped
194
+ * parentheses and no ASCII control characters or spaces. See
195
+ * `scanLinkDestination` for why the value is decoded but not
196
+ * percent-encoded.
197
+ */
198
+ parseLinkDestination(): string | null;
199
+ /** Length of the link label at `pos`, including brackets; 0 if invalid. */
200
+ parseLinkLabel(): number;
201
+ addBracket(node: MdNode, index: number, image: boolean): void;
202
+ removeBracket(): void;
203
+ parseOpenBracket(block: MdNode): boolean;
204
+ /** `!` only matters when it introduces an image. */
205
+ parseBang(block: MdNode): boolean;
206
+ /**
207
+ * The spec's "look for link or image" procedure. On a `]`, walk back to
208
+ * the newest bracket opener and try, in order: an inline `(dest "title")`,
209
+ * a full `[label]`, a collapsed `[]` or a shortcut reference. Anything that
210
+ * fails backtracks to just after the `]` and leaves a literal `]`.
211
+ */
212
+ parseCloseBracket(block: MdNode): boolean;
213
+ parseEntity(block: MdNode): boolean;
214
+ parseString(block: MdNode): boolean;
215
+ /**
216
+ * §6.7/§6.8: two or more spaces before the line ending make a hard break,
217
+ * anything else a soft one. Trailing spaces are dropped either way, as is
218
+ * the indentation of the next line.
219
+ */
220
+ parseNewline(block: MdNode): boolean;
221
+ /** One inline construct at `pos`; false only at the end of the subject. */
222
+ parseInline(block: MdNode): boolean;
223
+ /** Nothing claimed the character at `pos`: consume it as literal text. */
224
+ parseLiteralChar(block: MdNode): boolean;
225
+ /**
226
+ * Reset for one block's raw content; false when the trimmed subject is
227
+ * empty. Trimming is what stops trailing spaces at the end of a block
228
+ * from making a hard break, and drops the leading indentation of the
229
+ * first line.
230
+ */
231
+ beginBlock(block: MdNode): boolean;
232
+ /** The tail of a block's inline parse: clear the raw content, resolve
233
+ * emphasis over the whole delimiter stack. */
234
+ finishBlock(block: MdNode): void;
235
+ /** Parse one paragraph or heading's raw content into inline children. */
236
+ parse(block: MdNode): void;
237
+ /**
238
+ * §4.7: consume leading link reference definitions. Called by the block
239
+ * phase while finalizing a paragraph, repeatedly, until it returns 0.
240
+ */
241
+ parseReference(s: string): number;
242
+ }
3
243
  /**
4
244
  * Recognise GFM autolink literals throughout one finished block's inlines.
5
245
  *
@@ -11,9 +251,19 @@ export declare function linkifyAutolinks(block: MdNode): void;
11
251
  * every paragraph, heading and table cell into inline children.
12
252
  */
13
253
  export declare function parseInlines(doc: MdNode, refmap: RefMap, options: ParserOptions): void;
254
+ /**
255
+ * Walk the finished block tree, handing every inline content block
256
+ * (paragraphs, headings, table cells) to `fn` and running the GFM
257
+ * autolink-literal post-pass after it. This is the one iteration both
258
+ * inline drivers share — the hand scanner above and the engine path — so
259
+ * which blocks get inline parsing, and when linkify runs, is decided
260
+ * exactly once.
261
+ */
262
+ export declare function forEachInlineBlock(doc: MdNode, options: ParserOptions, fn: (block: MdNode) => void): void;
14
263
  /**
15
264
  * Consume link reference definitions from the front of a paragraph's raw
16
265
  * content, adding them to `refmap`. Returns the number of characters
17
266
  * consumed, or 0 if `s` does not start with a definition.
18
267
  */
19
268
  export declare function parseReference(s: string, refmap: RefMap): number;
269
+ export {};