scholarly-parse 0.1.1 → 0.2.1
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 -6
- package/changelog/0.2.x/0.2.0.md +43 -0
- package/changelog/0.2.x/0.2.1.md +45 -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 +7 -10
- package/dist/formats/html/metadata.d.ts.map +1 -1
- package/dist/formats/html/metadata.js +59 -23
- 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 +15 -31
- 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 +176 -59
- package/dist/formats/jats/blocks.js.map +1 -1
- package/dist/formats/jats/fragment.d.ts +8 -2
- package/dist/formats/jats/fragment.d.ts.map +1 -1
- package/dist/formats/jats/fragment.js +187 -7
- package/dist/formats/jats/fragment.js.map +1 -1
- package/dist/formats/jats/front.d.ts +0 -5
- package/dist/formats/jats/front.d.ts.map +1 -1
- package/dist/formats/jats/front.js +55 -33
- package/dist/formats/jats/front.js.map +1 -1
- package/dist/formats/jats/inline.d.ts +3 -3
- package/dist/formats/jats/inline.d.ts.map +1 -1
- package/dist/formats/jats/inline.js +118 -43
- package/dist/formats/jats/inline.js.map +1 -1
- package/dist/formats/jats/parse.js +43 -6
- package/dist/formats/jats/parse.js.map +1 -1
- package/dist/formats/jats/references.d.ts +0 -5
- package/dist/formats/jats/references.d.ts.map +1 -1
- package/dist/formats/jats/references.js +158 -50
- package/dist/formats/jats/references.js.map +1 -1
- package/dist/formats/jats/text.d.ts +16 -0
- package/dist/formats/jats/text.d.ts.map +1 -1
- package/dist/formats/jats/text.js +77 -1
- package/dist/formats/jats/text.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 +7 -1
- package/dist/formats/latexml/parse.d.ts.map +1 -1
- package/dist/formats/latexml/parse.js +61 -25
- 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 +0 -6
- package/dist/formats/pdf/references.d.ts.map +1 -1
- package/dist/formats/pdf/references.js +44 -8
- 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 +50 -30
- 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/arxiv.d.ts +51 -0
- package/dist/model/arxiv.d.ts.map +1 -0
- package/dist/model/arxiv.js +167 -0
- package/dist/model/arxiv.js.map +1 -0
- package/dist/model/document.d.ts +22 -4
- 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/identifiers.d.ts +32 -0
- package/dist/model/identifiers.d.ts.map +1 -0
- package/dist/model/identifiers.js +61 -0
- package/dist/model/identifiers.js.map +1 -0
- 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 +6 -1
- package/dist/parse.d.ts.map +1 -1
- package/dist/parse.js.map +1 -1
- package/dist/render/bare-url.d.ts +29 -0
- package/dist/render/bare-url.d.ts.map +1 -0
- package/dist/render/bare-url.js +207 -0
- package/dist/render/bare-url.js.map +1 -0
- package/dist/render/escape.d.ts +59 -8
- package/dist/render/escape.d.ts.map +1 -1
- package/dist/render/escape.js +225 -17
- package/dist/render/escape.js.map +1 -1
- package/dist/render/inline.d.ts +53 -9
- package/dist/render/inline.d.ts.map +1 -1
- package/dist/render/inline.js +789 -23
- 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 +39 -18
- package/dist/render/markdown.js.map +1 -1
- package/dist/render/read-inline.d.ts +70 -0
- package/dist/render/read-inline.d.ts.map +1 -0
- package/dist/render/read-inline.js +376 -0
- package/dist/render/read-inline.js.map +1 -0
- package/dist/render/scan.d.ts +54 -0
- package/dist/render/scan.d.ts.map +1 -0
- package/dist/render/scan.js +145 -0
- package/dist/render/scan.js.map +1 -0
- 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 +3 -4
- package/dist/render/text.d.ts.map +1 -1
- package/dist/render/text.js +5 -182
- 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 +111 -20
- package/dist/xml/ordered.js.map +1 -1
- package/dist/xml/well-formed.d.ts +11 -3
- package/dist/xml/well-formed.d.ts.map +1 -1
- package/dist/xml/well-formed.js +25 -7
- package/dist/xml/well-formed.js.map +1 -1
- package/package.json +12 -8
|
@@ -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
|
@@ -2,7 +2,10 @@ import type { SourceFormat } from './model/document.js';
|
|
|
2
2
|
import { type ParseOptions, type ParseResult } from './model/result.js';
|
|
3
3
|
/** Options for {@link parse}. Each applies to the formats that read it. */
|
|
4
4
|
export interface AutoParseOptions extends ParseOptions {
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Where the document was retrieved, so relative links and images resolve (HTML, LaTeXML).
|
|
7
|
+
* An arXiv HTML URL goes without a trailing slash; see `LatexmlOptions.baseUrl`.
|
|
8
|
+
*/
|
|
6
9
|
baseUrl?: string;
|
|
7
10
|
/** The format, when the caller knows it: skips detection. */
|
|
8
11
|
format?: SourceFormat;
|
|
@@ -14,6 +17,8 @@ export interface AutoParseOptions extends ParseOptions {
|
|
|
14
17
|
maxTextChars?: number;
|
|
15
18
|
/** Read at most this many text items (PDF). */
|
|
16
19
|
maxTextItems?: number;
|
|
20
|
+
/** Stop reading at the next page boundary once aborted, keeping what was read (PDF). */
|
|
21
|
+
signal?: AbortSignal;
|
|
17
22
|
}
|
|
18
23
|
/**
|
|
19
24
|
* 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
|
|
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;;;OAGG;IACH,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
|
+
{"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,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"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Where GFM links a bare URL (an autolink literal: `https://…`, `http://…`,
|
|
3
|
+
* `www.…`) in Markdown, read as micromark's GFM extension reads it, so the escaping can
|
|
4
|
+
* tell whether a backslash or a marker it writes would land inside one.
|
|
5
|
+
* @module src/render/bare-url
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* True when a URL starts at `start` of `text`: `http://` or `https://` not right after an
|
|
9
|
+
* ASCII letter, or `www.` at the start or after a space, `(`, `[`, `]`, or an emphasis
|
|
10
|
+
* marker. Brackets around the start are the caller's to weigh: GFM links no bare URL
|
|
11
|
+
* inside a link's text.
|
|
12
|
+
*/
|
|
13
|
+
export declare function bareUrlStarts(text: string, start: number): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* The end of the URL GFM links at `start` of `text`, where {@link bareUrlStarts} holds,
|
|
16
|
+
* or -1 when what follows is no domain. The URL runs to a space or `<`, less any trailing
|
|
17
|
+
* punctuation, an unbalanced `)`, or a character reference (`&`) at its end. Reading
|
|
18
|
+
* stops at `limit`: a URL that runs on past it ends at `limit + 1`. Each character is read
|
|
19
|
+
* a bounded number of times.
|
|
20
|
+
*/
|
|
21
|
+
export declare function bareUrlEnd(text: string, start: number, limit?: number): number;
|
|
22
|
+
/**
|
|
23
|
+
* The end of the autolink literal GFM forms around `at` in `text`, outside link text — a
|
|
24
|
+
* bare URL ({@link bareUrlEnd}) or an email address — or -1 when none holds it. A literal
|
|
25
|
+
* starts no earlier than `from`, where the last one GFM formed ends, and no earlier than
|
|
26
|
+
* the space or `<` before `at`, so only that stretch is read back.
|
|
27
|
+
*/
|
|
28
|
+
export declare function literalEnd(text: string, at: number, from?: number): number;
|
|
29
|
+
//# sourceMappingURL=bare-url.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bare-url.d.ts","sourceRoot":"","sources":["../../src/render/bare-url.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAiBH;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAQlE;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,SAAc,GAAG,MAAM,CA8CnF;AAaD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,SAAI,GAAG,MAAM,CAiBrE"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Where GFM links a bare URL (an autolink literal: `https://…`, `http://…`,
|
|
3
|
+
* `www.…`) in Markdown, read as micromark's GFM extension reads it, so the escaping can
|
|
4
|
+
* tell whether a backslash or a marker it writes would land inside one.
|
|
5
|
+
* @module src/render/bare-url
|
|
6
|
+
*/
|
|
7
|
+
/** Characters a URL gives back to the text around it when only such characters follow, up to a space, `<`, or the end. */
|
|
8
|
+
const TRAIL = new Set(['!', '"', "'", ')', '*', ',', '.', ':', ';', '?', '_', '~']);
|
|
9
|
+
/** Characters at which a URL's path checks whether the rest is a trail it gives back. */
|
|
10
|
+
const PATH_TRAIL = new Set([...TRAIL, '&', '<', ']']);
|
|
11
|
+
/** Characters after which `www.` can start a URL. */
|
|
12
|
+
const BEFORE_WWW = new Set(['', '(', '*', '_', '[', ']', '~', ' ', '\t', '\n', '\r']);
|
|
13
|
+
const PROTOCOL = /https?:\/\//iy;
|
|
14
|
+
const WWW = /www\./iy;
|
|
15
|
+
const ASCII_ALPHA = /^[A-Za-z]$/;
|
|
16
|
+
const SPACE = /^\s$/;
|
|
17
|
+
const PUNCTUATION = /^[\p{P}\p{S}]$/u;
|
|
18
|
+
/**
|
|
19
|
+
* True when a URL starts at `start` of `text`: `http://` or `https://` not right after an
|
|
20
|
+
* ASCII letter, or `www.` at the start or after a space, `(`, `[`, `]`, or an emphasis
|
|
21
|
+
* marker. Brackets around the start are the caller's to weigh: GFM links no bare URL
|
|
22
|
+
* inside a link's text.
|
|
23
|
+
*/
|
|
24
|
+
export function bareUrlStarts(text, start) {
|
|
25
|
+
const before = text.charAt(start - 1);
|
|
26
|
+
if (/[Hh]/.test(text.charAt(start))) {
|
|
27
|
+
PROTOCOL.lastIndex = start;
|
|
28
|
+
return !ASCII_ALPHA.test(before) && PROTOCOL.test(text);
|
|
29
|
+
}
|
|
30
|
+
WWW.lastIndex = start;
|
|
31
|
+
return BEFORE_WWW.has(before) && WWW.test(text) && WWW.lastIndex < text.length;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The end of the URL GFM links at `start` of `text`, where {@link bareUrlStarts} holds,
|
|
35
|
+
* or -1 when what follows is no domain. The URL runs to a space or `<`, less any trailing
|
|
36
|
+
* punctuation, an unbalanced `)`, or a character reference (`&`) at its end. Reading
|
|
37
|
+
* stops at `limit`: a URL that runs on past it ends at `limit + 1`. Each character is read
|
|
38
|
+
* a bounded number of times.
|
|
39
|
+
*/
|
|
40
|
+
export function bareUrlEnd(text, start, limit = text.length) {
|
|
41
|
+
PROTOCOL.lastIndex = start;
|
|
42
|
+
const protocol = PROTOCOL.test(text);
|
|
43
|
+
const domainStart = protocol ? PROTOCOL.lastIndex : start;
|
|
44
|
+
if (protocol) {
|
|
45
|
+
const first = text.charAt(domainStart);
|
|
46
|
+
if (!first || first < ' ' || first === '\u007f' || SPACE.test(first) || PUNCTUATION.test(first))
|
|
47
|
+
return -1;
|
|
48
|
+
}
|
|
49
|
+
const trail = trailReader(text);
|
|
50
|
+
let at = domainStart;
|
|
51
|
+
let seen = false;
|
|
52
|
+
let underscoreInLast = false;
|
|
53
|
+
let underscoreInLastButOne = false;
|
|
54
|
+
for (let c = text.charAt(at);; c = text.charAt(at)) {
|
|
55
|
+
if (c === '.' || c === '_') {
|
|
56
|
+
if (trail(at))
|
|
57
|
+
break;
|
|
58
|
+
if (c === '_') {
|
|
59
|
+
underscoreInLast = true;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
underscoreInLastButOne = underscoreInLast;
|
|
63
|
+
underscoreInLast = false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else if (!c || SPACE.test(c) || (c !== '-' && PUNCTUATION.test(c))) {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
seen = true;
|
|
71
|
+
}
|
|
72
|
+
at++;
|
|
73
|
+
}
|
|
74
|
+
if (!seen || underscoreInLast || underscoreInLastButOne)
|
|
75
|
+
return -1;
|
|
76
|
+
let opened = 0;
|
|
77
|
+
let closed = 0;
|
|
78
|
+
for (let c = text.charAt(at); c && !SPACE.test(c); c = text.charAt(at)) {
|
|
79
|
+
if (at === limit)
|
|
80
|
+
return PATH_TRAIL.has(c) && trail(at) ? at : limit + 1;
|
|
81
|
+
if (c === '(') {
|
|
82
|
+
opened++;
|
|
83
|
+
}
|
|
84
|
+
else if (c === ')' && closed < opened) {
|
|
85
|
+
closed++;
|
|
86
|
+
}
|
|
87
|
+
else if (PATH_TRAIL.has(c)) {
|
|
88
|
+
if (trail(at))
|
|
89
|
+
break;
|
|
90
|
+
if (c === ')')
|
|
91
|
+
closed++;
|
|
92
|
+
}
|
|
93
|
+
at++;
|
|
94
|
+
}
|
|
95
|
+
return at;
|
|
96
|
+
}
|
|
97
|
+
/** Where a bare URL can start, for a search. */
|
|
98
|
+
const URL_START = /https?:\/\/|www\./gi;
|
|
99
|
+
/** A character an email literal's local part holds. */
|
|
100
|
+
const ATEXT = /^[A-Za-z0-9+\-._]$/;
|
|
101
|
+
/** A character an email literal's domain holds, besides its dots. */
|
|
102
|
+
const DOMAIN = /^[A-Za-z0-9\-_]$/;
|
|
103
|
+
const ALPHANUMERIC = /^[A-Za-z0-9]$/;
|
|
104
|
+
/**
|
|
105
|
+
* The end of the autolink literal GFM forms around `at` in `text`, outside link text — a
|
|
106
|
+
* bare URL ({@link bareUrlEnd}) or an email address — or -1 when none holds it. A literal
|
|
107
|
+
* starts no earlier than `from`, where the last one GFM formed ends, and no earlier than
|
|
108
|
+
* the space or `<` before `at`, so only that stretch is read back.
|
|
109
|
+
*/
|
|
110
|
+
export function literalEnd(text, at, from = 0) {
|
|
111
|
+
let wordStart = at;
|
|
112
|
+
while (wordStart > from &&
|
|
113
|
+
!SPACE.test(text.charAt(wordStart - 1)) &&
|
|
114
|
+
text.charAt(wordStart - 1) !== '<')
|
|
115
|
+
wordStart--;
|
|
116
|
+
const start = new RegExp(URL_START);
|
|
117
|
+
start.lastIndex = wordStart;
|
|
118
|
+
for (let found = start.exec(text); found && found.index <= at; found = start.exec(text)) {
|
|
119
|
+
if (!bareUrlStarts(text, found.index))
|
|
120
|
+
continue;
|
|
121
|
+
const end = bareUrlEnd(text, found.index);
|
|
122
|
+
if (end > at)
|
|
123
|
+
return end;
|
|
124
|
+
if (end !== -1)
|
|
125
|
+
start.lastIndex = end;
|
|
126
|
+
}
|
|
127
|
+
return emailEnd(text, at, wordStart);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The end of the email literal GFM forms around `at`, starting no earlier than `from`, or
|
|
131
|
+
* -1: a local part of {@link ATEXT} characters after anything but such a character or a
|
|
132
|
+
* `/`, an `@`, and a domain of {@link DOMAIN} characters holding a dot that an alphanumeric
|
|
133
|
+
* follows, ending in a letter.
|
|
134
|
+
*/
|
|
135
|
+
function emailEnd(text, at, from) {
|
|
136
|
+
let atSign = at;
|
|
137
|
+
while (ATEXT.test(text.charAt(atSign)))
|
|
138
|
+
atSign++;
|
|
139
|
+
if (text.charAt(atSign) !== '@') {
|
|
140
|
+
let domain = at;
|
|
141
|
+
while (domain > from &&
|
|
142
|
+
(DOMAIN.test(text.charAt(domain - 1)) || text.charAt(domain - 1) === '.'))
|
|
143
|
+
domain--;
|
|
144
|
+
if (domain === from || text.charAt(domain - 1) !== '@')
|
|
145
|
+
return -1;
|
|
146
|
+
atSign = domain - 1;
|
|
147
|
+
}
|
|
148
|
+
let local = atSign;
|
|
149
|
+
while (local > from && ATEXT.test(text.charAt(local - 1)))
|
|
150
|
+
local--;
|
|
151
|
+
const before = text.charAt(local - 1);
|
|
152
|
+
if (local === atSign || before === '/' || ATEXT.test(before))
|
|
153
|
+
return -1;
|
|
154
|
+
let end = atSign + 1;
|
|
155
|
+
let dot = false;
|
|
156
|
+
for (;;) {
|
|
157
|
+
const c = text.charAt(end);
|
|
158
|
+
if (c === '.' && ALPHANUMERIC.test(text.charAt(end + 1)))
|
|
159
|
+
dot = true;
|
|
160
|
+
else if (!DOMAIN.test(c))
|
|
161
|
+
break;
|
|
162
|
+
end++;
|
|
163
|
+
}
|
|
164
|
+
return dot && /[A-Za-z]/.test(text.charAt(end - 1)) && end > at ? end : -1;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* A reader of `text` answering whether the characters from a position on are a trail a URL
|
|
168
|
+
* gives back: trailing punctuation and character references up to a space, `<`, or the
|
|
169
|
+
* end, or a `]` before one of those or `(` or `[`. A trail that fails fails from every
|
|
170
|
+
* position up to where it failed, so that stretch is not read again.
|
|
171
|
+
*/
|
|
172
|
+
function trailReader(text) {
|
|
173
|
+
let failedBefore = -1;
|
|
174
|
+
return (from) => {
|
|
175
|
+
if (from < failedBefore)
|
|
176
|
+
return false;
|
|
177
|
+
let at = from;
|
|
178
|
+
for (;;) {
|
|
179
|
+
const c = text.charAt(at);
|
|
180
|
+
if (TRAIL.has(c)) {
|
|
181
|
+
at++;
|
|
182
|
+
}
|
|
183
|
+
else if (c === '&') {
|
|
184
|
+
let end = at + 1;
|
|
185
|
+
while (ASCII_ALPHA.test(text.charAt(end)))
|
|
186
|
+
end++;
|
|
187
|
+
if (end === at + 1 || text.charAt(end) !== ';')
|
|
188
|
+
break;
|
|
189
|
+
at = end + 1;
|
|
190
|
+
}
|
|
191
|
+
else if (c === ']') {
|
|
192
|
+
at++;
|
|
193
|
+
const next = text.charAt(at);
|
|
194
|
+
if (!next || next === '(' || next === '[' || SPACE.test(next))
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
if (!c || c === '<' || SPACE.test(c))
|
|
199
|
+
return true;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
failedBefore = at;
|
|
204
|
+
return false;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=bare-url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bare-url.js","sourceRoot":"","sources":["../../src/render/bare-url.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,0HAA0H;AAC1H,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAEpF,yFAAyF;AACzF,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAEtD,qDAAqD;AACrD,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAA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CAAC;IACf,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/render/escape.d.ts
CHANGED
|
@@ -12,26 +12,67 @@
|
|
|
12
12
|
* Escape source text for use inside inline Markdown.
|
|
13
13
|
*
|
|
14
14
|
* - `\` before punctuation, `*`, `` ` ``, `$` (math delimiter), `~` (GFM strikethrough) — always.
|
|
15
|
-
* - `_` —
|
|
15
|
+
* - `_` — every one in a run that could delimit emphasis; a run with a letter or digit on
|
|
16
|
+
* both sides never can, so `snake_case`, `H_2`, and `foo__bar` stay readable.
|
|
16
17
|
* - `](` — the sequence that would turn bracketed text into a link.
|
|
17
18
|
* - `<` — only before a letter, `/`, `!`, or `?`, where it could open an HTML tag.
|
|
18
19
|
* - `&` — only where it would read as an entity reference.
|
|
20
|
+
* - A bare URL GFM would link (`https://…`, `www.…`) that holds or meets one of those
|
|
21
|
+
* escapes becomes an explicit link to the URL as the source has it, and text that only
|
|
22
|
+
* the escapes would make a URL links nothing ({@link bareUrlReader}).
|
|
23
|
+
*
|
|
24
|
+
* Readers join the escaped text of adjacent elements, so the text's end is closed as if
|
|
25
|
+
* anything could follow it, as the `_` rule already does: a trailing `\` is doubled, and
|
|
26
|
+
* a trailing `<`, `!` (an image's opener), or `&` with a partial entity name is escaped.
|
|
27
|
+
* A `](` split across two pieces, and markup another piece writes after a bare URL, are
|
|
28
|
+
* left to `joinInlineSeams`.
|
|
19
29
|
*
|
|
20
30
|
* Soft hyphens are dropped: they only mark where a word may break.
|
|
21
31
|
*/
|
|
22
32
|
export declare function escapeInline(text: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* {@link escapeInline} without its bare-URL rule, for link text: GFM links no bare URL
|
|
35
|
+
* there, and an explicit link would nest inside the outer one.
|
|
36
|
+
*/
|
|
37
|
+
export declare function escapeText(text: string): string;
|
|
38
|
+
/** A bare URL in Markdown and how to write it: what ends there is the same text. */
|
|
39
|
+
export interface BareUrl {
|
|
40
|
+
end: number;
|
|
41
|
+
written: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A reader of the bare URLs GFM links in `markdown`: given where one may start, whether it
|
|
45
|
+
* does, where it ends, and how to write it. One that holds a backslash escape or markup
|
|
46
|
+
* this package writes (an emphasis marker, a math or code delimiter, or the `[` of a link,
|
|
47
|
+
* at one of `linkOpeners`) is written as an explicit link to the URL GFM would link in the
|
|
48
|
+
* text as the source has it — its escapes undone, up to the first marker — and ends there:
|
|
49
|
+
* an autolink, or for a `www.` URL a link that keeps its text. Any other bare URL is
|
|
50
|
+
* written as it is, to the end GFM gives it. Asked in ascending order, it reads each
|
|
51
|
+
* stretch of the text a bounded number of times.
|
|
52
|
+
*/
|
|
53
|
+
export declare function bareUrlReader(markdown: string, linkOpeners?: ReadonlySet<number>): (start: number) => BareUrl | undefined;
|
|
54
|
+
/** True when an odd run of backslashes ends right before `at`: the last one escapes what follows. */
|
|
55
|
+
export declare function oddBackslashesBefore(markdown: string, at: number): boolean;
|
|
23
56
|
/**
|
|
24
57
|
* Escape a character sequence that would change meaning at the start of a block:
|
|
25
|
-
* an ATX heading, a quote, a list marker
|
|
26
|
-
*
|
|
58
|
+
* an ATX heading, a quote, a list marker (alone on the line too, where it would open an
|
|
59
|
+
* empty item), a tilde code fence, a thematic break, a table row, or a link
|
|
60
|
+
* reference definition, whose label holds no unescaped bracket (a `[` before a link's
|
|
61
|
+
* text that holds `]:` opens no definition, and escaping it would break the link).
|
|
27
62
|
*/
|
|
28
63
|
export declare function escapeBlockStart(text: string): string;
|
|
29
64
|
/**
|
|
30
65
|
* Keep TeX from reading as markup where a Markdown renderer without math support treats
|
|
31
|
-
*
|
|
32
|
-
*
|
|
66
|
+
* it as ordinary text: a `<` that could open an HTML tag and a `](` that could open a link
|
|
67
|
+
* get a space between them, which math mode ignores, and a backtick, which could open a
|
|
68
|
+
* code span, is written `\grave{}` (the accent command `` \` `` as `\grave`), which both
|
|
69
|
+
* KaTeX and MathJax list. For TeX between `$…$` (`inline`), what would end the delimiters
|
|
70
|
+
* early is closed too: a `$` is escaped, and a trailing backslash, which would escape the
|
|
71
|
+
* closing `$`, becomes a control space. Every backslash run is read once.
|
|
33
72
|
*/
|
|
34
|
-
export declare function escapeTex(tex: string
|
|
73
|
+
export declare function escapeTex(tex: string, { inline }?: {
|
|
74
|
+
inline?: boolean;
|
|
75
|
+
}): string;
|
|
35
76
|
/** Escape a value for a GFM table cell: pipes and line breaks would break the row. */
|
|
36
77
|
export declare function escapeTableCell(text: string): string;
|
|
37
78
|
/**
|
|
@@ -46,8 +87,18 @@ export declare function codeSpan(text: string): string;
|
|
|
46
87
|
/** True when `url` is safe to emit as a Markdown link target. */
|
|
47
88
|
export declare function isSafeUrl(url: string): boolean;
|
|
48
89
|
/**
|
|
49
|
-
* Escape a URL for use as
|
|
50
|
-
*
|
|
90
|
+
* Escape a URL for use as an autolink's target, `<…>`: whitespace, control characters,
|
|
91
|
+
* and angle brackets, which an autolink cannot hold, are percent-encoded. Parentheses are
|
|
92
|
+
* left as written.
|
|
93
|
+
*/
|
|
94
|
+
export declare function escapeAutolink(url: string): string;
|
|
95
|
+
/**
|
|
96
|
+
* Escape a URL for use as a Markdown link destination, so the destination holds the URL as
|
|
97
|
+
* written: whitespace, angle brackets, parentheses (an unbalanced one ends the destination),
|
|
98
|
+
* and backticks (one could open a code span across the link) are percent-encoded; a
|
|
99
|
+
* backslash before punctuation or at the end, an `&` that would read as a character
|
|
100
|
+
* reference, and a `$` (which the readers of inline math would pair with another) are
|
|
101
|
+
* escaped.
|
|
51
102
|
*/
|
|
52
103
|
export declare function escapeUrl(url: string): string;
|
|
53
104
|
//# sourceMappingURL=escape.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"escape.d.ts","sourceRoot":"","sources":["../../src/render/escape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"escape.d.ts","sourceRoot":"","sources":["../../src/render/escape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAeH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