@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/block.d.ts +257 -0
- package/dist/block.js +213 -68
- package/dist/block.js.map +1 -1
- package/dist/engine-block.d.ts +69 -0
- package/dist/engine-block.js +99 -0
- package/dist/engine-block.js.map +1 -0
- package/dist/engine-inline.d.ts +25 -0
- package/dist/engine-inline.js +237 -0
- package/dist/engine-inline.js.map +1 -0
- package/dist/inline.d.ts +250 -0
- package/dist/inline.js +395 -215
- package/dist/inline.js.map +1 -1
- package/dist/markdown.d.ts +2 -3
- package/dist/markdown.js +91 -63
- package/dist/markdown.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/block.ts +224 -75
- package/src/engine-block.ts +151 -0
- package/src/engine-inline.ts +284 -0
- package/src/inline.ts +422 -218
- package/src/markdown.ts +95 -65
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 `` 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 {};
|