@profullstack/readm3 0.2.0 → 0.3.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/README.md +100 -12
- package/dist/cli.d.ts +5 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +45 -5
- package/dist/cli.js.map +1 -1
- package/dist/editor.d.ts +77 -0
- package/dist/editor.d.ts.map +1 -0
- package/dist/editor.js +308 -0
- package/dist/editor.js.map +1 -0
- package/dist/emoji.d.ts +12 -0
- package/dist/emoji.d.ts.map +1 -0
- package/dist/emoji.js +73 -0
- package/dist/emoji.js.map +1 -0
- package/dist/flavors.d.ts +68 -0
- package/dist/flavors.d.ts.map +1 -0
- package/dist/flavors.js +223 -0
- package/dist/flavors.js.map +1 -0
- package/dist/index.d.ts +10 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/dist/markdown.d.ts +12 -3
- package/dist/markdown.d.ts.map +1 -1
- package/dist/markdown.js +424 -379
- package/dist/markdown.js.map +1 -1
- package/dist/print.d.ts +3 -3
- package/dist/print.d.ts.map +1 -1
- package/dist/print.js +8 -3
- package/dist/print.js.map +1 -1
- package/dist/roles.d.ts.map +1 -1
- package/dist/roles.js +17 -0
- package/dist/roles.js.map +1 -1
- package/dist/viewer.d.ts +5 -0
- package/dist/viewer.d.ts.map +1 -1
- package/dist/viewer.js +375 -60
- package/dist/viewer.js.map +1 -1
- package/package.json +9 -3
package/dist/flavors.js
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown flavors, as marked extensions.
|
|
3
|
+
*
|
|
4
|
+
* marked handles CommonMark and GFM — tables, task lists, strikethrough and
|
|
5
|
+
* bare-URL autolinks — so what lives here is only what GitHub and Reddit added
|
|
6
|
+
* on top and marked does not ship: footnotes, alerts, spoilers, superscript,
|
|
7
|
+
* subreddit and user links, and `:shortcode:` emoji.
|
|
8
|
+
*
|
|
9
|
+
* Every extension is a tokenizer only. readm3 never renders HTML: it walks the
|
|
10
|
+
* token tree itself in `markdown.ts` and emits styled spans, so a `renderer` on
|
|
11
|
+
* these would be dead weight.
|
|
12
|
+
*/
|
|
13
|
+
import { Lexer, Marked } from "marked";
|
|
14
|
+
import { emojiFor } from "./emoji.js";
|
|
15
|
+
export const FLAVORS = ["commonmark", "github", "reddit", "all"];
|
|
16
|
+
export const DEFAULT_FLAVOR = "github";
|
|
17
|
+
export function isFlavor(value) {
|
|
18
|
+
return FLAVORS.includes(value);
|
|
19
|
+
}
|
|
20
|
+
/* ------------------------------------------------------------- footnotes --- */
|
|
21
|
+
/** `[^1]: the note`, with indented continuation lines folded in. */
|
|
22
|
+
const footnoteDef = {
|
|
23
|
+
name: "footnoteDef",
|
|
24
|
+
level: "block",
|
|
25
|
+
start(src) {
|
|
26
|
+
const m = /^\[\^[^\]\n]+\]:/m.exec(src);
|
|
27
|
+
return m ? m.index : undefined;
|
|
28
|
+
},
|
|
29
|
+
tokenizer(src) {
|
|
30
|
+
const m = /^\[\^([^\]\n]+)\]:[ \t]*([^\n]*(?:\n(?:[ \t]+[^\n]*|[ \t]*(?=\n)))*)/.exec(src);
|
|
31
|
+
if (!m)
|
|
32
|
+
return undefined;
|
|
33
|
+
const body = (m[2] ?? "")
|
|
34
|
+
.split("\n")
|
|
35
|
+
.map((line) => line.replace(/^(?: {1,4}|\t)/, ""))
|
|
36
|
+
.join("\n")
|
|
37
|
+
.trim();
|
|
38
|
+
return {
|
|
39
|
+
type: "footnoteDef",
|
|
40
|
+
raw: m[0],
|
|
41
|
+
label: m[1],
|
|
42
|
+
tokens: this.lexer.blockTokens(body ? `${body}\n` : "\n"),
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
/** `[^1]` in running text. Must out-run the link tokenizer, so it is an extension. */
|
|
47
|
+
const footnoteRef = {
|
|
48
|
+
name: "footnoteRef",
|
|
49
|
+
level: "inline",
|
|
50
|
+
start(src) {
|
|
51
|
+
const i = src.indexOf("[^");
|
|
52
|
+
return i < 0 ? undefined : i;
|
|
53
|
+
},
|
|
54
|
+
tokenizer(src) {
|
|
55
|
+
const m = /^\[\^([^\]\n]+)\]/.exec(src);
|
|
56
|
+
if (!m)
|
|
57
|
+
return undefined;
|
|
58
|
+
return { type: "footnoteRef", raw: m[0], label: m[1] };
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
/* -------------------------------------------------------------- reddit --- */
|
|
62
|
+
/** `>!spoiler!<`. */
|
|
63
|
+
const spoiler = {
|
|
64
|
+
name: "spoiler",
|
|
65
|
+
level: "inline",
|
|
66
|
+
start(src) {
|
|
67
|
+
const i = src.indexOf(">!");
|
|
68
|
+
return i < 0 ? undefined : i;
|
|
69
|
+
},
|
|
70
|
+
tokenizer(src) {
|
|
71
|
+
const m = /^>!([\s\S]+?)!</.exec(src);
|
|
72
|
+
if (!m)
|
|
73
|
+
return undefined;
|
|
74
|
+
return {
|
|
75
|
+
type: "spoiler",
|
|
76
|
+
raw: m[0],
|
|
77
|
+
text: m[1],
|
|
78
|
+
tokens: this.lexer.inlineTokens(m[1]),
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* A paragraph opening with `>!`, claimed before the blockquote tokenizer sees it.
|
|
84
|
+
*
|
|
85
|
+
* `>` starts a blockquote in every other dialect, so without this a spoiler at
|
|
86
|
+
* the start of a line is quoted and its `>!` is eaten. Reddit reads the spoiler,
|
|
87
|
+
* and so do we — but only under a flavor that asked for it.
|
|
88
|
+
*/
|
|
89
|
+
const spoilerParagraph = {
|
|
90
|
+
name: "spoilerParagraph",
|
|
91
|
+
level: "block",
|
|
92
|
+
start(src) {
|
|
93
|
+
const m = /^>!/m.exec(src);
|
|
94
|
+
return m ? m.index : undefined;
|
|
95
|
+
},
|
|
96
|
+
tokenizer(src) {
|
|
97
|
+
if (!src.startsWith(">!"))
|
|
98
|
+
return undefined;
|
|
99
|
+
const m = /^[^\n]+(?:\n(?!\s*\n)[^\n]+)*/.exec(src);
|
|
100
|
+
if (!m)
|
|
101
|
+
return undefined;
|
|
102
|
+
const text = m[0];
|
|
103
|
+
return {
|
|
104
|
+
type: "paragraph",
|
|
105
|
+
raw: text,
|
|
106
|
+
text,
|
|
107
|
+
tokens: this.lexer.inlineTokens(text),
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
/** `^(a phrase)` or `^word`. */
|
|
112
|
+
const superscript = {
|
|
113
|
+
name: "superscript",
|
|
114
|
+
level: "inline",
|
|
115
|
+
start(src) {
|
|
116
|
+
const i = src.indexOf("^");
|
|
117
|
+
return i < 0 ? undefined : i;
|
|
118
|
+
},
|
|
119
|
+
tokenizer(src) {
|
|
120
|
+
const m = /^\^\(([^)\n]+)\)|^\^([^\s^()]+)/.exec(src);
|
|
121
|
+
if (!m)
|
|
122
|
+
return undefined;
|
|
123
|
+
const text = (m[1] ?? m[2] ?? "").trim();
|
|
124
|
+
if (!text)
|
|
125
|
+
return undefined;
|
|
126
|
+
return { type: "superscript", raw: m[0], text, tokens: this.lexer.inlineTokens(text) };
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* `r/subreddit` and `u/user`, with or without a leading slash.
|
|
131
|
+
*
|
|
132
|
+
* `start` carries the word-boundary check because a tokenizer only ever sees
|
|
133
|
+
* the source from a position marked, and `foo/r/bar` must not qualify.
|
|
134
|
+
*/
|
|
135
|
+
const redditLink = {
|
|
136
|
+
name: "redditLink",
|
|
137
|
+
level: "inline",
|
|
138
|
+
start(src) {
|
|
139
|
+
const m = /(^|[^\w/])(\/?[ru]\/[A-Za-z0-9][A-Za-z0-9_-]{1,})/.exec(src);
|
|
140
|
+
return m ? m.index + m[1].length : undefined;
|
|
141
|
+
},
|
|
142
|
+
tokenizer(src) {
|
|
143
|
+
const m = /^\/?([ru])\/([A-Za-z0-9][A-Za-z0-9_-]{1,})/.exec(src);
|
|
144
|
+
if (!m)
|
|
145
|
+
return undefined;
|
|
146
|
+
return {
|
|
147
|
+
type: "redditLink",
|
|
148
|
+
raw: m[0],
|
|
149
|
+
kind: m[1],
|
|
150
|
+
name: m[2],
|
|
151
|
+
href: `https://www.reddit.com/${m[1]}/${m[2]}/`,
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
/* --------------------------------------------------------------- emoji --- */
|
|
156
|
+
/** `:tada:`, left as written when the name is not one we know. */
|
|
157
|
+
const emoji = {
|
|
158
|
+
name: "emoji",
|
|
159
|
+
level: "inline",
|
|
160
|
+
start(src) {
|
|
161
|
+
const i = src.indexOf(":");
|
|
162
|
+
return i < 0 ? undefined : i;
|
|
163
|
+
},
|
|
164
|
+
tokenizer(src) {
|
|
165
|
+
const m = /^:([a-z0-9_+-]+):/.exec(src);
|
|
166
|
+
if (!m)
|
|
167
|
+
return undefined;
|
|
168
|
+
const glyph = emojiFor(m[1]);
|
|
169
|
+
if (glyph === null)
|
|
170
|
+
return undefined;
|
|
171
|
+
return { type: "emoji", raw: m[0], text: glyph };
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
/* -------------------------------------------------------------- lexers --- */
|
|
175
|
+
const GITHUB = [footnoteDef, footnoteRef, emoji];
|
|
176
|
+
const REDDIT = [spoilerParagraph, spoiler, superscript, redditLink];
|
|
177
|
+
function extensionsFor(flavor) {
|
|
178
|
+
switch (flavor) {
|
|
179
|
+
case "commonmark":
|
|
180
|
+
return [];
|
|
181
|
+
case "github":
|
|
182
|
+
return GITHUB;
|
|
183
|
+
case "reddit":
|
|
184
|
+
return REDDIT;
|
|
185
|
+
case "all":
|
|
186
|
+
return [...GITHUB, ...REDDIT];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const cache = new Map();
|
|
190
|
+
/**
|
|
191
|
+
* The configured marked instance for a flavor. Cached: building one walks every
|
|
192
|
+
* extension, and a resize re-renders the open document as its width changes.
|
|
193
|
+
*/
|
|
194
|
+
export function lexerFor(flavor = DEFAULT_FLAVOR) {
|
|
195
|
+
const hit = cache.get(flavor);
|
|
196
|
+
if (hit)
|
|
197
|
+
return hit;
|
|
198
|
+
const extensions = extensionsFor(flavor);
|
|
199
|
+
const marked = new Marked({ gfm: flavor !== "commonmark", breaks: false });
|
|
200
|
+
if (extensions.length > 0)
|
|
201
|
+
marked.use({ extensions });
|
|
202
|
+
cache.set(flavor, marked);
|
|
203
|
+
return marked;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* A fresh Lexer carrying the flavor's options.
|
|
207
|
+
*
|
|
208
|
+
* `Marked#lexer` is a bound helper, not the lexer itself, and the extension
|
|
209
|
+
* tokenizers need `this.lexer` to recurse — so the Lexer is built here from the
|
|
210
|
+
* instance defaults rather than reached for through the facade.
|
|
211
|
+
*/
|
|
212
|
+
function lexer(flavor) {
|
|
213
|
+
return new Lexer(lexerFor(flavor).defaults);
|
|
214
|
+
}
|
|
215
|
+
/** Block tokens for a source string, under a flavor. */
|
|
216
|
+
export function lex(source, flavor = DEFAULT_FLAVOR) {
|
|
217
|
+
return lexer(flavor).lex(source);
|
|
218
|
+
}
|
|
219
|
+
/** Inline tokens for a fragment, under a flavor. */
|
|
220
|
+
export function lexInline(source, flavor = DEFAULT_FLAVOR) {
|
|
221
|
+
return lexer(flavor).inlineTokens(source);
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=flavors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flavors.js","sourceRoot":"","sources":["../src/flavors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,EAAwE,MAAM,QAAQ,CAAC;AAC7G,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAqDtC,MAAM,CAAC,MAAM,OAAO,GAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;A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C3E,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,CAAC,GAAG,CAAC,EAAE,UAAU,EAAqB,CAAC,CAAC;IACzE,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1B,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,SAAS,KAAK,CAAC,MAAc;IAC3B,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC;AAC9C,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,GAAG,CAAC,MAAc,EAAE,SAAiB,cAAc;IACjE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,MAAM,CAAY,CAAC;AAC9C,CAAC;AAED,oDAAoD;AACpD,MAAM,UAAU,SAAS,CAAC,MAAc,EAAE,SAAiB,cAAc;IACvE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,MAAM,CAAY,CAAC;AACvD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* readm3 — a terminal markdown reader.
|
|
2
|
+
* readm3 — a terminal markdown reader and editor.
|
|
3
3
|
*
|
|
4
|
-
* The renderer
|
|
5
|
-
* pure, and
|
|
4
|
+
* The renderer, the file tree and the edit buffer are exported so they can be
|
|
5
|
+
* reused: all three are pure, and none of them needs a terminal.
|
|
6
6
|
*/
|
|
7
7
|
export { renderMarkdown, parseInline, wrapSpans, mergeSpans, normalizeHtml, plain, toText } from "./markdown.ts";
|
|
8
|
-
export type { Line, Span, Role } from "./markdown.ts";
|
|
8
|
+
export type { Line, Span, Role, RenderOptions } from "./markdown.ts";
|
|
9
|
+
export { FLAVORS, DEFAULT_FLAVOR, isFlavor, lex, lexInline, lexerFor } from "./flavors.ts";
|
|
10
|
+
export type { Flavor } from "./flavors.ts";
|
|
11
|
+
export { EMOJI, emojiFor } from "./emoji.ts";
|
|
12
|
+
export { createEditor, text, lineAt, continuation, insert, newline, backspace, del, killToLineEnd, killToLineStart, indent, undo, redo, breakRun, markSaved, moveLeft, moveRight, moveUp, moveDown, moveVertical, moveHome, moveEnd, moveDocStart, moveDocEnd, moveWordLeft, moveWordRight, } from "./editor.ts";
|
|
13
|
+
export type { Editor, EditKind, Snapshot } from "./editor.ts";
|
|
9
14
|
export { scan, flatten, files, filterTree, matches, reveal, indexOfPath, label, MARKDOWN, DEFAULT_IGNORE, } from "./tree.ts";
|
|
10
15
|
export type { Entry, FlatEntry, ScanOptions } from "./tree.ts";
|
|
11
16
|
export { colorOf } from "./roles.ts";
|
|
@@ -13,6 +18,6 @@ export { printDocument, renderAnsi, styleSpan, colorParams, resolveDepth, resolv
|
|
|
13
18
|
export type { PrintOptions, ColorMode } from "./print.ts";
|
|
14
19
|
export { run } from "./viewer.ts";
|
|
15
20
|
export type { ViewerOptions } from "./viewer.ts";
|
|
16
|
-
export { main, parseArgs, VERSION } from "./cli.ts";
|
|
21
|
+
export { main, parseArgs, USAGE, VERSION } from "./cli.ts";
|
|
17
22
|
export type { ParsedArgs } from "./cli.ts";
|
|
18
23
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACjH,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,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AO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAC3D,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* readm3 — a terminal markdown reader.
|
|
2
|
+
* readm3 — a terminal markdown reader and editor.
|
|
3
3
|
*
|
|
4
|
-
* The renderer
|
|
5
|
-
* pure, and
|
|
4
|
+
* The renderer, the file tree and the edit buffer are exported so they can be
|
|
5
|
+
* reused: all three are pure, and none of them needs a terminal.
|
|
6
6
|
*/
|
|
7
7
|
export { renderMarkdown, parseInline, wrapSpans, mergeSpans, normalizeHtml, plain, toText } from "./markdown.js";
|
|
8
|
+
export { FLAVORS, DEFAULT_FLAVOR, isFlavor, lex, lexInline, lexerFor } from "./flavors.js";
|
|
9
|
+
export { EMOJI, emojiFor } from "./emoji.js";
|
|
10
|
+
export { createEditor, text, lineAt, continuation, insert, newline, backspace, del, killToLineEnd, killToLineStart, indent, undo, redo, breakRun, markSaved, moveLeft, moveRight, moveUp, moveDown, moveVertical, moveHome, moveEnd, moveDocStart, moveDocEnd, moveWordLeft, moveWordRight, } from "./editor.js";
|
|
8
11
|
export { scan, flatten, files, filterTree, matches, reveal, indexOfPath, label, MARKDOWN, DEFAULT_IGNORE, } from "./tree.js";
|
|
9
12
|
export { colorOf } from "./roles.js";
|
|
10
13
|
export { printDocument, renderAnsi, styleSpan, colorParams, resolveDepth, resolveWidth, COLOR_MODES, } from "./print.js";
|
|
11
14
|
export { run } from "./viewer.js";
|
|
12
|
-
export { main, parseArgs, VERSION } from "./cli.js";
|
|
15
|
+
export { main, parseArgs, USAGE, VERSION } from "./cli.js";
|
|
13
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEjH,OAAO,EACL,IAAI,EACJ,OAAO,EACP,KAAK,EACL,UAAU,EACV,OAAO,EACP,MAAM,EACN,WAAW,EACX,KAAK,EACL,QAAQ,EACR,cAAc,GACf,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EACL,aAAa,EACb,UAAU,EACV,SAAS,EACT,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEjH,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE3F,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,IAAI,EACJ,MAAM,EACN,YAAY,EACZ,MAAM,EACN,OAAO,EACP,SAAS,EACT,GAAG,EACH,aAAa,EACb,eAAe,EACf,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,SAAS,EACT,MAAM,EACN,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,aAAa,GACd,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,IAAI,EACJ,OAAO,EACP,KAAK,EACL,UAAU,EACV,OAAO,EACP,MAAM,EACN,WAAW,EACX,KAAK,EACL,QAAQ,EACR,cAAc,GACf,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EACL,aAAa,EACb,UAAU,EACV,SAAS,EACT,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/markdown.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { type Flavor } from "./flavors.ts";
|
|
2
|
+
export type Role = "text" | "h1" | "h2" | "h3" | "code" | "fence" | "gutter" | "lang" | "link" | "url" | "quote" | "bullet" | "rule" | "meta" | "th" | "spoiler" | "sup" | "footnote" | "alert-note" | "alert-tip" | "alert-important" | "alert-warning" | "alert-caution";
|
|
2
3
|
export interface Span {
|
|
3
4
|
text: string;
|
|
4
5
|
role?: Role;
|
|
@@ -6,11 +7,18 @@ export interface Span {
|
|
|
6
7
|
italic?: boolean;
|
|
7
8
|
underline?: boolean;
|
|
8
9
|
dim?: boolean;
|
|
10
|
+
strike?: boolean;
|
|
9
11
|
}
|
|
10
12
|
export interface Line {
|
|
11
13
|
spans: Span[];
|
|
12
14
|
}
|
|
13
15
|
type Style = Omit<Span, "text">;
|
|
16
|
+
export interface RenderOptions {
|
|
17
|
+
/** Which dialect's extras to honor. Defaults to GitHub. */
|
|
18
|
+
flavor?: Flavor | undefined;
|
|
19
|
+
/** Show spoiler text rather than blocking it out. */
|
|
20
|
+
spoilers?: boolean | undefined;
|
|
21
|
+
}
|
|
14
22
|
/**
|
|
15
23
|
* Glue neighbouring spans that share a style back together.
|
|
16
24
|
*
|
|
@@ -29,7 +37,8 @@ export declare function toText(lines: Line[]): string[];
|
|
|
29
37
|
* Inline code is held out of this: `Array<string>` must survive tag stripping.
|
|
30
38
|
*/
|
|
31
39
|
export declare function normalizeHtml(src: string): string;
|
|
32
|
-
|
|
40
|
+
/** Inline markdown to spans. Exported because the site and tests both want it. */
|
|
41
|
+
export declare function parseInline(src: string, base?: Style, options?: RenderOptions): Span[];
|
|
33
42
|
/** Greedy word wrap that carries each word's styling with it. */
|
|
34
43
|
export declare function wrapSpans(spans: Span[], width: number, first?: number, hanging?: number): Line[];
|
|
35
44
|
/**
|
|
@@ -38,6 +47,6 @@ export declare function wrapSpans(spans: Span[], width: number, first?: number,
|
|
|
38
47
|
* `width` is the pane's interior, so a resize re-renders rather than reflows —
|
|
39
48
|
* cheap, and it keeps tables and code gutters honest.
|
|
40
49
|
*/
|
|
41
|
-
export declare function renderMarkdown(source: string, width: number): Line[];
|
|
50
|
+
export declare function renderMarkdown(source: string, width: number, options?: RenderOptions): Line[];
|
|
42
51
|
export {};
|
|
43
52
|
//# sourceMappingURL=markdown.d.ts.map
|
package/dist/markdown.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../src/markdown.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../src/markdown.ts"],"names":[],"mappings":"AAcA,OAAO,EAKL,KAAK,MAAM,EAMZ,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,IAAI,GACZ,MAAM,GACN,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,MAAM,GACN,OAAO,GACP,QAAQ,GACR,MAAM,GACN,MA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