scholarly-parse 0.1.0 → 0.2.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/CHANGELOG.md +8 -0
- package/README.md +6 -4
- package/changelog/0.1.x/0.1.1.md +41 -0
- package/changelog/0.2.x/0.2.0.md +43 -0
- package/dist/detect.d.ts +3 -2
- package/dist/detect.d.ts.map +1 -1
- package/dist/detect.js +40 -18
- package/dist/detect.js.map +1 -1
- package/dist/formats/html/blocks.d.ts +3 -2
- package/dist/formats/html/blocks.d.ts.map +1 -1
- package/dist/formats/html/blocks.js +128 -123
- package/dist/formats/html/blocks.js.map +1 -1
- package/dist/formats/html/context.d.ts +20 -0
- package/dist/formats/html/context.d.ts.map +1 -1
- package/dist/formats/html/context.js +4 -0
- package/dist/formats/html/context.js.map +1 -1
- package/dist/formats/html/inline.d.ts +7 -6
- package/dist/formats/html/inline.d.ts.map +1 -1
- package/dist/formats/html/inline.js +98 -38
- package/dist/formats/html/inline.js.map +1 -1
- package/dist/formats/html/metadata.d.ts +10 -5
- package/dist/formats/html/metadata.d.ts.map +1 -1
- package/dist/formats/html/metadata.js +41 -16
- package/dist/formats/html/metadata.js.map +1 -1
- package/dist/formats/html/parse.d.ts.map +1 -1
- package/dist/formats/html/parse.js +209 -59
- package/dist/formats/html/parse.js.map +1 -1
- package/dist/formats/html/references.d.ts.map +1 -1
- package/dist/formats/html/references.js +31 -17
- package/dist/formats/html/references.js.map +1 -1
- package/dist/formats/html/subtree.d.ts +112 -0
- package/dist/formats/html/subtree.d.ts.map +1 -0
- package/dist/formats/html/subtree.js +316 -0
- package/dist/formats/html/subtree.js.map +1 -0
- package/dist/formats/jats/blocks.d.ts +4 -1
- package/dist/formats/jats/blocks.d.ts.map +1 -1
- package/dist/formats/jats/blocks.js +129 -38
- package/dist/formats/jats/blocks.js.map +1 -1
- package/dist/formats/jats/context.d.ts +4 -1
- package/dist/formats/jats/context.d.ts.map +1 -1
- package/dist/formats/jats/fragment.d.ts.map +1 -1
- package/dist/formats/jats/fragment.js +2 -0
- package/dist/formats/jats/fragment.js.map +1 -1
- package/dist/formats/jats/front.d.ts.map +1 -1
- package/dist/formats/jats/front.js +12 -5
- package/dist/formats/jats/front.js.map +1 -1
- package/dist/formats/jats/inline.d.ts.map +1 -1
- package/dist/formats/jats/inline.js +23 -4
- package/dist/formats/jats/inline.js.map +1 -1
- package/dist/formats/jats/parse.d.ts.map +1 -1
- package/dist/formats/jats/parse.js +16 -4
- package/dist/formats/jats/parse.js.map +1 -1
- package/dist/formats/jats/references.d.ts.map +1 -1
- package/dist/formats/jats/references.js +95 -24
- package/dist/formats/jats/references.js.map +1 -1
- package/dist/formats/jats/tables.d.ts.map +1 -1
- package/dist/formats/jats/tables.js +14 -9
- package/dist/formats/jats/tables.js.map +1 -1
- package/dist/formats/latexml/blocks.d.ts.map +1 -1
- package/dist/formats/latexml/blocks.js +58 -40
- package/dist/formats/latexml/blocks.js.map +1 -1
- package/dist/formats/latexml/context.d.ts +7 -1
- package/dist/formats/latexml/context.d.ts.map +1 -1
- package/dist/formats/latexml/context.js.map +1 -1
- package/dist/formats/latexml/inline.d.ts +4 -3
- package/dist/formats/latexml/inline.d.ts.map +1 -1
- package/dist/formats/latexml/inline.js +10 -11
- package/dist/formats/latexml/inline.js.map +1 -1
- package/dist/formats/latexml/parse.d.ts.map +1 -1
- package/dist/formats/latexml/parse.js +30 -17
- package/dist/formats/latexml/parse.js.map +1 -1
- package/dist/formats/pdf/blocks.d.ts +2 -1
- package/dist/formats/pdf/blocks.d.ts.map +1 -1
- package/dist/formats/pdf/blocks.js +43 -16
- package/dist/formats/pdf/blocks.js.map +1 -1
- package/dist/formats/pdf/context.d.ts +15 -0
- package/dist/formats/pdf/context.d.ts.map +1 -0
- package/dist/formats/pdf/context.js +2 -0
- package/dist/formats/pdf/context.js.map +1 -0
- package/dist/formats/pdf/inline.d.ts +16 -0
- package/dist/formats/pdf/inline.d.ts.map +1 -1
- package/dist/formats/pdf/inline.js +45 -3
- package/dist/formats/pdf/inline.js.map +1 -1
- package/dist/formats/pdf/layout.d.ts.map +1 -1
- package/dist/formats/pdf/layout.js +39 -10
- package/dist/formats/pdf/layout.js.map +1 -1
- package/dist/formats/pdf/lines.d.ts +7 -1
- package/dist/formats/pdf/lines.d.ts.map +1 -1
- package/dist/formats/pdf/lines.js +17 -1
- package/dist/formats/pdf/lines.js.map +1 -1
- package/dist/formats/pdf/load.d.ts +40 -3
- package/dist/formats/pdf/load.d.ts.map +1 -1
- package/dist/formats/pdf/load.js +132 -46
- package/dist/formats/pdf/load.js.map +1 -1
- package/dist/formats/pdf/parse.d.ts +21 -1
- package/dist/formats/pdf/parse.d.ts.map +1 -1
- package/dist/formats/pdf/parse.js +60 -16
- package/dist/formats/pdf/parse.js.map +1 -1
- package/dist/formats/pdf/references.d.ts.map +1 -1
- package/dist/formats/pdf/references.js +38 -10
- package/dist/formats/pdf/references.js.map +1 -1
- package/dist/formats/pdf/structure.d.ts +4 -6
- package/dist/formats/pdf/structure.d.ts.map +1 -1
- package/dist/formats/pdf/structure.js +91 -35
- package/dist/formats/pdf/structure.js.map +1 -1
- package/dist/formats/tei/inline.d.ts +7 -1
- package/dist/formats/tei/inline.d.ts.map +1 -1
- package/dist/formats/tei/inline.js +20 -11
- package/dist/formats/tei/inline.js.map +1 -1
- package/dist/formats/tei/parse.d.ts.map +1 -1
- package/dist/formats/tei/parse.js +198 -50
- package/dist/formats/tei/parse.js.map +1 -1
- package/dist/html/dom.d.ts +34 -7
- package/dist/html/dom.d.ts.map +1 -1
- package/dist/html/dom.js +459 -1
- package/dist/html/dom.js.map +1 -1
- package/dist/html/interstitial.d.ts.map +1 -1
- package/dist/html/interstitial.js +47 -6
- package/dist/html/interstitial.js.map +1 -1
- package/dist/html/math.d.ts +7 -0
- package/dist/html/math.d.ts.map +1 -0
- package/dist/html/math.js +34 -0
- package/dist/html/math.js.map +1 -0
- package/dist/html/tables.d.ts +13 -8
- package/dist/html/tables.d.ts.map +1 -1
- package/dist/html/tables.js +7 -6
- package/dist/html/tables.js.map +1 -1
- package/dist/model/document.d.ts +5 -0
- package/dist/model/document.d.ts.map +1 -1
- package/dist/model/doi.d.ts +40 -0
- package/dist/model/doi.d.ts.map +1 -0
- package/dist/model/doi.js +98 -0
- package/dist/model/doi.js.map +1 -0
- package/dist/model/extremes.d.ts +7 -3
- package/dist/model/extremes.d.ts.map +1 -1
- package/dist/model/extremes.js +10 -3
- package/dist/model/extremes.js.map +1 -1
- package/dist/model/input.d.ts +2 -0
- package/dist/model/input.d.ts.map +1 -1
- package/dist/model/input.js +2 -1
- package/dist/model/input.js.map +1 -1
- package/dist/model/limits.d.ts +14 -0
- package/dist/model/limits.d.ts.map +1 -0
- package/dist/model/limits.js +14 -0
- package/dist/model/limits.js.map +1 -0
- package/dist/model/section-ids.d.ts +23 -2
- package/dist/model/section-ids.d.ts.map +1 -1
- package/dist/model/section-ids.js +38 -13
- package/dist/model/section-ids.js.map +1 -1
- package/dist/model/table-grid.d.ts +44 -7
- package/dist/model/table-grid.d.ts.map +1 -1
- package/dist/model/table-grid.js +59 -11
- package/dist/model/table-grid.js.map +1 -1
- package/dist/model/trailing.d.ts +15 -0
- package/dist/model/trailing.d.ts.map +1 -0
- package/dist/model/trailing.js +22 -0
- package/dist/model/trailing.js.map +1 -0
- package/dist/parse.d.ts +8 -0
- package/dist/parse.d.ts.map +1 -1
- package/dist/parse.js +5 -2
- package/dist/parse.js.map +1 -1
- package/dist/render/escape.d.ts +5 -0
- package/dist/render/escape.d.ts.map +1 -1
- package/dist/render/escape.js +9 -2
- package/dist/render/escape.js.map +1 -1
- package/dist/render/inline.d.ts +68 -7
- package/dist/render/inline.d.ts.map +1 -1
- package/dist/render/inline.js +249 -13
- package/dist/render/inline.js.map +1 -1
- package/dist/render/markdown.d.ts +41 -7
- package/dist/render/markdown.d.ts.map +1 -1
- package/dist/render/markdown.js +222 -44
- package/dist/render/markdown.js.map +1 -1
- package/dist/render/sections.d.ts +11 -2
- package/dist/render/sections.d.ts.map +1 -1
- package/dist/render/sections.js +25 -6
- package/dist/render/sections.js.map +1 -1
- package/dist/render/text.d.ts +17 -4
- package/dist/render/text.d.ts.map +1 -1
- package/dist/render/text.js +235 -49
- package/dist/render/text.js.map +1 -1
- package/dist/xml/mathml.d.ts +16 -12
- package/dist/xml/mathml.d.ts.map +1 -1
- package/dist/xml/mathml.js +110 -40
- package/dist/xml/mathml.js.map +1 -1
- package/dist/xml/ordered.d.ts +0 -6
- package/dist/xml/ordered.d.ts.map +1 -1
- package/dist/xml/ordered.js +37 -8
- package/dist/xml/ordered.js.map +1 -1
- package/package.json +1 -1
package/dist/render/inline.js
CHANGED
|
@@ -8,12 +8,14 @@ import { codeSpan, escapeInline, escapeTex, escapeUrl, isSafeUrl } from './escap
|
|
|
8
8
|
/**
|
|
9
9
|
* Wrap already-rendered Markdown in an emphasis marker (`*`, `**`, `~~`). Whitespace at
|
|
10
10
|
* the edges moves outside the markers, where CommonMark requires it, and empty content
|
|
11
|
-
* renders as itself.
|
|
11
|
+
* renders as itself. The edges are found by trimming, which reads each end once.
|
|
12
12
|
*/
|
|
13
13
|
export function emphasis(markdown, marker) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const core = markdown.trim();
|
|
15
|
+
if (!core)
|
|
16
|
+
return markdown;
|
|
17
|
+
const lead = markdown.length - markdown.trimStart().length;
|
|
18
|
+
return `${markdown.slice(0, lead)}${marker}${core}${marker}${markdown.slice(lead + core.length)}`;
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* Two or more citation numbers joined by commas or dashes (`12,13`, `4–7`). A single
|
|
@@ -23,7 +25,8 @@ const CITATION_RUN = /^\d+(?:\s*[,\u2012\u2013\u2014-]\s*\d+)+$/;
|
|
|
23
25
|
/**
|
|
24
26
|
* A superscript. Citation numbers become a bracketed marker (`[12,13]`), so they do not
|
|
25
27
|
* fuse with the word before them; anything else uses TeX-style notation (`10^{-5}`,
|
|
26
|
-
* `x^2`) that stays readable as plain text.
|
|
28
|
+
* `x^2`) that stays readable as plain text. A marker's text is escaped like any source
|
|
29
|
+
* text.
|
|
27
30
|
*
|
|
28
31
|
* `isCitation` is the parser's judgment that the superscript holds only citation links;
|
|
29
32
|
* an unlinked run of several citation numbers is recognized from its text.
|
|
@@ -33,7 +36,7 @@ export function superscript(markdown, plain, isCitation) {
|
|
|
33
36
|
if (!text)
|
|
34
37
|
return '';
|
|
35
38
|
if (isCitation || CITATION_RUN.test(text)) {
|
|
36
|
-
return `[${text.replace(/^\[|\]$/g, '').replace(/\s+/g, '')}]`;
|
|
39
|
+
return `[${escapeInline(text.replace(/^\[|\]$/g, '').replace(/\s+/g, ''))}]`;
|
|
37
40
|
}
|
|
38
41
|
return [...text].length === 1 ? `^${markdown.trim()}` : `^{${markdown.trim()}}`;
|
|
39
42
|
}
|
|
@@ -47,7 +50,8 @@ export function subscript(markdown, plain) {
|
|
|
47
50
|
/**
|
|
48
51
|
* A link. An unsafe scheme (`javascript:`, `data:`) renders as its text only, or as the
|
|
49
52
|
* target as escaped text when there is none; a link whose text is its own URL renders as
|
|
50
|
-
* an autolink.
|
|
53
|
+
* an autolink. A bracket in the text with no partner is escaped, so the link's own
|
|
54
|
+
* brackets enclose the whole text.
|
|
51
55
|
*/
|
|
52
56
|
export function link(markdown, url) {
|
|
53
57
|
const target = url?.trim();
|
|
@@ -56,7 +60,26 @@ export function link(markdown, url) {
|
|
|
56
60
|
const text = markdown.trim();
|
|
57
61
|
if (!text || text === target || text === escapeUrlText(target))
|
|
58
62
|
return `<${escapeUrl(target)}>`;
|
|
59
|
-
return `[${text}](${escapeUrl(target)})`;
|
|
63
|
+
return `[${escapeUnpaired(text)}](${escapeUrl(target)})`;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Inline Markdown with a backslash before each bracket that {@link pairBrackets} leaves
|
|
67
|
+
* unpaired. Brackets inside inline math are TeX, so they are left as written.
|
|
68
|
+
*/
|
|
69
|
+
function escapeUnpaired(markdown) {
|
|
70
|
+
return insertBackslashes(markdown, pairBrackets(markdown, { skipMath: true }).unpaired);
|
|
71
|
+
}
|
|
72
|
+
/** `markdown` with a backslash inserted before the character at each of `positions`, in ascending order. */
|
|
73
|
+
function insertBackslashes(markdown, positions) {
|
|
74
|
+
if (positions.length === 0)
|
|
75
|
+
return markdown;
|
|
76
|
+
let out = '';
|
|
77
|
+
let at = 0;
|
|
78
|
+
for (const position of positions) {
|
|
79
|
+
out += `${markdown.slice(at, position)}\\`;
|
|
80
|
+
at = position;
|
|
81
|
+
}
|
|
82
|
+
return out + markdown.slice(at);
|
|
60
83
|
}
|
|
61
84
|
/** How `escapeInline` would have rendered a bare URL, to recognize link text equal to it. */
|
|
62
85
|
function escapeUrlText(url) {
|
|
@@ -72,13 +95,226 @@ export function inlineMath(tex) {
|
|
|
72
95
|
const expression = tex.replace(/\s+/g, ' ').trim();
|
|
73
96
|
return expression ? `$${escapeTex(expression)}$` : '';
|
|
74
97
|
}
|
|
98
|
+
/** What can start a seam to repair, or a span the seam pass leaves alone. */
|
|
99
|
+
const SEAM = /[\\`<$\]]/g;
|
|
100
|
+
/** ASCII punctuation, which a backslash escapes. */
|
|
101
|
+
export const ESCAPABLE = /^[!-/:-@[-`{-~]$/;
|
|
102
|
+
/** A destination `link` writes: a URL with a scheme it allows, then the closing parenthesis. */
|
|
103
|
+
const LINK_DESTINATION = /(?:https?|ftp|mailto):[^\s()]*\)/iy;
|
|
104
|
+
/**
|
|
105
|
+
* Inline Markdown assembled from separately escaped pieces, with the seams between them
|
|
106
|
+
* repaired: the escaping of each piece cannot see what the next one adds.
|
|
107
|
+
*
|
|
108
|
+
* - Touching inline formulas join into one (`$a$$b$` would read as a display-math
|
|
109
|
+
* delimiter), with a space where the TeX at the joint would open an HTML tag or a link,
|
|
110
|
+
* as `escapeTex` writes it. Source text never yields `$$` (its dollar signs are
|
|
111
|
+
* escaped), so every `$$` is such a seam.
|
|
112
|
+
* - A `](` that `link` did not write, one not followed by a web or mail destination, is
|
|
113
|
+
* escaped, so no link forms with any other destination.
|
|
114
|
+
* - A `!` before a link is escaped, so the link does not read as an image.
|
|
115
|
+
*
|
|
116
|
+
* Code spans, autolinks, and link destinations are left as written, and a backslash
|
|
117
|
+
* escapes only the one character after it, so an escaped backslash escapes nothing. The
|
|
118
|
+
* text is read once, plus once more when it holds a `![`.
|
|
119
|
+
*/
|
|
120
|
+
export function joinInlineSeams(markdown) {
|
|
121
|
+
const out = [];
|
|
122
|
+
const codeSpanEnd = codeSpanCloser(markdown);
|
|
123
|
+
const seam = new RegExp(SEAM);
|
|
124
|
+
let at = 0;
|
|
125
|
+
for (let found = seam.exec(markdown); found; found = seam.exec(markdown)) {
|
|
126
|
+
const start = found.index;
|
|
127
|
+
let end = start + 1;
|
|
128
|
+
switch (found[0]) {
|
|
129
|
+
case '\\':
|
|
130
|
+
if (ESCAPABLE.test(markdown.charAt(end)))
|
|
131
|
+
end++;
|
|
132
|
+
break;
|
|
133
|
+
case '`':
|
|
134
|
+
end = codeSpanAt(markdown, start, codeSpanEnd).end;
|
|
135
|
+
break;
|
|
136
|
+
case '<':
|
|
137
|
+
end = autolinkAt(markdown, start)?.end ?? end;
|
|
138
|
+
break;
|
|
139
|
+
case '$':
|
|
140
|
+
if (markdown.charAt(end) === '$') {
|
|
141
|
+
out.push(markdown.slice(at, start), mathJoint(markdown, start));
|
|
142
|
+
at = end = start + 2;
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
default:
|
|
146
|
+
if (markdown.charAt(end) !== '(')
|
|
147
|
+
break;
|
|
148
|
+
LINK_DESTINATION.lastIndex = start + 2;
|
|
149
|
+
if (LINK_DESTINATION.test(markdown)) {
|
|
150
|
+
end = LINK_DESTINATION.lastIndex;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
out.push(markdown.slice(at, start), '\\');
|
|
154
|
+
at = start;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
seam.lastIndex = end;
|
|
158
|
+
}
|
|
159
|
+
out.push(markdown.slice(at));
|
|
160
|
+
const joined = out.join('');
|
|
161
|
+
return joined.includes(' {
|
|
175
|
+
const before = markdown.charAt(at - 1);
|
|
176
|
+
const after = markdown.charAt(at + 2);
|
|
177
|
+
return (before === '<' && /[A-Za-z/!?]/.test(after)) || (before === ']' && after === '(')
|
|
178
|
+
? ' '
|
|
179
|
+
: '';
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Markdown with a backslash before each `!` that would make the link after it an image,
|
|
183
|
+
* its brackets paired as a renderer with math support pairs them or as one without does.
|
|
184
|
+
* Every `](` left in it opens a destination `link` writes.
|
|
185
|
+
*/
|
|
186
|
+
function escapeImageOpeners(markdown) {
|
|
187
|
+
const bangs = new Set();
|
|
188
|
+
for (const skipMath of [false, true]) {
|
|
189
|
+
for (const [open, close] of pairBrackets(markdown, { skipMath }).pairs) {
|
|
190
|
+
if (markdown.charAt(close + 1) === '(' && markdown.charAt(open - 1) === '!') {
|
|
191
|
+
let backslashes = 0;
|
|
192
|
+
while (markdown.charAt(open - 2 - backslashes) === '\\')
|
|
193
|
+
backslashes++;
|
|
194
|
+
if (backslashes % 2 === 0)
|
|
195
|
+
bangs.add(open - 1);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return insertBackslashes(markdown, [...bangs].sort((a, b) => a - b));
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Each `[` paired with its `]` as CommonMark pairs them, in one pass: a bracket a
|
|
203
|
+
* backslash escapes, or one inside a code span or an autolink, does not count, and nested
|
|
204
|
+
* pairs balance on a stack. Inline math gets no special treatment, as in CommonMark,
|
|
205
|
+
* unless `skipMath` asks for `$…$` to be read as a span too, as `stripInline` reads it.
|
|
206
|
+
* `pairs` maps each paired `[` to its `]`; `unpaired` holds the rest, in ascending order.
|
|
207
|
+
*/
|
|
208
|
+
export function pairBrackets(markdown, { skipMath = false } = {}) {
|
|
209
|
+
const pairs = new Map();
|
|
210
|
+
const unpaired = [];
|
|
211
|
+
const open = [];
|
|
212
|
+
const codeSpanEnd = codeSpanCloser(markdown);
|
|
213
|
+
const special = skipMath ? /[\\`<[\]$]/g : /[\\`<[\]]/g;
|
|
214
|
+
let mathCloses = true;
|
|
215
|
+
for (let found = special.exec(markdown); found; found = special.exec(markdown)) {
|
|
216
|
+
const start = found.index;
|
|
217
|
+
let end = start + 1;
|
|
218
|
+
switch (found[0]) {
|
|
219
|
+
case '\\':
|
|
220
|
+
if (ESCAPABLE.test(markdown.charAt(end)))
|
|
221
|
+
end++;
|
|
222
|
+
break;
|
|
223
|
+
case '`':
|
|
224
|
+
end = codeSpanAt(markdown, start, codeSpanEnd).end;
|
|
225
|
+
break;
|
|
226
|
+
case '<':
|
|
227
|
+
end = autolinkAt(markdown, start)?.end ?? end;
|
|
228
|
+
break;
|
|
229
|
+
case '$': {
|
|
230
|
+
const close = mathCloses ? unescapedDollar(markdown, end) : -1;
|
|
231
|
+
if (close === -1)
|
|
232
|
+
mathCloses = false;
|
|
233
|
+
if (close > end)
|
|
234
|
+
end = close + 1;
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
case '[':
|
|
238
|
+
open.push(start);
|
|
239
|
+
break;
|
|
240
|
+
default: {
|
|
241
|
+
const opener = open.pop();
|
|
242
|
+
if (opener === undefined)
|
|
243
|
+
unpaired.push(start);
|
|
244
|
+
else
|
|
245
|
+
pairs.set(opener, start);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
special.lastIndex = end;
|
|
249
|
+
}
|
|
250
|
+
return { pairs, unpaired: [...unpaired, ...open].sort((a, b) => a - b) };
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* The backtick run at `start`, and the code span it opens: `content` is undefined, and
|
|
254
|
+
* `end` the end of the run, when no run of its length closes it.
|
|
255
|
+
*/
|
|
256
|
+
export function codeSpanAt(markdown, start, codeSpanEnd) {
|
|
257
|
+
let open = start + 1;
|
|
258
|
+
while (markdown.charAt(open) === '`')
|
|
259
|
+
open++;
|
|
260
|
+
const close = codeSpanEnd(open - start, open);
|
|
261
|
+
if (close === undefined)
|
|
262
|
+
return { end: open };
|
|
263
|
+
return { content: markdown.slice(open, close), end: close + open - start };
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* A finder of code-span closers for `markdown`: the start of the first run of exactly
|
|
267
|
+
* `length` backticks at or after `from`, which a run of that length opening before
|
|
268
|
+
* `from` closes. Runs are found once, and the search for each length only moves forward,
|
|
269
|
+
* as the text is read.
|
|
270
|
+
*/
|
|
271
|
+
export function codeSpanCloser(markdown) {
|
|
272
|
+
const starts = new Map();
|
|
273
|
+
for (const run of markdown.matchAll(/`+/g)) {
|
|
274
|
+
const list = starts.get(run[0].length);
|
|
275
|
+
if (list)
|
|
276
|
+
list.push(run.index);
|
|
277
|
+
else
|
|
278
|
+
starts.set(run[0].length, [run.index]);
|
|
279
|
+
}
|
|
280
|
+
const next = new Map();
|
|
281
|
+
return (length, from) => {
|
|
282
|
+
const list = starts.get(length) ?? [];
|
|
283
|
+
let i = next.get(length) ?? 0;
|
|
284
|
+
while (i < list.length && (list[i] ?? from) < from)
|
|
285
|
+
i++;
|
|
286
|
+
next.set(length, i);
|
|
287
|
+
return list[i];
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* The first `$` at or after `from` that no odd run of backslashes escapes, counting none
|
|
292
|
+
* before `from`, or -1. When there is none, there is none after a later `$` either.
|
|
293
|
+
*/
|
|
294
|
+
export function unescapedDollar(markdown, from) {
|
|
295
|
+
for (let at = markdown.indexOf('$', from); at !== -1; at = markdown.indexOf('$', at + 1)) {
|
|
296
|
+
let backslashes = 0;
|
|
297
|
+
for (let i = at - 1; i >= from && markdown.charAt(i) === '\\'; i--)
|
|
298
|
+
backslashes++;
|
|
299
|
+
if (backslashes % 2 === 0)
|
|
300
|
+
return at;
|
|
301
|
+
}
|
|
302
|
+
return -1;
|
|
303
|
+
}
|
|
304
|
+
/** An autolink's target: a URL with a scheme `link` writes as one. */
|
|
305
|
+
const AUTOLINK_TARGET = /^(?:https?|ftp|mailto):[\s\S]/i;
|
|
75
306
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* signs are escaped), so every `$$` in inline Markdown is such a seam.
|
|
307
|
+
* An autolink at `start`: its target up to the next `>`, which no `<` comes before (a
|
|
308
|
+
* written URL has its angle brackets percent-encoded).
|
|
79
309
|
*/
|
|
80
|
-
export function
|
|
81
|
-
|
|
310
|
+
export function autolinkAt(markdown, start) {
|
|
311
|
+
const angle = /[<>]/g;
|
|
312
|
+
angle.lastIndex = start + 1;
|
|
313
|
+
const close = angle.exec(markdown);
|
|
314
|
+
if (close?.[0] !== '>')
|
|
315
|
+
return;
|
|
316
|
+
const target = markdown.slice(start + 1, close.index);
|
|
317
|
+
return AUTOLINK_TARGET.test(target) ? { end: close.index + 1, target } : undefined;
|
|
82
318
|
}
|
|
83
319
|
/** Inline code. */
|
|
84
320
|
export function inlineCode(text) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inline.js","sourceRoot":"","sources":["../../src/render/inline.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEtF;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,QAAgB,EAAE,MAAc;IACvD,MAAM,
|
|
1
|
+
{"version":3,"file":"inline.js","sourceRoot":"","sources":["../../src/render/inline.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEtF;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,QAAgB,EAAE,MAAc;IACvD,MAAM,IAAI,GAAG,QAAQ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EAAE,CAAC,CAAC,CAAC,KAAK,GAAG;QAAE,OAAO;IAC/B,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IACtD,OAAO,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACrF,CAAC;AAED,mBAAmB;AACnB,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACpC,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @fileoverview `ScholarlyDocument` → Markdown (CommonMark + GFM tables).
|
|
3
3
|
* @module src/render/markdown
|
|
4
4
|
*/
|
|
5
|
-
import type { Abstract, Block, ScholarlyDocument, Section, SectionKind } from '../model/document.js';
|
|
5
|
+
import type { Abstract, Block, Footnote, Reference, ScholarlyDocument, Section, SectionKind } from '../model/document.js';
|
|
6
6
|
/** What to include when rendering. Everything is included by default. */
|
|
7
7
|
export interface MarkdownOptions {
|
|
8
8
|
/** `main` renders only the main abstract, or the first non-graphical one when none is marked main. */
|
|
@@ -14,8 +14,13 @@ export interface MarkdownOptions {
|
|
|
14
14
|
metadata?: boolean;
|
|
15
15
|
references?: boolean;
|
|
16
16
|
/**
|
|
17
|
-
* Render only these
|
|
18
|
-
*
|
|
17
|
+
* Render only these entries, by the IDs `toSections` returns: `abstract-N` for the Nth
|
|
18
|
+
* abstract, a section's ID for that section, `floats` for the figures and tables
|
|
19
|
+
* outside any section, and `footnotes` and `references` for those lists. An abstract,
|
|
20
|
+
* the floats, the footnotes, or the references render as their `toSections` entry; a
|
|
21
|
+
* section renders as its entry followed by its subsections'. An abstract's own sections
|
|
22
|
+
* can be named by their IDs from the model too. Entries come in reading order, metadata
|
|
23
|
+
* is left out, and the other options are ignored.
|
|
19
24
|
*/
|
|
20
25
|
sections?: string[];
|
|
21
26
|
}
|
|
@@ -23,13 +28,42 @@ export interface MarkdownOptions {
|
|
|
23
28
|
export declare function toMarkdown(document: ScholarlyDocument, options?: MarkdownOptions): string;
|
|
24
29
|
/** An abstract's heading: its own title, else its kind's. */
|
|
25
30
|
export declare function abstractHeading(abstract: Abstract): string;
|
|
31
|
+
/** An abstract as `toSections` lists it: under its heading, which stands even with nothing under it. */
|
|
32
|
+
export declare function abstractMarkdown(abstract: Abstract): string;
|
|
26
33
|
/**
|
|
27
34
|
* A section heading's text: label, then title, else the kind's default where the
|
|
28
35
|
* section opens that kind (an untitled part of a titled appendix is not a new one).
|
|
29
36
|
*/
|
|
30
37
|
export declare function headingText(section: Section, parentKind: SectionKind | undefined): string | undefined;
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Render a section and its subsections, its heading at `level` (capped at 6). `depth`
|
|
40
|
+
* counts the lists, quotes, and boxes around the section (a box can hold sections).
|
|
41
|
+
*/
|
|
42
|
+
export declare function renderSection(section: Section, level: number, parentKind?: SectionKind, depth?: number): string;
|
|
43
|
+
/** Heading over the figures and tables the source places outside any section. */
|
|
44
|
+
export declare const FLOATS_HEADING = "Figures and tables";
|
|
45
|
+
/** The figures and tables outside any section, under their own heading. */
|
|
46
|
+
export declare function renderFloats(floats: Block[]): string;
|
|
47
|
+
/** Heading over the footnotes. */
|
|
48
|
+
export declare const FOOTNOTES_HEADING = "Footnotes";
|
|
49
|
+
/** The footnotes as a list under their own heading, each led by its label. */
|
|
50
|
+
export declare function renderFootnotes(footnotes: Footnote[]): string;
|
|
51
|
+
/** Heading over the references. */
|
|
52
|
+
export declare const REFERENCES_HEADING = "References";
|
|
53
|
+
/** The references as a list under their own heading, each led by its bracketed label. */
|
|
54
|
+
export declare function renderReferences(references: Reference[]): string;
|
|
55
|
+
/**
|
|
56
|
+
* Render blocks separated by blank lines. `depth` counts the lists, quotes, and boxes
|
|
57
|
+
* around them.
|
|
58
|
+
*/
|
|
59
|
+
export declare function renderBlocks(blocks: Block[], depth?: number): string;
|
|
60
|
+
/**
|
|
61
|
+
* Deepest nesting of lists, quotes, and boxes that indents or marks what it holds. The
|
|
62
|
+
* list, quote, or box at this level renders everything inside it at its own prefix: list
|
|
63
|
+
* items deeper still keep their markers at its items' indentation, and deeper quotes and
|
|
64
|
+
* boxes add no `>`. A line's prefix stays within eight levels, and the renderer's stack
|
|
65
|
+
* stays fixed, however deep a document nests. The corpus nests lists two deep at most,
|
|
66
|
+
* and LaTeX's list environments stop at four.
|
|
67
|
+
*/
|
|
68
|
+
export declare const MAX_BLOCK_NESTING = 8;
|
|
35
69
|
//# sourceMappingURL=markdown.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/render/markdown.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EACV,QAAQ,EAER,KAAK,EAEL,iBAAiB,EACjB,OAAO,EACP,WAAW,EAEZ,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/render/markdown.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EACV,QAAQ,EAER,KAAK,EAEL,QAAQ,EAIR,SAAS,EACT,iBAAiB,EACjB,OAAO,EACP,WAAW,EAEZ,MAAM,sBAAsB,CAAC;AAa9B,yEAAyE;AACzE,MAAM,WAAW,eAAe;IAC9B,sGAAsG;IACtG,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;IACpC,4EAA4E;IAC5E,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,uDAAuD;IACvD,QAAQ,CAAC,EAAE,OA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