scholarly-parse 0.1.1 → 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 +4 -0
- package/README.md +4 -4
- 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 +116 -114
- package/dist/formats/html/blocks.js.map +1 -1
- package/dist/formats/html/context.d.ts +17 -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 +30 -28
- 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 +207 -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 +11 -13
- 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 +120 -32
- package/dist/formats/jats/blocks.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.js +10 -1
- 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 +6 -4
- package/dist/formats/jats/references.js.map +1 -1
- package/dist/formats/latexml/blocks.d.ts.map +1 -1
- package/dist/formats/latexml/blocks.js +42 -31
- package/dist/formats/latexml/blocks.js.map +1 -1
- package/dist/formats/latexml/context.d.ts +4 -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 +19 -11
- package/dist/formats/latexml/parse.js.map +1 -1
- 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 +32 -1
- 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 +15 -5
- package/dist/formats/pdf/load.d.ts.map +1 -1
- package/dist/formats/pdf/load.js +17 -5
- package/dist/formats/pdf/load.js.map +1 -1
- package/dist/formats/pdf/parse.d.ts +5 -0
- package/dist/formats/pdf/parse.d.ts.map +1 -1
- package/dist/formats/pdf/parse.js +9 -10
- 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 +36 -6
- package/dist/formats/pdf/references.js.map +1 -1
- package/dist/formats/pdf/structure.d.ts +3 -1
- package/dist/formats/pdf/structure.d.ts.map +1 -1
- package/dist/formats/pdf/structure.js +89 -33
- package/dist/formats/pdf/structure.js.map +1 -1
- package/dist/formats/tei/inline.d.ts +4 -1
- package/dist/formats/tei/inline.d.ts.map +1 -1
- package/dist/formats/tei/inline.js +6 -3
- 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 +16 -8
- 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/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/model/document.d.ts +5 -0
- package/dist/model/document.d.ts.map +1 -1
- package/dist/model/doi.d.ts +21 -3
- package/dist/model/doi.d.ts.map +1 -1
- package/dist/model/doi.js +45 -3
- package/dist/model/doi.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/parse.d.ts +2 -0
- package/dist/parse.d.ts.map +1 -1
- 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 +67 -6
- package/dist/render/inline.d.ts.map +1 -1
- package/dist/render/inline.js +243 -9
- package/dist/render/inline.js.map +1 -1
- package/dist/render/markdown.d.ts +14 -9
- package/dist/render/markdown.d.ts.map +1 -1
- package/dist/render/markdown.js +23 -14
- package/dist/render/markdown.js.map +1 -1
- package/dist/render/sections.d.ts +9 -5
- package/dist/render/sections.d.ts.map +1 -1
- package/dist/render/sections.js +20 -15
- package/dist/render/sections.js.map +1 -1
- package/dist/render/text.d.ts +5 -0
- package/dist/render/text.d.ts.map +1 -1
- package/dist/render/text.js +65 -87
- 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 +1 -6
- package/dist/xml/ordered.js.map +1 -1
- package/package.json +1 -1
package/dist/model/doi.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doi.d.ts","sourceRoot":"","sources":["../../src/model/doi.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"doi.d.ts","sourceRoot":"","sources":["../../src/model/doi.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAuBH;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAI1E;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE1D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAIjE;AAcD;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAgBvD"}
|
package/dist/model/doi.js
CHANGED
|
@@ -1,13 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* @fileoverview DOIs as the model holds them: a field's DOI without its resolver or `doi:`
|
|
3
|
+
* prefix, and the first DOI in running text, read in one pass over its runs of DOI
|
|
4
|
+
* characters without the punctuation, quotes, and brackets that close it. JATS and TEI
|
|
5
|
+
* identifier fields and HTML `<meta>` tags normalize here; PDF, HTML, and LaTeXML
|
|
6
|
+
* references read the DOI in an entry's text here, and a PDF's first page reads the DOI
|
|
7
|
+
* a label introduces.
|
|
5
8
|
* @module src/model/doi
|
|
6
9
|
*/
|
|
7
10
|
/** A DOI's `10.` prefix and every character after it that a DOI can hold. */
|
|
8
11
|
const DOI_RUN = /\b10\.\d{4,9}\/[^\s"<>]+/g;
|
|
9
12
|
/** Marks that close a DOI rather than belong to it: a sentence's punctuation, closing quotes. */
|
|
10
13
|
const CLOSING_MARKS = '.,;:"\'”’';
|
|
14
|
+
/** A resolver URL or `doi:` label leading a DOI field's value. */
|
|
15
|
+
const DOI_PREFIX = /^(?:https?:\/\/(?:dx\.|www\.)?doi\.org\/|doi:\s*)/i;
|
|
16
|
+
/** A value that starts as a DOI does: `10.`, a registrant code, and a `/`. */
|
|
17
|
+
const DOI_START = /^10\.\d{4,9}\//;
|
|
18
|
+
/**
|
|
19
|
+
* A label ending right before a DOI: `doi.org/`, `doi:`, or `doi` and a space, then
|
|
20
|
+
* optionally one opening quote. Its whitespace is bounded, so it fits {@link LABEL_WINDOW}.
|
|
21
|
+
*/
|
|
22
|
+
const DOI_LABEL = /\bdoi(?:\.org\/|:\s{0,8}|\s{1,8})["'“‘]?$/i;
|
|
23
|
+
/** How far back from a DOI run its label is looked for: the longest label and the character before it. */
|
|
24
|
+
const LABEL_WINDOW = 14;
|
|
25
|
+
/**
|
|
26
|
+
* A DOI field's value as the model holds it: without a resolver (`https://doi.org/`,
|
|
27
|
+
* `http://dx.doi.org/`) or `doi:` prefix in any case, without the marks closing it
|
|
28
|
+
* ({@link trimDoi}), lowercased. Undefined for a value that is not a DOI (`n/a`, `10.`,
|
|
29
|
+
* `10.1234/`).
|
|
30
|
+
*/
|
|
31
|
+
export function normalizeDoi(value) {
|
|
32
|
+
if (value === undefined)
|
|
33
|
+
return;
|
|
34
|
+
const doi = value.trim().replace(DOI_PREFIX, '');
|
|
35
|
+
return DOI_START.test(doi) ? trimDoi(doi)?.toLowerCase() : undefined;
|
|
36
|
+
}
|
|
11
37
|
/**
|
|
12
38
|
* The first DOI in `text` whose run of DOI characters ends at whitespace, the end of the
|
|
13
39
|
* text, or a quote closing one opened right before it, without the marks closing it
|
|
@@ -16,7 +42,23 @@ const CLOSING_MARKS = '.,;:"\'”’';
|
|
|
16
42
|
* that ends at a quote costs one pass, not one per `10.` inside it.
|
|
17
43
|
*/
|
|
18
44
|
export function doiInText(text) {
|
|
45
|
+
return firstDoi(text, () => true);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The first DOI in `text` that a label introduces, read as {@link doiInText} reads one:
|
|
49
|
+
* its run must follow `doi.org/`, `doi:`, or `doi` and a space (in any case), optionally
|
|
50
|
+
* with one opening quote between (`doi: "10.1234/abc"`, `DOI 10.1234/abc`). A DOI with no
|
|
51
|
+
* label before it is passed over. The label is looked for in a bounded window before each
|
|
52
|
+
* run, so the text is still read in one pass.
|
|
53
|
+
*/
|
|
54
|
+
export function labeledDoiInText(text) {
|
|
55
|
+
return firstDoi(text, (index) => DOI_LABEL.test(text.slice(Math.max(0, index - LABEL_WINDOW), index)));
|
|
56
|
+
}
|
|
57
|
+
/** The first whole DOI run in `text` that `accept`, given where the run starts, takes. */
|
|
58
|
+
function firstDoi(text, accept) {
|
|
19
59
|
for (const { 0: run, index } of text.matchAll(DOI_RUN)) {
|
|
60
|
+
if (!accept(index))
|
|
61
|
+
continue;
|
|
20
62
|
const after = text.charAt(index + run.length);
|
|
21
63
|
const whole = !after || /\s/.test(after) || (after === '"' && text.charAt(index - 1) === '"');
|
|
22
64
|
const doi = whole ? trimDoi(run) : undefined;
|
package/dist/model/doi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doi.js","sourceRoot":"","sources":["../../src/model/doi.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"doi.js","sourceRoot":"","sources":["../../src/model/doi.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,6EAA6E;AAC7E,MAAM,OAAO,GAAG,2BAA2B,CAAC;AAE5C,iGAAiG;AACjG,MAAM,aAAa,GAAG,WAAW,CAAC;AAElC,kEAAkE;AAClE,MAAM,UAAU,GAAG,oDAAoD,CAAC;AAExE,8EAA8E;AAC9E,MAAM,SAAS,GAAG,gBAAgB,CAAC;AAEnC;;;GAGG;AACH,MAAM,SAAS,GAAG,4CAA4C,CAAC;AAE/D,0GAA0G;AAC1G,MAAM,YAAY,GAAG,EAAE,CAAC;AAExB;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,KAAyB;IACpD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO;IAChC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACjD,OAAO,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACvE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,OAAO,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAC9B,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,KAA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zB,IAAI,IAAI,KAAK,GAAG;YAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;aAC9B,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACtC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;gBAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;;gBAC5B,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IACD,IAAI,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC;IACrB,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QAAE,GAAG,EAAE,CAAC;IACjG,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC/B,OAAO,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AAChE,CAAC"}
|
package/dist/model/input.d.ts
CHANGED
|
@@ -11,4 +11,6 @@ export declare function exceedsBudget(input: string | Uint8Array, maxBytes: numb
|
|
|
11
11
|
* A leading byte-order mark is dropped from strings too.
|
|
12
12
|
*/
|
|
13
13
|
export declare function decodeText(input: string | Uint8Array): string;
|
|
14
|
+
/** The encoding a leading byte-order mark names: UTF-8, UTF-16LE, or UTF-16BE. */
|
|
15
|
+
export declare function bomEncoding(bytes: Uint8Array): 'utf-8' | 'utf-16le' | 'utf-16be' | undefined;
|
|
14
16
|
//# sourceMappingURL=input.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/model/input.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,oFAAoF;AACpF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAKnF;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAU7D"}
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/model/input.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,oFAAoF;AACpF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAKnF;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAU7D;AAED,kFAAkF;AAClF,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,CAK5F"}
|
package/dist/model/input.js
CHANGED
|
@@ -30,7 +30,8 @@ export function decodeText(input) {
|
|
|
30
30
|
}
|
|
31
31
|
return decoder.decode(input).replace(/^/, '');
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
/** The encoding a leading byte-order mark names: UTF-8, UTF-16LE, or UTF-16BE. */
|
|
34
|
+
export function bomEncoding(bytes) {
|
|
34
35
|
if (bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf)
|
|
35
36
|
return 'utf-8';
|
|
36
37
|
if (bytes[0] === 0xff && bytes[1] === 0xfe)
|
package/dist/model/input.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../src/model/input.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,oFAAoF;AACpF,MAAM,UAAU,aAAa,CAAC,KAA0B,EAAE,QAAgB;IACxE,IAAI,OAAO,KAAK,KAAK,QA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C,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QACjE,0CAA0C,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAC3D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Bounds on untrusted input that the XML parser (`src/xml/`) and the HTML
|
|
3
|
+
* loader (`src/html/dom.ts`) share, in a module of their own so neither imports the
|
|
4
|
+
* other's module for a constant.
|
|
5
|
+
* @module src/model/limits
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Deepest element nesting accepted. Real articles stay far shallower — body, section,
|
|
9
|
+
* paragraph, and inline markup rarely pass 20 levels, the deepest MathML seen stays
|
|
10
|
+
* under 60, and the deepest HTML fixture nests 39 levels — so this bounds hostile input
|
|
11
|
+
* and the recursive walks over it.
|
|
12
|
+
*/
|
|
13
|
+
export declare const MAX_XML_DEPTH = 256;
|
|
14
|
+
//# sourceMappingURL=limits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../src/model/limits.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,aAAa,MAAM,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Bounds on untrusted input that the XML parser (`src/xml/`) and the HTML
|
|
3
|
+
* loader (`src/html/dom.ts`) share, in a module of their own so neither imports the
|
|
4
|
+
* other's module for a constant.
|
|
5
|
+
* @module src/model/limits
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Deepest element nesting accepted. Real articles stay far shallower — body, section,
|
|
9
|
+
* paragraph, and inline markup rarely pass 20 levels, the deepest MathML seen stays
|
|
10
|
+
* under 60, and the deepest HTML fixture nests 39 levels — so this bounds hostile input
|
|
11
|
+
* and the recursive walks over it.
|
|
12
|
+
*/
|
|
13
|
+
export const MAX_XML_DEPTH = 256;
|
|
14
|
+
//# sourceMappingURL=limits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits.js","sourceRoot":"","sources":["../../src/model/limits.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC"}
|
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Section IDs unique within one document: the source's own ID when it is
|
|
3
|
-
* unused, else a fallback made unique with a numeric suffix.
|
|
3
|
+
* unused, else a fallback made unique with a numeric suffix. The IDs `toSections` gives
|
|
4
|
+
* its entries that are not sections are defined here too, and no section is issued one.
|
|
4
5
|
* @module src/model/section-ids
|
|
5
6
|
*/
|
|
6
|
-
/**
|
|
7
|
+
/** The ID `toSections` gives the abstract at `index` in `document.abstracts`. */
|
|
8
|
+
export declare function abstractId(index: number): string;
|
|
9
|
+
/** The ID `toSections` gives the figures and tables outside any section. */
|
|
10
|
+
export declare const FLOATS_ID = "floats";
|
|
11
|
+
/** The ID `toSections` gives the footnotes. */
|
|
12
|
+
export declare const FOOTNOTES_ID = "footnotes";
|
|
13
|
+
/** The ID `toSections` gives the references. */
|
|
14
|
+
export declare const REFERENCES_ID = "references";
|
|
15
|
+
/**
|
|
16
|
+
* The IDs `toSections` generates: {@link abstractId}'s `abstract-<digits>`,
|
|
17
|
+
* {@link FLOATS_ID}, {@link FOOTNOTES_ID}, and {@link REFERENCES_ID}. A section never
|
|
18
|
+
* takes one, so each entry's ID names that entry alone.
|
|
19
|
+
*/
|
|
20
|
+
export declare const RESERVED_SECTION_ID: RegExp;
|
|
21
|
+
/**
|
|
22
|
+
* Issue an ID into `issued`: `sourceId` when unused, else `fallback` made unique. An ID
|
|
23
|
+
* in the reserved family counts as used, so it takes a suffix of its own: `abstract-1`
|
|
24
|
+
* becomes `abstract-1-2`, and a second `abstract`, whose `abstract-2` is reserved,
|
|
25
|
+
* becomes `abstract-2-2`. A suffixed ID is reserved only when its base is `abstract`, and
|
|
26
|
+
* suffixing that one again leaves the family, so at most two suffixes are added.
|
|
27
|
+
*/
|
|
7
28
|
export declare function issueId(issued: Set<string>, sourceId: string | undefined, fallback: string): string;
|
|
8
29
|
//# sourceMappingURL=section-ids.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"section-ids.d.ts","sourceRoot":"","sources":["../../src/model/section-ids.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"section-ids.d.ts","sourceRoot":"","sources":["../../src/model/section-ids.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,iFAAiF;AACjF,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,4EAA4E;AAC5E,eAAO,MAAM,SAAS,WAAW,CAAC;AAElC,+CAA+C;AAC/C,eAAO,MAAM,YAAY,cAAc,CAAC;AAExC,gDAAgD;AAChD,eAAO,MAAM,aAAa,eAAe,CAAC;AAE1C;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,QAAmD,CAAC;AASpF;;;;;;GAMG;AACH,wBAAgB,OAAO,CACrB,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,EACnB,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,QAAQ,EAAE,MAAM,GACf,MAAM,CAKR"}
|
|
@@ -1,28 +1,53 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Section IDs unique within one document: the source's own ID when it is
|
|
3
|
-
* unused, else a fallback made unique with a numeric suffix.
|
|
3
|
+
* unused, else a fallback made unique with a numeric suffix. The IDs `toSections` gives
|
|
4
|
+
* its entries that are not sections are defined here too, and no section is issued one.
|
|
4
5
|
* @module src/model/section-ids
|
|
5
6
|
*/
|
|
7
|
+
/** The ID `toSections` gives the abstract at `index` in `document.abstracts`. */
|
|
8
|
+
export function abstractId(index) {
|
|
9
|
+
return `abstract-${index + 1}`;
|
|
10
|
+
}
|
|
11
|
+
/** The ID `toSections` gives the figures and tables outside any section. */
|
|
12
|
+
export const FLOATS_ID = 'floats';
|
|
13
|
+
/** The ID `toSections` gives the footnotes. */
|
|
14
|
+
export const FOOTNOTES_ID = 'footnotes';
|
|
15
|
+
/** The ID `toSections` gives the references. */
|
|
16
|
+
export const REFERENCES_ID = 'references';
|
|
17
|
+
/**
|
|
18
|
+
* The IDs `toSections` generates: {@link abstractId}'s `abstract-<digits>`,
|
|
19
|
+
* {@link FLOATS_ID}, {@link FOOTNOTES_ID}, and {@link REFERENCES_ID}. A section never
|
|
20
|
+
* takes one, so each entry's ID names that entry alone.
|
|
21
|
+
*/
|
|
22
|
+
export const RESERVED_SECTION_ID = /^(?:abstract-\d+|floats|footnotes|references)$/;
|
|
6
23
|
/**
|
|
7
24
|
* The next suffix to try for each base, per set of issued IDs, so a document that
|
|
8
25
|
* repeats one ID throughout costs one step per section rather than a search from `-2`
|
|
9
26
|
* each time. A suffix freed by a deleted ID is not reissued; IDs stay unique.
|
|
10
27
|
*/
|
|
11
28
|
const nextSuffix = new WeakMap();
|
|
12
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Issue an ID into `issued`: `sourceId` when unused, else `fallback` made unique. An ID
|
|
31
|
+
* in the reserved family counts as used, so it takes a suffix of its own: `abstract-1`
|
|
32
|
+
* becomes `abstract-1-2`, and a second `abstract`, whose `abstract-2` is reserved,
|
|
33
|
+
* becomes `abstract-2-2`. A suffixed ID is reserved only when its base is `abstract`, and
|
|
34
|
+
* suffixing that one again leaves the family, so at most two suffixes are added.
|
|
35
|
+
*/
|
|
13
36
|
export function issueId(issued, sourceId, fallback) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const suffixes = nextSuffix.get(issued) ?? new Map();
|
|
18
|
-
nextSuffix.set(issued, suffixes);
|
|
19
|
-
let n = suffixes.get(base) ?? 2;
|
|
20
|
-
while (issued.has(`${base}-${n}`))
|
|
21
|
-
n++;
|
|
22
|
-
id = `${base}-${n}`;
|
|
23
|
-
suffixes.set(base, n + 1);
|
|
24
|
-
}
|
|
37
|
+
let id = sourceId || fallback;
|
|
38
|
+
while (issued.has(id) || RESERVED_SECTION_ID.test(id))
|
|
39
|
+
id = suffixed(issued, id);
|
|
25
40
|
issued.add(id);
|
|
26
41
|
return id;
|
|
27
42
|
}
|
|
43
|
+
/** `base` with the first numeric suffix not yet issued. */
|
|
44
|
+
function suffixed(issued, base) {
|
|
45
|
+
const suffixes = nextSuffix.get(issued) ?? new Map();
|
|
46
|
+
nextSuffix.set(issued, suffixes);
|
|
47
|
+
let n = suffixes.get(base) ?? 2;
|
|
48
|
+
while (issued.has(`${base}-${n}`))
|
|
49
|
+
n++;
|
|
50
|
+
suffixes.set(base, n + 1);
|
|
51
|
+
return `${base}-${n}`;
|
|
52
|
+
}
|
|
28
53
|
//# sourceMappingURL=section-ids.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"section-ids.js","sourceRoot":"","sources":["../../src/model/section-ids.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"section-ids.js","sourceRoot":"","sources":["../../src/model/section-ids.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,iFAAiF;AACjF,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,YAAY,KAAK,GAAG,CAAC,EAAE,CAAC;AACjC,CAAC;AAED,4EAA4E;AAC5E,MAAM,CAAC,MAAM,SAAS,GAAG,QAAQ,CAAC;AAElC,+CAA+C;AAC/C,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC;AAExC,gDAAgD;AAChD,MAAM,CAAC,MAAM,aAAa,GAAG,YAAY,CAAC;AAE1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,gDAAgD,CAAC;AAEpF;;;;GAIG;AACH,MAAM,UAAU,GAAG,IAAI,OAAO,EAAoC,CAAC;AAEnE;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CACrB,MAAmB,EACnB,QAA4B,EAC5B,QAAgB;IAEhB,IAAI,EAAE,GAAG,QAAQ,IAAI,QAAQ,CAAC;IAC9B,OAAO,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;QAAE,EAAE,GAAG,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACjF,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACf,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,2DAA2D;AAC3D,SAAS,QAAQ,CAAC,MAAmB,EAAE,IAAY;IACjD,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,GAAG,EAAkB,CAAC;IACrE,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACjC,IAAI,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC;QAAE,CAAC,EAAE,CAAC;IACvC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1B,OAAO,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC;AACxB,CAAC"}
|
package/dist/parse.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface AutoParseOptions extends ParseOptions {
|
|
|
14
14
|
maxTextChars?: number;
|
|
15
15
|
/** Read at most this many text items (PDF). */
|
|
16
16
|
maxTextItems?: number;
|
|
17
|
+
/** Stop reading at the next page boundary once aborted, keeping what was read (PDF). */
|
|
18
|
+
signal?: AbortSignal;
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* Parse a document of any supported format. The format comes from the payload itself
|
package/dist/parse.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAU,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhF,2EAA2E;AAC3E,MAAM,WAAW,gBAAiB,SAAQ,YAAY;IACpD,8FAA8F;IAC9F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,yFAAyF;IACzF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAU,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhF,2EAA2E;AAC3E,MAAM,WAAW,gBAAiB,SAAQ,YAAY;IACpD,8FAA8F;IAC9F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,yFAAyF;IACzF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wFAAwF;IACxF,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAsB,KAAK,CACzB,KAAK,EAAE,MAAM,GAAG,UAAU,EAC1B,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,WAAW,CAAC,CA6BtB"}
|
package/dist/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,MAAM,EAAuC,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,MAAM,EAAuC,MAAM,mBAAmB,CAAC;AAoBhF;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CACzB,KAA0B,EAC1B,OAAO,GAAqB,EAAE;IAE9B,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,aAAa,EAAE,GAAG,SAAS,EAAE,GAAG,OAAO,CAAC;IACjF,MAAM,MAAM,GAAG,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC;IACpE,MAAM,OAAO,GAAG,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,CAAC;IACxE,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,MAAM;YACT,OAAO,CAAC,MAAM,MAAM,CAAC,yBAAyB,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC5E,KAAK,KAAK;YACR,OAAO,CAAC,MAAM,MAAM,CAAC,wBAAwB,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC1E,KAAK,SAAS;YACZ,OAAO,CAAC,MAAM,MAAM,CAAC,4BAA4B,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACnF,KAAK,MAAM;YACT,OAAO,CAAC,MAAM,MAAM,CAAC,yBAAyB,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC7E,KAAK,KAAK;YACR,IAAI,OAAO,KAAK,KAAK,QAAQ;gBAC3B,OAAO,MAAM,CACX,cAAc,EACd,qEAAqE,CACtE,CAAC;YACJ,OAAO,CAAC,MAAM,MAAM,CAAC,wBAAwB,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE;gBAC9D,GAAG,MAAM;gBACT,GAAG,SAAS;aACb,CAAC,CAAC;QACL,KAAK,SAAS;YACZ,OAAO,MAAM,CACX,cAAc,EACd,kFAAkF,CACnF,CAAC;IACN,CAAC;AACH,CAAC"}
|
package/dist/render/escape.d.ts
CHANGED
|
@@ -17,6 +17,11 @@
|
|
|
17
17
|
* - `<` — only before a letter, `/`, `!`, or `?`, where it could open an HTML tag.
|
|
18
18
|
* - `&` — only where it would read as an entity reference.
|
|
19
19
|
*
|
|
20
|
+
* Readers join the escaped text of adjacent elements, so the text's end is closed as if
|
|
21
|
+
* anything could follow it, as the `_` rule already does: a trailing `\` is doubled, and
|
|
22
|
+
* a trailing `<`, `!` (an image's opener), or `&` with a partial entity name is escaped.
|
|
23
|
+
* A `](` split across two pieces is left to `joinInlineSeams`.
|
|
24
|
+
*
|
|
20
25
|
* Soft hyphens are dropped: they only mark where a word may break.
|
|
21
26
|
*/
|
|
22
27
|
export declare function escapeInline(text: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"escape.d.ts","sourceRoot":"","sources":["../../src/render/escape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH
|
|
1
|
+
{"version":3,"file":"escape.d.ts","sourceRoot":"","sources":["../../src/render/escape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAWjD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQrD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,sFAAsF;AACtF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,oFAAoF;AACpF,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,SAAI,GAAG,MAAM,CAG3D;AAED,6EAA6E;AAC7E,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI7C;AAKD,iEAAiE;AACjE,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE9C;AAKD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C"}
|
package/dist/render/escape.js
CHANGED
|
@@ -20,17 +20,24 @@ const ESCAPABLE_AFTER_BACKSLASH = /\\(?=[!-/:-@[-`{-~])/g;
|
|
|
20
20
|
* - `<` — only before a letter, `/`, `!`, or `?`, where it could open an HTML tag.
|
|
21
21
|
* - `&` — only where it would read as an entity reference.
|
|
22
22
|
*
|
|
23
|
+
* Readers join the escaped text of adjacent elements, so the text's end is closed as if
|
|
24
|
+
* anything could follow it, as the `_` rule already does: a trailing `\` is doubled, and
|
|
25
|
+
* a trailing `<`, `!` (an image's opener), or `&` with a partial entity name is escaped.
|
|
26
|
+
* A `](` split across two pieces is left to `joinInlineSeams`.
|
|
27
|
+
*
|
|
23
28
|
* Soft hyphens are dropped: they only mark where a word may break.
|
|
24
29
|
*/
|
|
25
30
|
export function escapeInline(text) {
|
|
26
31
|
return text
|
|
27
32
|
.replace(/\u00AD/g, '')
|
|
28
33
|
.replace(ESCAPABLE_AFTER_BACKSLASH, '\\\\')
|
|
34
|
+
.replace(/\\$/, '\\\\')
|
|
29
35
|
.replace(/[*`$~]/g, '\\$&')
|
|
30
36
|
.replace(/(^|[^\p{L}\p{N}])_|_(?=$|[^\p{L}\p{N}])/gu, (match) => match.replace('_', '\\_'))
|
|
31
37
|
.replace(/\]\(/g, '\\](')
|
|
32
|
-
.replace(/<(?=[A-Za-z/!?])/g, '\\<')
|
|
33
|
-
.replace(
|
|
38
|
+
.replace(/<(?=[A-Za-z/!?]|$)/g, '\\<')
|
|
39
|
+
.replace(/!$/, '\\!')
|
|
40
|
+
.replace(/&(?=#?[A-Za-z0-9]+;|#?[A-Za-z0-9]*$)/g, '\\&');
|
|
34
41
|
}
|
|
35
42
|
/**
|
|
36
43
|
* Escape a character sequence that would change meaning at the start of a block:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"escape.js","sourceRoot":"","sources":["../../src/render/escape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,iEAAiE;AACjE,MAAM,yBAAyB,GAAG,uBAAuB,CAAC;AAE1D
|
|
1
|
+
{"version":3,"file":"escape.js","sourceRoot":"","sources":["../../src/render/escape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,iEAAiE;AACjE,MAAM,yBAAyB,GAAG,uBAAuB,CAAC;AAE1D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,IAAI;SACR,OAAO,CAAC,SAAS,EAAE,EAAE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EjF;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;AACzF,CAAC"}
|
package/dist/render/inline.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ export declare function emphasis(markdown: string, marker: string): string;
|
|
|
7
7
|
/**
|
|
8
8
|
* A superscript. Citation numbers become a bracketed marker (`[12,13]`), so they do not
|
|
9
9
|
* fuse with the word before them; anything else uses TeX-style notation (`10^{-5}`,
|
|
10
|
-
* `x^2`) that stays readable as plain text.
|
|
10
|
+
* `x^2`) that stays readable as plain text. A marker's text is escaped like any source
|
|
11
|
+
* text.
|
|
11
12
|
*
|
|
12
13
|
* `isCitation` is the parser's judgment that the superscript holds only citation links;
|
|
13
14
|
* an unlinked run of several citation numbers is recognized from its text.
|
|
@@ -18,7 +19,8 @@ export declare function subscript(markdown: string, plain: string): string;
|
|
|
18
19
|
/**
|
|
19
20
|
* A link. An unsafe scheme (`javascript:`, `data:`) renders as its text only, or as the
|
|
20
21
|
* target as escaped text when there is none; a link whose text is its own URL renders as
|
|
21
|
-
* an autolink.
|
|
22
|
+
* an autolink. A bracket in the text with no partner is escaped, so the link's own
|
|
23
|
+
* brackets enclose the whole text.
|
|
22
24
|
*/
|
|
23
25
|
export declare function link(markdown: string, url: string | undefined): string;
|
|
24
26
|
/**
|
|
@@ -28,12 +30,71 @@ export declare function link(markdown: string, url: string | undefined): string;
|
|
|
28
30
|
export declare const FORMULA_IMAGE = "[formula]";
|
|
29
31
|
/** Inline math: `$tex$`. Empty TeX renders nothing. */
|
|
30
32
|
export declare function inlineMath(tex: string): string;
|
|
33
|
+
/** ASCII punctuation, which a backslash escapes. */
|
|
34
|
+
export declare const ESCAPABLE: RegExp;
|
|
31
35
|
/**
|
|
32
|
-
* Inline Markdown
|
|
33
|
-
*
|
|
34
|
-
*
|
|
36
|
+
* Inline Markdown assembled from separately escaped pieces, with the seams between them
|
|
37
|
+
* repaired: the escaping of each piece cannot see what the next one adds.
|
|
38
|
+
*
|
|
39
|
+
* - Touching inline formulas join into one (`$a$$b$` would read as a display-math
|
|
40
|
+
* delimiter), with a space where the TeX at the joint would open an HTML tag or a link,
|
|
41
|
+
* as `escapeTex` writes it. Source text never yields `$$` (its dollar signs are
|
|
42
|
+
* escaped), so every `$$` is such a seam.
|
|
43
|
+
* - A `](` that `link` did not write, one not followed by a web or mail destination, is
|
|
44
|
+
* escaped, so no link forms with any other destination.
|
|
45
|
+
* - A `!` before a link is escaped, so the link does not read as an image.
|
|
46
|
+
*
|
|
47
|
+
* Code spans, autolinks, and link destinations are left as written, and a backslash
|
|
48
|
+
* escapes only the one character after it, so an escaped backslash escapes nothing. The
|
|
49
|
+
* text is read once, plus once more when it holds a `![`.
|
|
50
|
+
*/
|
|
51
|
+
export declare function joinInlineSeams(markdown: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* Inline Markdown as one finished run: whitespace collapsed and trimmed, then the seams
|
|
54
|
+
* between its separately escaped pieces repaired ({@link joinInlineSeams}).
|
|
55
|
+
*/
|
|
56
|
+
export declare function collapseInline(markdown: string): string;
|
|
57
|
+
/**
|
|
58
|
+
* Each `[` paired with its `]` as CommonMark pairs them, in one pass: a bracket a
|
|
59
|
+
* backslash escapes, or one inside a code span or an autolink, does not count, and nested
|
|
60
|
+
* pairs balance on a stack. Inline math gets no special treatment, as in CommonMark,
|
|
61
|
+
* unless `skipMath` asks for `$…$` to be read as a span too, as `stripInline` reads it.
|
|
62
|
+
* `pairs` maps each paired `[` to its `]`; `unpaired` holds the rest, in ascending order.
|
|
63
|
+
*/
|
|
64
|
+
export declare function pairBrackets(markdown: string, { skipMath }?: {
|
|
65
|
+
skipMath?: boolean;
|
|
66
|
+
}): {
|
|
67
|
+
pairs: Map<number, number>;
|
|
68
|
+
unpaired: number[];
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* The backtick run at `start`, and the code span it opens: `content` is undefined, and
|
|
72
|
+
* `end` the end of the run, when no run of its length closes it.
|
|
73
|
+
*/
|
|
74
|
+
export declare function codeSpanAt(markdown: string, start: number, codeSpanEnd: (length: number, from: number) => number | undefined): {
|
|
75
|
+
content?: string;
|
|
76
|
+
end: number;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* A finder of code-span closers for `markdown`: the start of the first run of exactly
|
|
80
|
+
* `length` backticks at or after `from`, which a run of that length opening before
|
|
81
|
+
* `from` closes. Runs are found once, and the search for each length only moves forward,
|
|
82
|
+
* as the text is read.
|
|
83
|
+
*/
|
|
84
|
+
export declare function codeSpanCloser(markdown: string): (length: number, from: number) => number | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* The first `$` at or after `from` that no odd run of backslashes escapes, counting none
|
|
87
|
+
* before `from`, or -1. When there is none, there is none after a later `$` either.
|
|
88
|
+
*/
|
|
89
|
+
export declare function unescapedDollar(markdown: string, from: number): number;
|
|
90
|
+
/**
|
|
91
|
+
* An autolink at `start`: its target up to the next `>`, which no `<` comes before (a
|
|
92
|
+
* written URL has its angle brackets percent-encoded).
|
|
35
93
|
*/
|
|
36
|
-
export declare function
|
|
94
|
+
export declare function autolinkAt(markdown: string, start: number): {
|
|
95
|
+
end: number;
|
|
96
|
+
target: string;
|
|
97
|
+
} | undefined;
|
|
37
98
|
/** Inline code. */
|
|
38
99
|
export declare function inlineCode(text: string): string;
|
|
39
100
|
//# sourceMappingURL=inline.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inline.d.ts","sourceRoot":"","sources":["../../src/render/inline.ts"],"names":[],"mappings":"AAQA;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAKjE;AAQD
|
|
1
|
+
{"version":3,"file":"inline.d.ts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