scholarly-parse 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +6 -4
- package/changelog/0.1.x/0.1.1.md +41 -0
- package/changelog/0.2.x/0.2.0.md +43 -0
- package/dist/detect.d.ts +3 -2
- package/dist/detect.d.ts.map +1 -1
- package/dist/detect.js +40 -18
- package/dist/detect.js.map +1 -1
- package/dist/formats/html/blocks.d.ts +3 -2
- package/dist/formats/html/blocks.d.ts.map +1 -1
- package/dist/formats/html/blocks.js +128 -123
- package/dist/formats/html/blocks.js.map +1 -1
- package/dist/formats/html/context.d.ts +20 -0
- package/dist/formats/html/context.d.ts.map +1 -1
- package/dist/formats/html/context.js +4 -0
- package/dist/formats/html/context.js.map +1 -1
- package/dist/formats/html/inline.d.ts +7 -6
- package/dist/formats/html/inline.d.ts.map +1 -1
- package/dist/formats/html/inline.js +98 -38
- package/dist/formats/html/inline.js.map +1 -1
- package/dist/formats/html/metadata.d.ts +10 -5
- package/dist/formats/html/metadata.d.ts.map +1 -1
- package/dist/formats/html/metadata.js +41 -16
- package/dist/formats/html/metadata.js.map +1 -1
- package/dist/formats/html/parse.d.ts.map +1 -1
- package/dist/formats/html/parse.js +209 -59
- package/dist/formats/html/parse.js.map +1 -1
- package/dist/formats/html/references.d.ts.map +1 -1
- package/dist/formats/html/references.js +31 -17
- package/dist/formats/html/references.js.map +1 -1
- package/dist/formats/html/subtree.d.ts +112 -0
- package/dist/formats/html/subtree.d.ts.map +1 -0
- package/dist/formats/html/subtree.js +316 -0
- package/dist/formats/html/subtree.js.map +1 -0
- package/dist/formats/jats/blocks.d.ts +4 -1
- package/dist/formats/jats/blocks.d.ts.map +1 -1
- package/dist/formats/jats/blocks.js +129 -38
- package/dist/formats/jats/blocks.js.map +1 -1
- package/dist/formats/jats/context.d.ts +4 -1
- package/dist/formats/jats/context.d.ts.map +1 -1
- package/dist/formats/jats/fragment.d.ts.map +1 -1
- package/dist/formats/jats/fragment.js +2 -0
- package/dist/formats/jats/fragment.js.map +1 -1
- package/dist/formats/jats/front.d.ts.map +1 -1
- package/dist/formats/jats/front.js +12 -5
- package/dist/formats/jats/front.js.map +1 -1
- package/dist/formats/jats/inline.d.ts.map +1 -1
- package/dist/formats/jats/inline.js +23 -4
- package/dist/formats/jats/inline.js.map +1 -1
- package/dist/formats/jats/parse.d.ts.map +1 -1
- package/dist/formats/jats/parse.js +16 -4
- package/dist/formats/jats/parse.js.map +1 -1
- package/dist/formats/jats/references.d.ts.map +1 -1
- package/dist/formats/jats/references.js +95 -24
- package/dist/formats/jats/references.js.map +1 -1
- package/dist/formats/jats/tables.d.ts.map +1 -1
- package/dist/formats/jats/tables.js +14 -9
- package/dist/formats/jats/tables.js.map +1 -1
- package/dist/formats/latexml/blocks.d.ts.map +1 -1
- package/dist/formats/latexml/blocks.js +58 -40
- package/dist/formats/latexml/blocks.js.map +1 -1
- package/dist/formats/latexml/context.d.ts +7 -1
- package/dist/formats/latexml/context.d.ts.map +1 -1
- package/dist/formats/latexml/context.js.map +1 -1
- package/dist/formats/latexml/inline.d.ts +4 -3
- package/dist/formats/latexml/inline.d.ts.map +1 -1
- package/dist/formats/latexml/inline.js +10 -11
- package/dist/formats/latexml/inline.js.map +1 -1
- package/dist/formats/latexml/parse.d.ts.map +1 -1
- package/dist/formats/latexml/parse.js +30 -17
- package/dist/formats/latexml/parse.js.map +1 -1
- package/dist/formats/pdf/blocks.d.ts +2 -1
- package/dist/formats/pdf/blocks.d.ts.map +1 -1
- package/dist/formats/pdf/blocks.js +43 -16
- package/dist/formats/pdf/blocks.js.map +1 -1
- package/dist/formats/pdf/context.d.ts +15 -0
- package/dist/formats/pdf/context.d.ts.map +1 -0
- package/dist/formats/pdf/context.js +2 -0
- package/dist/formats/pdf/context.js.map +1 -0
- package/dist/formats/pdf/inline.d.ts +16 -0
- package/dist/formats/pdf/inline.d.ts.map +1 -1
- package/dist/formats/pdf/inline.js +45 -3
- package/dist/formats/pdf/inline.js.map +1 -1
- package/dist/formats/pdf/layout.d.ts.map +1 -1
- package/dist/formats/pdf/layout.js +39 -10
- package/dist/formats/pdf/layout.js.map +1 -1
- package/dist/formats/pdf/lines.d.ts +7 -1
- package/dist/formats/pdf/lines.d.ts.map +1 -1
- package/dist/formats/pdf/lines.js +17 -1
- package/dist/formats/pdf/lines.js.map +1 -1
- package/dist/formats/pdf/load.d.ts +40 -3
- package/dist/formats/pdf/load.d.ts.map +1 -1
- package/dist/formats/pdf/load.js +132 -46
- package/dist/formats/pdf/load.js.map +1 -1
- package/dist/formats/pdf/parse.d.ts +21 -1
- package/dist/formats/pdf/parse.d.ts.map +1 -1
- package/dist/formats/pdf/parse.js +60 -16
- package/dist/formats/pdf/parse.js.map +1 -1
- package/dist/formats/pdf/references.d.ts.map +1 -1
- package/dist/formats/pdf/references.js +38 -10
- package/dist/formats/pdf/references.js.map +1 -1
- package/dist/formats/pdf/structure.d.ts +4 -6
- package/dist/formats/pdf/structure.d.ts.map +1 -1
- package/dist/formats/pdf/structure.js +91 -35
- package/dist/formats/pdf/structure.js.map +1 -1
- package/dist/formats/tei/inline.d.ts +7 -1
- package/dist/formats/tei/inline.d.ts.map +1 -1
- package/dist/formats/tei/inline.js +20 -11
- package/dist/formats/tei/inline.js.map +1 -1
- package/dist/formats/tei/parse.d.ts.map +1 -1
- package/dist/formats/tei/parse.js +198 -50
- package/dist/formats/tei/parse.js.map +1 -1
- package/dist/html/dom.d.ts +34 -7
- package/dist/html/dom.d.ts.map +1 -1
- package/dist/html/dom.js +459 -1
- package/dist/html/dom.js.map +1 -1
- package/dist/html/interstitial.d.ts.map +1 -1
- package/dist/html/interstitial.js +47 -6
- package/dist/html/interstitial.js.map +1 -1
- package/dist/html/math.d.ts +7 -0
- package/dist/html/math.d.ts.map +1 -0
- package/dist/html/math.js +34 -0
- package/dist/html/math.js.map +1 -0
- package/dist/html/tables.d.ts +13 -8
- package/dist/html/tables.d.ts.map +1 -1
- package/dist/html/tables.js +7 -6
- package/dist/html/tables.js.map +1 -1
- package/dist/model/document.d.ts +5 -0
- package/dist/model/document.d.ts.map +1 -1
- package/dist/model/doi.d.ts +40 -0
- package/dist/model/doi.d.ts.map +1 -0
- package/dist/model/doi.js +98 -0
- package/dist/model/doi.js.map +1 -0
- package/dist/model/extremes.d.ts +7 -3
- package/dist/model/extremes.d.ts.map +1 -1
- package/dist/model/extremes.js +10 -3
- package/dist/model/extremes.js.map +1 -1
- package/dist/model/input.d.ts +2 -0
- package/dist/model/input.d.ts.map +1 -1
- package/dist/model/input.js +2 -1
- package/dist/model/input.js.map +1 -1
- package/dist/model/limits.d.ts +14 -0
- package/dist/model/limits.d.ts.map +1 -0
- package/dist/model/limits.js +14 -0
- package/dist/model/limits.js.map +1 -0
- package/dist/model/section-ids.d.ts +23 -2
- package/dist/model/section-ids.d.ts.map +1 -1
- package/dist/model/section-ids.js +38 -13
- package/dist/model/section-ids.js.map +1 -1
- package/dist/model/table-grid.d.ts +44 -7
- package/dist/model/table-grid.d.ts.map +1 -1
- package/dist/model/table-grid.js +59 -11
- package/dist/model/table-grid.js.map +1 -1
- package/dist/model/trailing.d.ts +15 -0
- package/dist/model/trailing.d.ts.map +1 -0
- package/dist/model/trailing.js +22 -0
- package/dist/model/trailing.js.map +1 -0
- package/dist/parse.d.ts +8 -0
- package/dist/parse.d.ts.map +1 -1
- package/dist/parse.js +5 -2
- package/dist/parse.js.map +1 -1
- package/dist/render/escape.d.ts +5 -0
- package/dist/render/escape.d.ts.map +1 -1
- package/dist/render/escape.js +9 -2
- package/dist/render/escape.js.map +1 -1
- package/dist/render/inline.d.ts +68 -7
- package/dist/render/inline.d.ts.map +1 -1
- package/dist/render/inline.js +249 -13
- package/dist/render/inline.js.map +1 -1
- package/dist/render/markdown.d.ts +41 -7
- package/dist/render/markdown.d.ts.map +1 -1
- package/dist/render/markdown.js +222 -44
- package/dist/render/markdown.js.map +1 -1
- package/dist/render/sections.d.ts +11 -2
- package/dist/render/sections.d.ts.map +1 -1
- package/dist/render/sections.js +25 -6
- package/dist/render/sections.js.map +1 -1
- package/dist/render/text.d.ts +17 -4
- package/dist/render/text.d.ts.map +1 -1
- package/dist/render/text.js +235 -49
- package/dist/render/text.js.map +1 -1
- package/dist/xml/mathml.d.ts +16 -12
- package/dist/xml/mathml.d.ts.map +1 -1
- package/dist/xml/mathml.js +110 -40
- package/dist/xml/mathml.js.map +1 -1
- package/dist/xml/ordered.d.ts +0 -6
- package/dist/xml/ordered.d.ts.map +1 -1
- package/dist/xml/ordered.js +37 -8
- package/dist/xml/ordered.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project. Each entry links to its full per-version file in [changelog/](changelog/).
|
|
4
4
|
|
|
5
|
+
## [0.2.0](changelog/0.2.x/0.2.0.md) — 2026-10-06 · 🛡️ Security
|
|
6
|
+
|
|
7
|
+
Escaping that holds across element boundaries and HTML nesting bounded before the DOM is built, plus toSections entries for footnotes and references, PDF footnotes, a PDF abort signal, and parsing fixes in every format.
|
|
8
|
+
|
|
9
|
+
## [0.1.1](changelog/0.1.x/0.1.1.md) — 2026-09-26 · 🛡️ Security
|
|
10
|
+
|
|
11
|
+
Hardening against hostile input: PDF reading budgets, one table budget per document, capped Markdown nesting, and linear-time text patterns, plus Grobid TEI outline fixes.
|
|
12
|
+
|
|
5
13
|
## [0.1.0](changelog/0.1.x/0.1.0.md) — 2026-09-26
|
|
6
14
|
|
|
7
15
|
First release: JATS, Grobid TEI, arXiv LaTeXML, publisher HTML, and PDF parsed into one document model and rendered as Markdown.
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
<div align="center">
|
|
7
7
|
|
|
8
|
-
[](./CHANGELOG.md) [](./LICENSE) [](https://www.npmjs.com/package/scholarly-parse) [](https://www.typescriptlang.org/) [](https://nodejs.org/)
|
|
9
9
|
|
|
10
10
|
</div>
|
|
11
11
|
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
## What it does
|
|
15
15
|
|
|
16
|
-
`scholarly-parse` reads a paper in any of five formats — JATS XML from PubMed Central, Europe PMC, and publisher feeds; TEI from Grobid; LaTeXML HTML from arXiv; publisher article pages; and PDF — into one `ScholarlyDocument`, and renders it as Markdown.
|
|
16
|
+
`scholarly-parse` reads a paper in any of five formats — JATS XML from PubMed Central, Europe PMC, and publisher feeds; TEI from Grobid; LaTeXML HTML from arXiv; publisher article pages; and PDF — into one `ScholarlyDocument`, and renders it as Markdown.
|
|
17
17
|
|
|
18
18
|
## Install
|
|
19
19
|
|
|
@@ -54,7 +54,7 @@ if (!result.ok && result.error.reason === 'blocked') {
|
|
|
54
54
|
}
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
`toSections` flattens the document into sections with their heading paths and sizes, for serving a long paper a piece at a time:
|
|
57
|
+
`toSections` flattens the document into sections with their heading paths and sizes, for serving a long paper a piece at a time. Figures and tables outside any section, the footnotes, and the references come last, one entry each, and each entry's `id` renders it alone through `toMarkdown(document, { sections: [id] })`:
|
|
58
58
|
|
|
59
59
|
```ts
|
|
60
60
|
import { toSections } from 'scholarly-parse';
|
|
@@ -75,7 +75,9 @@ for (const { path, chars, markdown } of toSections(document)) {
|
|
|
75
75
|
| `scholarly-parse/html` | `parseHtml` |
|
|
76
76
|
| `scholarly-parse/pdf` | `parsePdf` |
|
|
77
77
|
|
|
78
|
-
Every parser returns `{ ok: true, document }` or `{ ok: false, error: { reason, message } }`, where `reason` is `malformed`, `wrong-format`, `empty`, `blocked`, or `too-large`. Each takes a `maxInputBytes` budget; `parseLatexml` and `parseHtml` take the page's `baseUrl` to resolve links, and `parsePdf`
|
|
78
|
+
Every parser returns `{ ok: true, document }` or `{ ok: false, error: { reason, message } }`, where `reason` is `malformed`, `wrong-format`, `empty`, `blocked`, or `too-large`. Each takes a `maxInputBytes` budget; `parseLatexml` and `parseHtml` take the page's `baseUrl` to resolve links, and `parsePdf` reading budgets counted across the document: `maxPages` (default 300), `maxTextItems` (500,000), `maxTextChars` (4,000,000), and `maxOperators` (10,000,000). A PDF that reaches one parses as far as it was read, with a `truncated-input` warning. `parseJats` and `parseTei` are synchronous; the rest are async.
|
|
79
|
+
|
|
80
|
+
`parsePdf` and `parse` also take a `signal`: once it is aborted (`AbortSignal.timeout(ms)`, a request's cancellation), reading stops at the next page boundary and keeps what was read, warned `truncated-input`. pdf.js reads a page without yielding, so for a hard time or memory bound on untrusted PDFs, run `parsePdf` in a worker or process you can terminate.
|
|
79
81
|
|
|
80
82
|
## Formats
|
|
81
83
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: "Hardening against hostile input: PDF reading budgets, one table budget per document, capped Markdown nesting, and linear-time text patterns, plus Grobid TEI outline fixes."
|
|
3
|
+
breaking: false
|
|
4
|
+
security: true
|
|
5
|
+
agent-notes: |
|
|
6
|
+
`FlatSection.kind` gains `'floats'`: `toSections` ends with a floats entry whenever `document.floats` is non-empty, so an exhaustive `switch` on `kind` needs a `'floats'` case.
|
|
7
|
+
A PDF page that fails to load now returns `ok: true` with a `truncated-input` warning where it returned `malformed`; check `diagnostics.warnings` where a partial read should count as a failure.
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# 0.1.1 — 2026-09-26
|
|
11
|
+
|
|
12
|
+
## Added
|
|
13
|
+
|
|
14
|
+
- **`PdfOptions.maxTextItems`, `maxTextChars`, `maxOperators`** (defaults 500,000, 4,000,000, and 10,000,000), which `parse()` forwards: document-wide PDF reading budgets. Reading stops at the first one reached, keeps what was read, and warns `truncated-input` ([#6](https://github.com/cyanheads/scholarly-parse/issues/6)).
|
|
15
|
+
- **`toSections` ends with a `floats` entry** holding `document.floats` under Figures and tables, when there are any ([#18](https://github.com/cyanheads/scholarly-parse/issues/18)). `FlatSection.kind` gains `'floats'`.
|
|
16
|
+
|
|
17
|
+
## Changed
|
|
18
|
+
|
|
19
|
+
- **A PDF page that fails to load** ends reading with a `truncated-input` warning and keeps the pages before it, instead of failing the parse as `malformed`; with no usable text before it, the result is still `malformed`.
|
|
20
|
+
- **Grobid TEI outline**: numbered list items Grobid writes as headings nest as paragraph headings of the section they interrupt ([#16](https://github.com/cyanheads/scholarly-parse/issues/16)), and an unnumbered heading nests under the numbered section before it, numbered `2` or `2.` ([#19](https://github.com/cyanheads/scholarly-parse/issues/19)). Section structure changes for some Grobid documents.
|
|
21
|
+
|
|
22
|
+
## Fixed
|
|
23
|
+
|
|
24
|
+
- **`toText`** leaves code and TeX as written (code spans and blocks, inline and display math) and drops code fence lines; quote markers come off at every depth ([#15](https://github.com/cyanheads/scholarly-parse/issues/15)).
|
|
25
|
+
- **`toMarkdown({ sections })`** renders every ID `toSections` returns, `abstract-N` and `floats` included, in reading order ([#21](https://github.com/cyanheads/scholarly-parse/issues/21)).
|
|
26
|
+
- **Reference DOIs** in PDF, HTML, and LaTeXML leave out closing punctuation and enclosing quotes or brackets, keep balanced parentheses in the suffix, and are read when quoted ([#22](https://github.com/cyanheads/scholarly-parse/issues/22), [#25](https://github.com/cyanheads/scholarly-parse/issues/25)).
|
|
27
|
+
- **Redirect stubs** whose refresh `<meta>` lists `content` before `http-equiv` fail as `blocked`, as they already did in the other order.
|
|
28
|
+
- **Document-sized lists** are appended in a loop, so a section holding a very large number of blocks parses instead of failing as `malformed` ([#14](https://github.com/cyanheads/scholarly-parse/issues/14)).
|
|
29
|
+
- **JATS and TEI character references** to U+0000, a surrogate, or past U+10FFFF read as U+FFFD, as in HTML and LaTeXML, and the entity-expansion cap counts only DOCTYPE-declared entities, so an article dense with `&` parses ([#12](https://github.com/cyanheads/scholarly-parse/issues/12)).
|
|
30
|
+
- **One-page PDF reads** keep the lines in the top and bottom margins, dropping only a page number ([#20](https://github.com/cyanheads/scholarly-parse/issues/20)).
|
|
31
|
+
- **PDF table cells** right of every column land in the last column rather than the first.
|
|
32
|
+
- **Grobid TEI text**: sentences in adjacent `<s>` elements and caption paragraphs are spaced, keywords Grobid could not split stay one keyword, and OpenAlex's HTML-wrapped TEI reads the `<back>` beside `<text>`.
|
|
33
|
+
- **Grobid TEI sections**: a heading with no text of its own is kept when sections follow it, including a back-matter statement Grobid writes entirely as a heading, and figures and tables beside annex parts are floats.
|
|
34
|
+
|
|
35
|
+
## Security
|
|
36
|
+
|
|
37
|
+
- **`parsePdf` bounds pdf.js work across the document** through the new reading budgets. One page's own pdf.js work stays unbounded, so a hard time or memory bound on untrusted PDFs needs a worker or process the caller can terminate.
|
|
38
|
+
- **Table grids draw on one budget per document** in every format: copies of a spanned cell past 1,000,000 characters are left empty and rows past 2,000,000 grid cells dropped, each cut table warned `truncated-input` ([#8](https://github.com/cyanheads/scholarly-parse/issues/8)). PDF grids draw on the same cell budget and place their cells in linear time.
|
|
39
|
+
- **Markdown nests lists, quotes, and boxes at most eight levels**; deeper content renders at the eighth level's prefix, so output size and stack depth stay bounded ([#11](https://github.com/cyanheads/scholarly-parse/issues/11)).
|
|
40
|
+
- **Text patterns run in linear time on hostile input**: the HTML interstitial check, TeX delimiters, DOI and trailing-punctuation trims, arXiv links, LaTeXML watermarks and listings, JATS citations, emphasis, and `toText` ([#9](https://github.com/cyanheads/scholarly-parse/issues/9)).
|
|
41
|
+
- **TEI affiliations** are indexed as they are read, so an author list with many distinct affiliations parses in linear time (the TEI part of [#10](https://github.com/cyanheads/scholarly-parse/issues/10)).
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: "Escaping that holds across element boundaries and HTML nesting bounded before the DOM is built, plus toSections entries for footnotes and references, PDF footnotes, a PDF abort signal, and parsing fixes in every format."
|
|
3
|
+
breaking: false
|
|
4
|
+
security: true
|
|
5
|
+
agent-notes: |
|
|
6
|
+
`FlatSection.kind` gains `'footnotes'` and `'references'`: `toSections` ends with those entries after `floats` whenever the document has any, so an exhaustive `switch` on `kind` needs both cases.
|
|
7
|
+
Abstract-part section IDs from TEI, LaTeXML, publisher HTML, and PDF are now `abstract-<n>-<m>` (was `abstract-<n>`, `abstract`, or `s<n>`); a stored part ID needs remapping. `abstract-<digits>`, `floats`, `footnotes`, and `references` are never section IDs.
|
|
8
|
+
`parsePdf` now fills `document.footnotes`, so PDF Markdown can gain a `## Footnotes` section.
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# 0.2.0 — 2026-10-06
|
|
12
|
+
|
|
13
|
+
## Added
|
|
14
|
+
|
|
15
|
+
- **`PdfOptions.signal` and `AutoParseOptions.signal`**: an aborted `AbortSignal` stops a PDF read at the next page boundary, keeping what was read with a `truncated-input` warning ([#17](https://github.com/cyanheads/scholarly-parse/issues/17)). With a signal, each page waits one `setTimeout` turn so a timeout can fire.
|
|
16
|
+
- **`toSections` ends with `footnotes` and `references` entries** after `floats`, each holding what `toMarkdown` writes for it, and `toMarkdown({ sections })` renders them ([#27](https://github.com/cyanheads/scholarly-parse/issues/27)). `FlatSection.kind` gains both.
|
|
17
|
+
- **PDF footnotes**: labelled notes set below a page's text before the reference list become `document.footnotes`; first-page affiliations and licences stay front matter ([#43](https://github.com/cyanheads/scholarly-parse/issues/43)).
|
|
18
|
+
- **`detect`** reads bytes by their UTF-8 or UTF-16 byte-order mark, skips processing instructions before the root, names an `<article class="ltx_document">` fragment LaTeXML, and names JATS inside a PMC OAI-PMH record, which `parseJats` reads with flavor `pmc` ([#31](https://github.com/cyanheads/scholarly-parse/issues/31), [#45](https://github.com/cyanheads/scholarly-parse/issues/45)).
|
|
19
|
+
|
|
20
|
+
## Changed
|
|
21
|
+
|
|
22
|
+
- **Section IDs**: `issueId` never gives a section a `toSections` ID (`abstract-<n>`, `floats`, `footnotes`, `references`), and every reader numbers abstract parts `abstract-<n>-<m>`, so each `toSections` ID renders one entry ([#24](https://github.com/cyanheads/scholarly-parse/issues/24)).
|
|
23
|
+
- **Publisher HTML lead**: on a titled page with no abstract, article prose between the title and the first heading opens the body, byline still dropped ([#32](https://github.com/cyanheads/scholarly-parse/issues/32)).
|
|
24
|
+
- **Publisher HTML landing pages** parse as front matter and an abstract with a `no-body` warning that names a landing page; the title heading falls back to the one matching `citation_title`, and `Metadata`/`BibTeX` sections are furniture ([#30](https://github.com/cyanheads/scholarly-parse/issues/30)).
|
|
25
|
+
- **JATS footnotes** write every block of a note into its text (lists, formulas, code, captions; a table's rows are warned `unhandled-element`), definitions keep their paragraphs, and block elements read as inline text are spaced ([#35](https://github.com/cyanheads/scholarly-parse/issues/35)).
|
|
26
|
+
|
|
27
|
+
## Fixed
|
|
28
|
+
|
|
29
|
+
- **DOIs** in JATS and TEI article, related-work, and reference fields lose resolver and `doi:` prefixes, through one shared `normalizeDoi` ([#38](https://github.com/cyanheads/scholarly-parse/issues/38)).
|
|
30
|
+
- **`toText`** strips links whose label holds brackets, and `link()` escapes a label's unpaired brackets, leaving inline math alone ([#36](https://github.com/cyanheads/scholarly-parse/issues/36)).
|
|
31
|
+
- **MathML** `mmultiscripts` keep prescripts and postscripts (`{}_6^{14}C`) ([#40](https://github.com/cyanheads/scholarly-parse/issues/40)), and LaTeXML and publisher HTML convert MathML that carries no TeX instead of dropping or flattening it ([#41](https://github.com/cyanheads/scholarly-parse/issues/41)).
|
|
32
|
+
- **Publisher HTML metadata**: `<a rel="license">` and `<area rel="license">` are read as the license ([#29](https://github.com/cyanheads/scholarly-parse/issues/29)), and an `<h1>` fallback title is escaped once ([#33](https://github.com/cyanheads/scholarly-parse/issues/33)).
|
|
33
|
+
- **PDF**: runs drawn under a heading no longer join its line ([#2](https://github.com/cyanheads/scholarly-parse/issues/2)); a figure's panel labels are not headings ([#3](https://github.com/cyanheads/scholarly-parse/issues/3)); bold back-matter labels after the last reference end the list ([#5](https://github.com/cyanheads/scholarly-parse/issues/5)); one- and two-entry numbered bibliographies and `68.[No title]` entries split ([#42](https://github.com/cyanheads/scholarly-parse/issues/42)); a quoted or colon-less first-page DOI is read ([#23](https://github.com/cyanheads/scholarly-parse/issues/23)).
|
|
34
|
+
|
|
35
|
+
## Security
|
|
36
|
+
|
|
37
|
+
- **Inline escaping holds across element boundaries**: `escapeInline` closes each fragment's end and every reader runs `joinInlineSeams` over finished inline Markdown, so text split across elements cannot form raw HTML, an image, or a non-web link; citation markers are escaped ([#44](https://github.com/cyanheads/scholarly-parse/issues/44)).
|
|
38
|
+
- **HTML and LaTeXML nesting is bounded before the DOM is built**: tags of elements past 256 levels are dropped with their text kept and a `truncated-input` warning, and walkers read each element's subtree facts once, so deep or chained markup parses in linear time ([#7](https://github.com/cyanheads/scholarly-parse/issues/7)). Repeated self-closed `<math/>` and `<svg/>` are bounded the same way.
|
|
39
|
+
- **Linear-time lookups**: HTML and LaTeXML affiliations, HTML in-page link targets, JATS trailing `<notes>` ([#10](https://github.com/cyanheads/scholarly-parse/issues/10)), and a LaTeXML paragraph holding many footnotes.
|
|
40
|
+
|
|
41
|
+
## Dependencies
|
|
42
|
+
|
|
43
|
+
- `source-map-js` 1.2.1 → 1.2.2 (transitive dev dependency through vitest; [GHSA-68fv-2mgg-jv7q](https://github.com/advisories/GHSA-68fv-2mgg-jv7q))
|
package/dist/detect.d.ts
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { SourceFormat } from './model/document.js';
|
|
6
6
|
/**
|
|
7
|
-
* The format of `input`, or undefined when it is none this package reads.
|
|
8
|
-
*
|
|
7
|
+
* The format of `input`, or undefined when it is none this package reads. Bytes are read
|
|
8
|
+
* by their byte-order mark, else as Latin-1. A challenge or access-denied page is `html`;
|
|
9
|
+
* the HTML parser reports it as `blocked`.
|
|
9
10
|
*/
|
|
10
11
|
export declare function detect(input: string | Uint8Array): SourceFormat | undefined;
|
|
11
12
|
//# sourceMappingURL=detect.d.ts.map
|
package/dist/detect.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../src/detect.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../src/detect.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAMxD;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,YAAY,GAAG,SAAS,CAwB3E"}
|
package/dist/detect.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { bomEncoding } from './model/input.js';
|
|
2
|
+
/** How many characters of the input the sniffers read: headers and root elements sit at the start. */
|
|
3
|
+
const SNIFF_CHARS = 64 * 1024;
|
|
3
4
|
/**
|
|
4
|
-
* The format of `input`, or undefined when it is none this package reads.
|
|
5
|
-
*
|
|
5
|
+
* The format of `input`, or undefined when it is none this package reads. Bytes are read
|
|
6
|
+
* by their byte-order mark, else as Latin-1. A challenge or access-denied page is `html`;
|
|
7
|
+
* the HTML parser reports it as `blocked`.
|
|
6
8
|
*/
|
|
7
9
|
export function detect(input) {
|
|
8
|
-
const head = typeof input === 'string'
|
|
9
|
-
? input.slice(0, SNIFF_BYTES)
|
|
10
|
-
: latin1(input.subarray(0, SNIFF_BYTES));
|
|
10
|
+
const head = typeof input === 'string' ? input.slice(0, SNIFF_CHARS) : opening(input);
|
|
11
11
|
if (/^[\s\S]{0,1024}%PDF-/.test(head))
|
|
12
12
|
return 'pdf';
|
|
13
13
|
const text = head.replace(/^/, '').replace(/^\s+/, '');
|
|
@@ -16,9 +16,18 @@ export function detect(input) {
|
|
|
16
16
|
// TEI before HTML: OpenAlex serves Grobid's TEI wrapped in an HTML page.
|
|
17
17
|
if (/<TEI[\s>]|xmlns=["']http:\/\/www\.tei-c\.org\/ns\/1\.0["']/i.test(text))
|
|
18
18
|
return 'tei';
|
|
19
|
-
|
|
19
|
+
const root = afterProlog(text);
|
|
20
|
+
// LaTeXML before JATS: an arXiv fragment is rooted at `<article class="ltx_document">`.
|
|
21
|
+
if (/^<article\s[^<>]*\bclass\s*=\s*["'][^"'<>]*\bltx_document\b/i.test(root))
|
|
22
|
+
return 'latexml';
|
|
23
|
+
if (/^(?:<!DOCTYPE\s+(?:article|pmc-articleset)\b|<article[\s>]|<pmc-articleset[\s>])/i.test(root)) {
|
|
24
|
+
return 'jats';
|
|
25
|
+
}
|
|
26
|
+
// PMC's OAI-PMH record carries the article in `<metadata>`; an error or `oai_dc` record does not.
|
|
27
|
+
if (/^<OAI-PMH[\s>]/i.test(root) && /<metadata[^<>]*>\s*<article[\s>]/i.test(root)) {
|
|
20
28
|
return 'jats';
|
|
21
29
|
}
|
|
30
|
+
// After the JATS roots, since a JATS article's text can name the class.
|
|
22
31
|
// Each `<meta` is read up to the next `<`: a run of unclosed ones is scanned once, not once per tag.
|
|
23
32
|
if (/\bltx_document\b|<meta[^<>]+content=["']LaTeXML/i.test(text))
|
|
24
33
|
return 'latexml';
|
|
@@ -26,26 +35,39 @@ export function detect(input) {
|
|
|
26
35
|
return 'html';
|
|
27
36
|
return;
|
|
28
37
|
}
|
|
38
|
+
/** Markup the prolog may hold before the root, by how it opens and closes. */
|
|
39
|
+
const PROLOG_MARKUP = [
|
|
40
|
+
['<!--', '-->'],
|
|
41
|
+
['<?', '?>'],
|
|
42
|
+
];
|
|
29
43
|
/**
|
|
30
|
-
* The text from the root element on, past
|
|
31
|
-
* whitespace before the root. Scanned forward once: a regex over a run of
|
|
32
|
-
* backtracks exponentially when the root after them does not match.
|
|
44
|
+
* The text from the root element on, past the XML declaration, processing instructions,
|
|
45
|
+
* comments, and whitespace before the root. Scanned forward once: a regex over a run of
|
|
46
|
+
* comments backtracks exponentially when the root after them does not match.
|
|
33
47
|
*/
|
|
34
48
|
function afterProlog(text) {
|
|
35
|
-
let at =
|
|
49
|
+
let at = 0;
|
|
36
50
|
for (;;) {
|
|
37
51
|
while (/\s/.test(text.charAt(at)))
|
|
38
52
|
at++;
|
|
39
|
-
|
|
53
|
+
const markup = PROLOG_MARKUP.find(([open]) => text.startsWith(open, at));
|
|
54
|
+
if (!markup)
|
|
40
55
|
return text.slice(at);
|
|
41
|
-
const
|
|
56
|
+
const [open, close] = markup;
|
|
57
|
+
const end = text.indexOf(close, at + open.length);
|
|
42
58
|
if (end === -1)
|
|
43
59
|
return '';
|
|
44
|
-
at = end +
|
|
60
|
+
at = end + close.length;
|
|
45
61
|
}
|
|
46
62
|
}
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
|
|
63
|
+
/**
|
|
64
|
+
* The first {@link SNIFF_CHARS} characters of `bytes`, decoded by their byte-order mark as
|
|
65
|
+
* `decodeText` does — UTF-16 takes twice the bytes — else as Latin-1, which reads ASCII
|
|
66
|
+
* markup whatever the real encoding.
|
|
67
|
+
*/
|
|
68
|
+
function opening(bytes) {
|
|
69
|
+
const encoding = bomEncoding(bytes);
|
|
70
|
+
const width = encoding === 'utf-16le' || encoding === 'utf-16be' ? 2 : 1;
|
|
71
|
+
return new TextDecoder(encoding ?? 'latin1').decode(bytes.subarray(0, SNIFF_CHARS * width));
|
|
50
72
|
}
|
|
51
73
|
//# sourceMappingURL=detect.js.map
|
package/dist/detect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect.js","sourceRoot":"","sources":["../src/detect.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"detect.js","sourceRoot":"","sources":["../src/detect.ts"],"names":[],"mappings":"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"}
|
|
@@ -16,7 +16,7 @@ export type FloatKind = 'figure' | 'table' | 'supplement';
|
|
|
16
16
|
* `tw`, `supplementary`) together with the image, table, or file link they wrap, so a
|
|
17
17
|
* class alone never swallows a section.
|
|
18
18
|
*/
|
|
19
|
-
export declare function floatKind(element: Element): FloatKind | undefined;
|
|
19
|
+
export declare function floatKind(element: Element, ctx: HtmlContext): FloatKind | undefined;
|
|
20
20
|
/** Blocks for a node list, in document order. */
|
|
21
21
|
export declare function flowBlocks(nodes: Node[], ctx: HtmlContext): Block[];
|
|
22
22
|
/** Link-list words publishers put in captions and reference entries, not part of the text. */
|
|
@@ -24,6 +24,7 @@ export declare const LINK_LABEL: RegExp;
|
|
|
24
24
|
/**
|
|
25
25
|
* True for an element that holds only links and link-list words ("Download: PNG TIFF",
|
|
26
26
|
* "Full size image", "[DOI] [PubMed]"): navigation around a caption, not caption text.
|
|
27
|
+
* Text outside its links that runs past the subtree text cap is not a link list.
|
|
27
28
|
*/
|
|
28
|
-
export declare function isLinkList(element: Element): boolean;
|
|
29
|
+
export declare function isLinkList(element: Element, ctx: HtmlContext): boolean;
|
|
29
30
|
//# sourceMappingURL=blocks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../../src/formats/html/blocks.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../../src/formats/html/blocks.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAaH,OAAO,KAAK,EACV,KAAK,EAKN,MAAM,yBAAyB,CAAC;AAKjC,OAAO,EAAE,KAAK,WAAW,EAA2B,MAAM,cAAc,CAAC;AAezE,mGAAmG;AACnG,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,OAAO,GAAG,YAAY,CAAC;AAY1D;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,WAAW,GAAG,SAAS,GAAG,SAAS,CAuBnF;AA0DD,iDAAiD;AACjD,wBAAgB,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,WAAW,GAAG,KAAK,EAAE,CAKnE;AAqJD,8FAA8F;AAC9F,eAAO,MAAM,UAAU,QACid,CAAC;AAEze;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,WAAW,GAAG,OAAO,CAStE"}
|