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
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
* the M−1 rows below, repeating its text: the value belongs to each position it covers,
|
|
8
8
|
* and keeping the source cell count would put values under the wrong headers.
|
|
9
9
|
* (pubmed-mcp-server#111)
|
|
10
|
+
*
|
|
11
|
+
* The grids of one document draw on one {@link GridBudget}: what the tables of a document
|
|
12
|
+
* may repeat and hold is capped where the grid is built, where a parser can still record
|
|
13
|
+
* what it cut.
|
|
10
14
|
* @module src/model/table-grid
|
|
11
15
|
*/
|
|
12
16
|
/**
|
|
@@ -15,6 +19,41 @@
|
|
|
15
19
|
* bounded row instead of an unbounded allocation.
|
|
16
20
|
*/
|
|
17
21
|
export declare const MAX_TABLE_COLUMNS = 512;
|
|
22
|
+
/**
|
|
23
|
+
* Characters the tables of one document may repeat from a spanned cell into the other
|
|
24
|
+
* positions it covers. Past it, a covered position is empty; the cell's own position
|
|
25
|
+
* keeps its text. The most any corpus document repeats is about a thousand.
|
|
26
|
+
*/
|
|
27
|
+
export declare const MAX_SPAN_COPY_CHARS = 1000000;
|
|
28
|
+
/**
|
|
29
|
+
* Grid cells the tables of one document may hold together, padding included. Past it, a
|
|
30
|
+
* table's remaining rows are dropped. The largest corpus document holds under a thousand;
|
|
31
|
+
* a supplementary table of 500,000 rows by two columns fits whole.
|
|
32
|
+
*/
|
|
33
|
+
export declare const MAX_GRID_CELLS = 2000000;
|
|
34
|
+
/** What the tables of one document may still spend. Every grid built for the document draws on it. */
|
|
35
|
+
export interface GridBudget {
|
|
36
|
+
/** Grid cells left. */
|
|
37
|
+
cells: number;
|
|
38
|
+
/** Characters left for copies of spanned cells. */
|
|
39
|
+
copyChars: number;
|
|
40
|
+
}
|
|
41
|
+
/** A fresh budget for one document. */
|
|
42
|
+
export declare function createGridBudget(): GridBudget;
|
|
43
|
+
/**
|
|
44
|
+
* What a warning calls a table: its label when the label names it ("Table 2"), else
|
|
45
|
+
* `Table` and the bare number or the id.
|
|
46
|
+
*/
|
|
47
|
+
export declare function tableName(label: string | undefined, id?: string): string;
|
|
48
|
+
/** The `truncated-input` warning for a grid the budget cut, naming its table. */
|
|
49
|
+
export declare function truncatedGridMessage(name: string): string;
|
|
50
|
+
/** A built grid. */
|
|
51
|
+
export interface Grid {
|
|
52
|
+
headerRows: number;
|
|
53
|
+
rows: string[][];
|
|
54
|
+
/** The budget ran out while this grid was built: some copies are empty, or rows were dropped. */
|
|
55
|
+
truncated: boolean;
|
|
56
|
+
}
|
|
18
57
|
export interface SourceCell {
|
|
19
58
|
colspan: number;
|
|
20
59
|
header: boolean;
|
|
@@ -29,12 +68,10 @@ export interface SourceRow {
|
|
|
29
68
|
/** A span attribute value, clamped to the grid; anything unparseable is 1. */
|
|
30
69
|
export declare function spanValue(raw: string | null | undefined): number;
|
|
31
70
|
/**
|
|
32
|
-
* Build the grid
|
|
33
|
-
* cells; a row the source left short is padded so cells
|
|
34
|
-
* column.
|
|
71
|
+
* Build the grid, charging the document's `budget`. Header rows are head rows plus any
|
|
72
|
+
* leading row made only of header cells; a row the source left short is padded so cells
|
|
73
|
+
* never shift under the wrong column. Rows are kept in order while the grid, padded to
|
|
74
|
+
* its widest row so far, fits the cells left.
|
|
35
75
|
*/
|
|
36
|
-
export declare function buildGrid(sourceRows: SourceRow[]):
|
|
37
|
-
headerRows: number;
|
|
38
|
-
rows: string[][];
|
|
39
|
-
};
|
|
76
|
+
export declare function buildGrid(sourceRows: SourceRow[], budget: GridBudget): Grid;
|
|
40
77
|
//# sourceMappingURL=table-grid.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-grid.d.ts","sourceRoot":"","sources":["../../src/model/table-grid.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"table-grid.d.ts","sourceRoot":"","sources":["../../src/model/table-grid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,UAAY,CAAC;AAE7C;;;;GAIG;AACH,eAAO,MAAM,cAAc,UAAY,CAAC;AAExC,sGAAsG;AACtG,MAAM,WAAW,UAAU;IACzB,uBAAuB;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,uCAAuC;AACvC,wBAAgB,gBAAgB,IAAI,UAAU,CAE7C;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAExE;AAED,iFAAiF;AACjF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,oBAAoB;AACpB,MAAM,WAAW,IAAI;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;IACjB,iGAAiG;IACjG,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,kDAAkD;IAClD,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,8EAA8E;AAC9E,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAIhE;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CA2D3E"}
|
package/dist/model/table-grid.js
CHANGED
|
@@ -7,15 +7,45 @@
|
|
|
7
7
|
* the M−1 rows below, repeating its text: the value belongs to each position it covers,
|
|
8
8
|
* and keeping the source cell count would put values under the wrong headers.
|
|
9
9
|
* (pubmed-mcp-server#111)
|
|
10
|
+
*
|
|
11
|
+
* The grids of one document draw on one {@link GridBudget}: what the tables of a document
|
|
12
|
+
* may repeat and hold is capped where the grid is built, where a parser can still record
|
|
13
|
+
* what it cut.
|
|
10
14
|
* @module src/model/table-grid
|
|
11
15
|
*/
|
|
12
|
-
import { largest } from './extremes.js';
|
|
13
16
|
/**
|
|
14
17
|
* Widest grid a row may occupy, and the ceiling every declared span is clamped to. The
|
|
15
18
|
* widest real row observed is 15 columns; the cap turns `colspan="99999999"` into a
|
|
16
19
|
* bounded row instead of an unbounded allocation.
|
|
17
20
|
*/
|
|
18
21
|
export const MAX_TABLE_COLUMNS = 512;
|
|
22
|
+
/**
|
|
23
|
+
* Characters the tables of one document may repeat from a spanned cell into the other
|
|
24
|
+
* positions it covers. Past it, a covered position is empty; the cell's own position
|
|
25
|
+
* keeps its text. The most any corpus document repeats is about a thousand.
|
|
26
|
+
*/
|
|
27
|
+
export const MAX_SPAN_COPY_CHARS = 1_000_000;
|
|
28
|
+
/**
|
|
29
|
+
* Grid cells the tables of one document may hold together, padding included. Past it, a
|
|
30
|
+
* table's remaining rows are dropped. The largest corpus document holds under a thousand;
|
|
31
|
+
* a supplementary table of 500,000 rows by two columns fits whole.
|
|
32
|
+
*/
|
|
33
|
+
export const MAX_GRID_CELLS = 2_000_000;
|
|
34
|
+
/** A fresh budget for one document. */
|
|
35
|
+
export function createGridBudget() {
|
|
36
|
+
return { cells: MAX_GRID_CELLS, copyChars: MAX_SPAN_COPY_CHARS };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* What a warning calls a table: its label when the label names it ("Table 2"), else
|
|
40
|
+
* `Table` and the bare number or the id.
|
|
41
|
+
*/
|
|
42
|
+
export function tableName(label, id) {
|
|
43
|
+
return label && /^\p{L}/u.test(label) ? label : `Table ${label ?? id ?? ''}`.trim();
|
|
44
|
+
}
|
|
45
|
+
/** The `truncated-input` warning for a grid the budget cut, naming its table. */
|
|
46
|
+
export function truncatedGridMessage(name) {
|
|
47
|
+
return `${name} exceeds the document's table budget: copies of spanned cells past it are empty, and rows past it dropped`;
|
|
48
|
+
}
|
|
19
49
|
/** A span attribute value, clamped to the grid; anything unparseable is 1. */
|
|
20
50
|
export function spanValue(raw) {
|
|
21
51
|
const declared = Number.parseInt(raw ?? '', 10);
|
|
@@ -24,20 +54,31 @@ export function spanValue(raw) {
|
|
|
24
54
|
return Math.min(declared, MAX_TABLE_COLUMNS);
|
|
25
55
|
}
|
|
26
56
|
/**
|
|
27
|
-
* Build the grid
|
|
28
|
-
* cells; a row the source left short is padded so cells
|
|
29
|
-
* column.
|
|
57
|
+
* Build the grid, charging the document's `budget`. Header rows are head rows plus any
|
|
58
|
+
* leading row made only of header cells; a row the source left short is padded so cells
|
|
59
|
+
* never shift under the wrong column. Rows are kept in order while the grid, padded to
|
|
60
|
+
* its widest row so far, fits the cells left.
|
|
30
61
|
*/
|
|
31
|
-
export function buildGrid(sourceRows) {
|
|
62
|
+
export function buildGrid(sourceRows, budget) {
|
|
32
63
|
const parsed = [];
|
|
33
64
|
const carried = [];
|
|
65
|
+
let truncated = false;
|
|
66
|
+
/** A spanned cell's text for one more position it covers, while the budget lasts. */
|
|
67
|
+
const copy = (text) => {
|
|
68
|
+
if (text.length > budget.copyChars) {
|
|
69
|
+
truncated = true;
|
|
70
|
+
return '';
|
|
71
|
+
}
|
|
72
|
+
budget.copyChars -= text.length;
|
|
73
|
+
return text;
|
|
74
|
+
};
|
|
34
75
|
const drainCarried = (row, col) => {
|
|
35
76
|
let at = col;
|
|
36
77
|
while (at < MAX_TABLE_COLUMNS) {
|
|
37
78
|
const carry = carried[at];
|
|
38
79
|
if (!carry)
|
|
39
80
|
return at;
|
|
40
|
-
row[at] = carry.value;
|
|
81
|
+
row[at] = copy(carry.value);
|
|
41
82
|
carry.remaining -= 1;
|
|
42
83
|
if (carry.remaining <= 0)
|
|
43
84
|
carried[at] = undefined;
|
|
@@ -45,14 +86,15 @@ export function buildGrid(sourceRows) {
|
|
|
45
86
|
}
|
|
46
87
|
return at;
|
|
47
88
|
};
|
|
89
|
+
let width = 0;
|
|
48
90
|
for (const source of sourceRows) {
|
|
49
91
|
const row = [];
|
|
50
92
|
let col = 0;
|
|
51
93
|
for (const cell of source.cells) {
|
|
52
94
|
col = drainCarried(row, col);
|
|
53
|
-
const
|
|
54
|
-
for (let i = 0; i <
|
|
55
|
-
row[col] = cell.text;
|
|
95
|
+
const span = Math.min(cell.colspan, MAX_TABLE_COLUMNS - col);
|
|
96
|
+
for (let i = 0; i < span; i++) {
|
|
97
|
+
row[col] = i === 0 ? cell.text : copy(cell.text);
|
|
56
98
|
if (cell.rowspan > 1)
|
|
57
99
|
carried[col] = { remaining: cell.rowspan - 1, value: cell.text };
|
|
58
100
|
col += 1;
|
|
@@ -63,17 +105,23 @@ export function buildGrid(sourceRows) {
|
|
|
63
105
|
col = carried[col] ? drainCarried(row, col) : col + 1;
|
|
64
106
|
if (source.cells.length === 0)
|
|
65
107
|
continue;
|
|
108
|
+
const widest = Math.max(width, row.length);
|
|
109
|
+
if ((parsed.length + 1) * widest > budget.cells) {
|
|
110
|
+
truncated = true;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
width = widest;
|
|
66
114
|
for (let i = 0; i < row.length; i++)
|
|
67
115
|
row[i] ??= '';
|
|
68
116
|
parsed.push({ cells: row, header: source.inHead || source.cells.every((c) => c.header) });
|
|
69
117
|
}
|
|
70
|
-
|
|
118
|
+
budget.cells -= parsed.length * width;
|
|
71
119
|
for (const row of parsed)
|
|
72
120
|
while (row.cells.length < width)
|
|
73
121
|
row.cells.push('');
|
|
74
122
|
let headerRows = 0;
|
|
75
123
|
while (parsed[headerRows]?.header)
|
|
76
124
|
headerRows++;
|
|
77
|
-
return { headerRows, rows: parsed.map((row) => row.cells) };
|
|
125
|
+
return { headerRows, rows: parsed.map((row) => row.cells), truncated };
|
|
78
126
|
}
|
|
79
127
|
//# sourceMappingURL=table-grid.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-grid.js","sourceRoot":"","sources":["../../src/model/table-grid.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"table-grid.js","sourceRoot":"","sources":["../../src/model/table-grid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAErC;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,SAAS,CAAC;AAE7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC;AAUxC,uCAAuC;AACvC,MAAM,UAAU,gBAAgB;IAC9B,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,mBAAmB,EAAE,CAAC;AACnE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,KAAyB,EAAE,EAAW;IAC9D,OAAO,KAAK,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,KAAK,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;AACtF,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,oBAAoB,CAAC,IAA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|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The characters a string ends with, found by walking back from its end. A
|
|
3
|
+
* pattern anchored only at the end (`/[.,;]+$/`) is tried from every position of a run it
|
|
4
|
+
* does not end, and each try reads to the end of the run, so its time grows with the
|
|
5
|
+
* square of the run. Walking back reads the run once.
|
|
6
|
+
* @module src/model/trailing
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* How many characters before `end` match `char`, a pattern for one character (without
|
|
10
|
+
* the `g` or `y` flag), counted back from `end`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function trailingLength(text: string, char: RegExp, end?: number): number;
|
|
13
|
+
/** `text` without the characters at its end that `char`, a pattern for one character, matches. */
|
|
14
|
+
export declare function trimTrailing(text: string, char: RegExp): string;
|
|
15
|
+
//# sourceMappingURL=trailing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trailing.d.ts","sourceRoot":"","sources":["../../src/model/trailing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,SAAc,GAAG,MAAM,CAIpF;AAED,kGAAkG;AAClG,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/D"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The characters a string ends with, found by walking back from its end. A
|
|
3
|
+
* pattern anchored only at the end (`/[.,;]+$/`) is tried from every position of a run it
|
|
4
|
+
* does not end, and each try reads to the end of the run, so its time grows with the
|
|
5
|
+
* square of the run. Walking back reads the run once.
|
|
6
|
+
* @module src/model/trailing
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* How many characters before `end` match `char`, a pattern for one character (without
|
|
10
|
+
* the `g` or `y` flag), counted back from `end`.
|
|
11
|
+
*/
|
|
12
|
+
export function trailingLength(text, char, end = text.length) {
|
|
13
|
+
let start = end;
|
|
14
|
+
while (start > 0 && char.test(text.charAt(start - 1)))
|
|
15
|
+
start--;
|
|
16
|
+
return end - start;
|
|
17
|
+
}
|
|
18
|
+
/** `text` without the characters at its end that `char`, a pattern for one character, matches. */
|
|
19
|
+
export function trimTrailing(text, char) {
|
|
20
|
+
return text.slice(0, text.length - trailingLength(text, char));
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=trailing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trailing.js","sourceRoot":"","sources":["../../src/model/trailing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,IAAY,EAAE,GAAG,GAAG,IAAI,CAAC,MAAM;IAC1E,IAAI,KAAK,GAAG,GAAG,CAAC;IAChB,OAAO,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAAE,KAAK,EAAE,CAAC;IAC/D,OAAO,GAAG,GAAG,KAAK,CAAC;AACrB,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,IAAY;IACrD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AACjE,CAAC"}
|
package/dist/parse.d.ts
CHANGED
|
@@ -6,8 +6,16 @@ export interface AutoParseOptions extends ParseOptions {
|
|
|
6
6
|
baseUrl?: string;
|
|
7
7
|
/** The format, when the caller knows it: skips detection. */
|
|
8
8
|
format?: SourceFormat;
|
|
9
|
+
/** Read no further page once the pages read hold more than this many operators (PDF). */
|
|
10
|
+
maxOperators?: number;
|
|
9
11
|
/** Read at most this many pages (PDF). */
|
|
10
12
|
maxPages?: number;
|
|
13
|
+
/** Read at most this many characters of text (PDF). */
|
|
14
|
+
maxTextChars?: number;
|
|
15
|
+
/** Read at most this many text items (PDF). */
|
|
16
|
+
maxTextItems?: number;
|
|
17
|
+
/** Stop reading at the next page boundary once aborted, keeping what was read (PDF). */
|
|
18
|
+
signal?: AbortSignal;
|
|
11
19
|
}
|
|
12
20
|
/**
|
|
13
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,0CAA0C;IAC1C,QAAQ,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
CHANGED
|
@@ -12,7 +12,7 @@ import { failed } from './model/result.js';
|
|
|
12
12
|
* PDF needs its bytes: PDF passed as a string fails as `wrong-format`.
|
|
13
13
|
*/
|
|
14
14
|
export async function parse(input, options = {}) {
|
|
15
|
-
const { baseUrl, format = detect(input), maxInputBytes,
|
|
15
|
+
const { baseUrl, format = detect(input), maxInputBytes, ...pdfLimits } = options;
|
|
16
16
|
const budget = maxInputBytes === undefined ? {} : { maxInputBytes };
|
|
17
17
|
const located = baseUrl === undefined ? budget : { ...budget, baseUrl };
|
|
18
18
|
switch (format) {
|
|
@@ -27,7 +27,10 @@ export async function parse(input, options = {}) {
|
|
|
27
27
|
case 'pdf':
|
|
28
28
|
if (typeof input === 'string')
|
|
29
29
|
return failed('wrong-format', 'PDF must be passed as bytes: text decoding loses its binary content');
|
|
30
|
-
return (await import('./formats/pdf/index.js')).parsePdf(input,
|
|
30
|
+
return (await import('./formats/pdf/index.js')).parsePdf(input, {
|
|
31
|
+
...budget,
|
|
32
|
+
...pdfLimits,
|
|
33
|
+
});
|
|
31
34
|
case undefined:
|
|
32
35
|
return failed('wrong-format', 'Not a format this package reads: no PDF header, XML root element, or HTML markup');
|
|
33
36
|
}
|
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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;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,CAAC;SACtB,OAAO,CAAC,yBAAyB,EAAE,MAAM,CAAC;SAC1C,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;SACtB,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC;SAC1B,OAAO,CAAC,2CAA2C,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;SAC1F,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC;SACxB,OAAO,CAAC,qBAAqB,EAAE,KAAK,CAAC;SACrC,OA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whitespace at
|
|
3
3
|
* the edges moves outside the markers, where CommonMark requires it, and empty content
|
|
4
|
-
* renders as itself.
|
|
4
|
+
* renders as itself. The edges are found by trimming, which reads each end once.
|
|
5
5
|
*/
|
|
6
6
|
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,
|
|
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,CAKj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