scholarly-parse 0.1.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.
Files changed (238) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +201 -0
  3. package/README.md +118 -0
  4. package/changelog/0.1.x/0.1.0.md +17 -0
  5. package/changelog/template.md +150 -0
  6. package/dist/detect.d.ts +11 -0
  7. package/dist/detect.d.ts.map +1 -0
  8. package/dist/detect.js +51 -0
  9. package/dist/detect.js.map +1 -0
  10. package/dist/formats/html/blocks.d.ts +29 -0
  11. package/dist/formats/html/blocks.d.ts.map +1 -0
  12. package/dist/formats/html/blocks.js +527 -0
  13. package/dist/formats/html/blocks.js.map +1 -0
  14. package/dist/formats/html/context.d.ts +19 -0
  15. package/dist/formats/html/context.d.ts.map +1 -0
  16. package/dist/formats/html/context.js +122 -0
  17. package/dist/formats/html/context.js.map +1 -0
  18. package/dist/formats/html/index.d.ts +7 -0
  19. package/dist/formats/html/index.d.ts.map +1 -0
  20. package/dist/formats/html/index.js +7 -0
  21. package/dist/formats/html/index.js.map +1 -0
  22. package/dist/formats/html/inline.d.ts +26 -0
  23. package/dist/formats/html/inline.d.ts.map +1 -0
  24. package/dist/formats/html/inline.js +253 -0
  25. package/dist/formats/html/inline.js.map +1 -0
  26. package/dist/formats/html/metadata.d.ts +30 -0
  27. package/dist/formats/html/metadata.d.ts.map +1 -0
  28. package/dist/formats/html/metadata.js +212 -0
  29. package/dist/formats/html/metadata.js.map +1 -0
  30. package/dist/formats/html/parse.d.ts +17 -0
  31. package/dist/formats/html/parse.d.ts.map +1 -0
  32. package/dist/formats/html/parse.js +405 -0
  33. package/dist/formats/html/parse.js.map +1 -0
  34. package/dist/formats/html/references.d.ts +12 -0
  35. package/dist/formats/html/references.d.ts.map +1 -0
  36. package/dist/formats/html/references.js +123 -0
  37. package/dist/formats/html/references.js.map +1 -0
  38. package/dist/formats/jats/blocks.d.ts +52 -0
  39. package/dist/formats/jats/blocks.d.ts.map +1 -0
  40. package/dist/formats/jats/blocks.js +614 -0
  41. package/dist/formats/jats/blocks.js.map +1 -0
  42. package/dist/formats/jats/context.d.ts +17 -0
  43. package/dist/formats/jats/context.d.ts.map +1 -0
  44. package/dist/formats/jats/context.js +2 -0
  45. package/dist/formats/jats/context.js.map +1 -0
  46. package/dist/formats/jats/fragment.d.ts +7 -0
  47. package/dist/formats/jats/fragment.d.ts.map +1 -0
  48. package/dist/formats/jats/fragment.js +42 -0
  49. package/dist/formats/jats/fragment.js.map +1 -0
  50. package/dist/formats/jats/front.d.ts +25 -0
  51. package/dist/formats/jats/front.d.ts.map +1 -0
  52. package/dist/formats/jats/front.js +380 -0
  53. package/dist/formats/jats/front.js.map +1 -0
  54. package/dist/formats/jats/index.d.ts +8 -0
  55. package/dist/formats/jats/index.d.ts.map +1 -0
  56. package/dist/formats/jats/index.js +8 -0
  57. package/dist/formats/jats/index.js.map +1 -0
  58. package/dist/formats/jats/inline.d.ts +24 -0
  59. package/dist/formats/jats/inline.d.ts.map +1 -0
  60. package/dist/formats/jats/inline.js +274 -0
  61. package/dist/formats/jats/inline.js.map +1 -0
  62. package/dist/formats/jats/parse.d.ts +9 -0
  63. package/dist/formats/jats/parse.d.ts.map +1 -0
  64. package/dist/formats/jats/parse.js +247 -0
  65. package/dist/formats/jats/parse.js.map +1 -0
  66. package/dist/formats/jats/references.d.ts +25 -0
  67. package/dist/formats/jats/references.d.ts.map +1 -0
  68. package/dist/formats/jats/references.js +406 -0
  69. package/dist/formats/jats/references.js.map +1 -0
  70. package/dist/formats/jats/tables.d.ts +18 -0
  71. package/dist/formats/jats/tables.d.ts.map +1 -0
  72. package/dist/formats/jats/tables.js +105 -0
  73. package/dist/formats/jats/tables.js.map +1 -0
  74. package/dist/formats/jats/text.d.ts +23 -0
  75. package/dist/formats/jats/text.d.ts.map +1 -0
  76. package/dist/formats/jats/text.js +114 -0
  77. package/dist/formats/jats/text.js.map +1 -0
  78. package/dist/formats/latexml/blocks.d.ts +13 -0
  79. package/dist/formats/latexml/blocks.d.ts.map +1 -0
  80. package/dist/formats/latexml/blocks.js +454 -0
  81. package/dist/formats/latexml/blocks.js.map +1 -0
  82. package/dist/formats/latexml/context.d.ts +19 -0
  83. package/dist/formats/latexml/context.d.ts.map +1 -0
  84. package/dist/formats/latexml/context.js +18 -0
  85. package/dist/formats/latexml/context.js.map +1 -0
  86. package/dist/formats/latexml/index.d.ts +7 -0
  87. package/dist/formats/latexml/index.d.ts.map +1 -0
  88. package/dist/formats/latexml/index.js +7 -0
  89. package/dist/formats/latexml/index.js.map +1 -0
  90. package/dist/formats/latexml/inline.d.ts +16 -0
  91. package/dist/formats/latexml/inline.d.ts.map +1 -0
  92. package/dist/formats/latexml/inline.js +113 -0
  93. package/dist/formats/latexml/inline.js.map +1 -0
  94. package/dist/formats/latexml/parse.d.ts +16 -0
  95. package/dist/formats/latexml/parse.d.ts.map +1 -0
  96. package/dist/formats/latexml/parse.js +405 -0
  97. package/dist/formats/latexml/parse.js.map +1 -0
  98. package/dist/formats/pdf/blocks.d.ts +14 -0
  99. package/dist/formats/pdf/blocks.d.ts.map +1 -0
  100. package/dist/formats/pdf/blocks.js +203 -0
  101. package/dist/formats/pdf/blocks.js.map +1 -0
  102. package/dist/formats/pdf/index.d.ts +7 -0
  103. package/dist/formats/pdf/index.d.ts.map +1 -0
  104. package/dist/formats/pdf/index.js +7 -0
  105. package/dist/formats/pdf/index.js.map +1 -0
  106. package/dist/formats/pdf/inline.d.ts +8 -0
  107. package/dist/formats/pdf/inline.d.ts.map +1 -0
  108. package/dist/formats/pdf/inline.js +91 -0
  109. package/dist/formats/pdf/inline.js.map +1 -0
  110. package/dist/formats/pdf/layout.d.ts +33 -0
  111. package/dist/formats/pdf/layout.d.ts.map +1 -0
  112. package/dist/formats/pdf/layout.js +358 -0
  113. package/dist/formats/pdf/layout.js.map +1 -0
  114. package/dist/formats/pdf/lines.d.ts +40 -0
  115. package/dist/formats/pdf/lines.d.ts.map +1 -0
  116. package/dist/formats/pdf/lines.js +104 -0
  117. package/dist/formats/pdf/lines.js.map +1 -0
  118. package/dist/formats/pdf/load.d.ts +43 -0
  119. package/dist/formats/pdf/load.d.ts.map +1 -0
  120. package/dist/formats/pdf/load.js +126 -0
  121. package/dist/formats/pdf/load.js.map +1 -0
  122. package/dist/formats/pdf/parse.d.ts +9 -0
  123. package/dist/formats/pdf/parse.d.ts.map +1 -0
  124. package/dist/formats/pdf/parse.js +126 -0
  125. package/dist/formats/pdf/parse.js.map +1 -0
  126. package/dist/formats/pdf/references.d.ts +14 -0
  127. package/dist/formats/pdf/references.d.ts.map +1 -0
  128. package/dist/formats/pdf/references.js +104 -0
  129. package/dist/formats/pdf/references.js.map +1 -0
  130. package/dist/formats/pdf/structure.d.ts +29 -0
  131. package/dist/formats/pdf/structure.d.ts.map +1 -0
  132. package/dist/formats/pdf/structure.js +533 -0
  133. package/dist/formats/pdf/structure.js.map +1 -0
  134. package/dist/formats/tei/index.d.ts +7 -0
  135. package/dist/formats/tei/index.d.ts.map +1 -0
  136. package/dist/formats/tei/index.js +7 -0
  137. package/dist/formats/tei/index.js.map +1 -0
  138. package/dist/formats/tei/inline.d.ts +24 -0
  139. package/dist/formats/tei/inline.d.ts.map +1 -0
  140. package/dist/formats/tei/inline.js +107 -0
  141. package/dist/formats/tei/inline.js.map +1 -0
  142. package/dist/formats/tei/parse.d.ts +4 -0
  143. package/dist/formats/tei/parse.d.ts.map +1 -0
  144. package/dist/formats/tei/parse.js +560 -0
  145. package/dist/formats/tei/parse.js.map +1 -0
  146. package/dist/html/dom.d.ts +35 -0
  147. package/dist/html/dom.d.ts.map +1 -0
  148. package/dist/html/dom.js +70 -0
  149. package/dist/html/dom.js.map +1 -0
  150. package/dist/html/interstitial.d.ts +14 -0
  151. package/dist/html/interstitial.d.ts.map +1 -0
  152. package/dist/html/interstitial.js +67 -0
  153. package/dist/html/interstitial.js.map +1 -0
  154. package/dist/html/tables.d.ts +12 -0
  155. package/dist/html/tables.d.ts.map +1 -0
  156. package/dist/html/tables.js +62 -0
  157. package/dist/html/tables.js.map +1 -0
  158. package/dist/index.d.ts +12 -0
  159. package/dist/index.d.ts.map +1 -0
  160. package/dist/index.js +12 -0
  161. package/dist/index.js.map +1 -0
  162. package/dist/model/diagnostics.d.ts +15 -0
  163. package/dist/model/diagnostics.d.ts.map +1 -0
  164. package/dist/model/diagnostics.js +37 -0
  165. package/dist/model/diagnostics.js.map +1 -0
  166. package/dist/model/document.d.ts +289 -0
  167. package/dist/model/document.d.ts.map +1 -0
  168. package/dist/model/document.js +13 -0
  169. package/dist/model/document.js.map +1 -0
  170. package/dist/model/extremes.d.ts +11 -0
  171. package/dist/model/extremes.d.ts.map +1 -0
  172. package/dist/model/extremes.js +23 -0
  173. package/dist/model/extremes.js.map +1 -0
  174. package/dist/model/index.d.ts +8 -0
  175. package/dist/model/index.d.ts.map +1 -0
  176. package/dist/model/index.js +2 -0
  177. package/dist/model/index.js.map +1 -0
  178. package/dist/model/input.d.ts +14 -0
  179. package/dist/model/input.d.ts.map +1 -0
  180. package/dist/model/input.js +47 -0
  181. package/dist/model/input.js.map +1 -0
  182. package/dist/model/result.d.ts +53 -0
  183. package/dist/model/result.d.ts.map +1 -0
  184. package/dist/model/result.js +40 -0
  185. package/dist/model/result.js.map +1 -0
  186. package/dist/model/section-ids.d.ts +8 -0
  187. package/dist/model/section-ids.d.ts.map +1 -0
  188. package/dist/model/section-ids.js +28 -0
  189. package/dist/model/section-ids.js.map +1 -0
  190. package/dist/model/section-kinds.d.ts +19 -0
  191. package/dist/model/section-kinds.d.ts.map +1 -0
  192. package/dist/model/section-kinds.js +42 -0
  193. package/dist/model/section-kinds.js.map +1 -0
  194. package/dist/model/table-grid.d.ts +40 -0
  195. package/dist/model/table-grid.d.ts.map +1 -0
  196. package/dist/model/table-grid.js +79 -0
  197. package/dist/model/table-grid.js.map +1 -0
  198. package/dist/parse.d.ts +18 -0
  199. package/dist/parse.d.ts.map +1 -0
  200. package/dist/parse.js +35 -0
  201. package/dist/parse.js.map +1 -0
  202. package/dist/render/escape.d.ts +53 -0
  203. package/dist/render/escape.d.ts.map +1 -0
  204. package/dist/render/escape.js +94 -0
  205. package/dist/render/escape.js.map +1 -0
  206. package/dist/render/index.d.ts +8 -0
  207. package/dist/render/index.d.ts.map +1 -0
  208. package/dist/render/index.js +8 -0
  209. package/dist/render/index.js.map +1 -0
  210. package/dist/render/inline.d.ts +39 -0
  211. package/dist/render/inline.d.ts.map +1 -0
  212. package/dist/render/inline.js +87 -0
  213. package/dist/render/inline.js.map +1 -0
  214. package/dist/render/markdown.d.ts +35 -0
  215. package/dist/render/markdown.d.ts.map +1 -0
  216. package/dist/render/markdown.js +279 -0
  217. package/dist/render/markdown.js.map +1 -0
  218. package/dist/render/sections.d.ts +25 -0
  219. package/dist/render/sections.d.ts.map +1 -0
  220. package/dist/render/sections.js +45 -0
  221. package/dist/render/sections.js.map +1 -0
  222. package/dist/render/text.d.ts +13 -0
  223. package/dist/render/text.d.ts.map +1 -0
  224. package/dist/render/text.js +66 -0
  225. package/dist/render/text.js.map +1 -0
  226. package/dist/xml/mathml.d.ts +24 -0
  227. package/dist/xml/mathml.d.ts.map +1 -0
  228. package/dist/xml/mathml.js +201 -0
  229. package/dist/xml/mathml.js.map +1 -0
  230. package/dist/xml/ordered.d.ts +49 -0
  231. package/dist/xml/ordered.d.ts.map +1 -0
  232. package/dist/xml/ordered.js +151 -0
  233. package/dist/xml/ordered.js.map +1 -0
  234. package/dist/xml/well-formed.d.ts +15 -0
  235. package/dist/xml/well-formed.d.ts.map +1 -0
  236. package/dist/xml/well-formed.js +120 -0
  237. package/dist/xml/well-formed.js.map +1 -0
  238. package/package.json +137 -0
@@ -0,0 +1,212 @@
1
+ import { escapeInline } from '../../render/escape.js';
2
+ /** Every named `<meta>` tag with content, in document order. */
3
+ export function readMetaTags(document) {
4
+ return Array.from(document.querySelectorAll('meta')).flatMap((meta) => {
5
+ const name = (meta.getAttribute('name') ?? meta.getAttribute('property') ?? '')
6
+ .trim()
7
+ .toLowerCase();
8
+ const content = meta.getAttribute('content')?.replace(/\s+/g, ' ').trim();
9
+ return name && content ? [{ content, name }] : [];
10
+ });
11
+ }
12
+ function first(tags, ...names) {
13
+ for (const name of names) {
14
+ const tag = tags.find((t) => t.name === name);
15
+ if (tag)
16
+ return tag.content;
17
+ }
18
+ return;
19
+ }
20
+ function all(tags, name) {
21
+ return tags.filter((t) => t.name === name).map((t) => t.content);
22
+ }
23
+ /** A DOI without a resolver or `doi:` prefix, lowercased. */
24
+ export function normalizeDoi(value) {
25
+ const doi = value
26
+ ?.trim()
27
+ .replace(/^(?:https?:\/\/(?:dx\.)?doi\.org\/|doi:\s*)/i, '')
28
+ .replace(/[.,;]+$/, '');
29
+ return doi && /^10\.\d{4,9}\//.test(doi) ? doi.toLowerCase() : undefined;
30
+ }
31
+ /** `2024/05/12`, `2024-05-12`, `2024-05`, `2024`, `May 12, 2024` → a partial date. */
32
+ export function parseDate(value) {
33
+ if (!value)
34
+ return;
35
+ const numeric = /^(\d{4})(?:[-/.](\d{1,2})(?:[-/.](\d{1,2}))?)?/.exec(value.trim());
36
+ if (numeric) {
37
+ const [, year, month, day] = numeric;
38
+ return {
39
+ year: Number(year),
40
+ ...(month && Number(month) >= 1 && Number(month) <= 12 && { month: Number(month) }),
41
+ ...(month && day && Number(day) >= 1 && Number(day) <= 31 && { day: Number(day) }),
42
+ };
43
+ }
44
+ const parsed = Date.parse(value);
45
+ if (Number.isNaN(parsed))
46
+ return;
47
+ const date = new Date(parsed);
48
+ return { day: date.getUTCDate(), month: date.getUTCMonth() + 1, year: date.getUTCFullYear() };
49
+ }
50
+ /** An author from a `citation_author` value: `Family, Given` or `Given Family`. */
51
+ function authorFrom(value) {
52
+ const comma = value.indexOf(',');
53
+ if (comma === -1)
54
+ return { name: value };
55
+ const family = value.slice(0, comma).trim();
56
+ const given = value.slice(comma + 1).trim();
57
+ return { family, ...(given && { given }), name: given ? `${given} ${family}` : family };
58
+ }
59
+ /** Front matter from the page's tags. `fallbackTitle` is the visible `<h1>`, used when no tag names one. */
60
+ export function extractMetadata(document, tags, fallbackTitle) {
61
+ const affiliations = [];
62
+ const authors = [];
63
+ for (const tag of tags) {
64
+ const current = authors.at(-1);
65
+ if (tag.name === 'citation_author') {
66
+ authors.push(authorFrom(tag.content));
67
+ }
68
+ else if (current && tag.name === 'citation_author_institution') {
69
+ const existing = affiliations.indexOf(tag.content);
70
+ const index = existing === -1 ? affiliations.push(tag.content) - 1 : existing;
71
+ current.affiliations = [...new Set([...(current.affiliations ?? []), index])];
72
+ }
73
+ else if (current && tag.name === 'citation_author_orcid') {
74
+ const orcid = /\d{4}-\d{4}-\d{4}-\d{3}[\dX]/.exec(tag.content)?.[0];
75
+ if (orcid)
76
+ current.orcid = orcid;
77
+ }
78
+ else if (current && tag.name === 'citation_author_email') {
79
+ current.email = tag.content;
80
+ }
81
+ }
82
+ if (authors.length === 0)
83
+ for (const creator of all(tags, 'dc.creator'))
84
+ authors.push(authorFrom(creator));
85
+ const title = first(tags, 'citation_title', 'dc.title') ?? fallbackTitle ?? first(tags, 'og:title');
86
+ const doi = normalizeDoi(first(tags, 'citation_doi', 'prism.doi') ??
87
+ all(tags, 'dc.identifier').find((value) => /10\.\d{4,9}\//.test(value)));
88
+ const pmid = first(tags, 'citation_pmid')?.replace(/\D/g, '');
89
+ const pmcid = /PMC\d+/i.exec(first(tags, 'citation_pmcid') ?? '')?.[0]?.toUpperCase();
90
+ const arxiv = first(tags, 'citation_arxiv_id')?.replace(/^arxiv:/i, '');
91
+ const identifiers = {
92
+ ...(doi && { doi }),
93
+ ...(pmid && { pmid }),
94
+ ...(pmcid && { pmcid }),
95
+ ...(arxiv && { arxiv }),
96
+ };
97
+ const firstPage = first(tags, 'citation_firstpage');
98
+ const lastPage = first(tags, 'citation_lastpage');
99
+ const venue = {
100
+ ...optional('title', first(tags, 'citation_journal_title', 'citation_conference_title', 'citation_inbook_title', 'prism.publicationname')),
101
+ ...optional('volume', first(tags, 'citation_volume', 'prism.volume')),
102
+ ...optional('issue', first(tags, 'citation_issue', 'prism.number')),
103
+ ...optional('pages', firstPage && lastPage && firstPage !== lastPage ? `${firstPage}–${lastPage}` : firstPage),
104
+ ...optional('publisher', first(tags, 'citation_publisher', 'dc.publisher')),
105
+ ...optional('issn', first(tags, 'citation_issn', 'prism.issn', 'prism.eissn')),
106
+ };
107
+ const keywords = all(tags, 'citation_keywords')
108
+ .flatMap((value) => value.split(/\s*[;,]\s*/))
109
+ .filter(Boolean);
110
+ const licenseUrl = document.querySelector('link[rel="license"]')?.getAttribute('href') ??
111
+ [first(tags, 'dc.rights'), first(tags, 'citation_license')].find((value) => /^https?:\/\//.test(value ?? ''));
112
+ // `dc.rights` often holds only a copyright line; it counts as a license when it names one.
113
+ const licenseText = [first(tags, 'dc.rights'), first(tags, 'citation_license')].find((value) => value &&
114
+ !/^https?:\/\//.test(value) &&
115
+ /licen[cs]|creative\s*commons|\bcc[\s-]?by\b|\bcc0\b|public domain/i.test(value));
116
+ const language = first(tags, 'citation_language', 'dc.language') ??
117
+ document.documentElement?.getAttribute('lang') ??
118
+ undefined;
119
+ const published = parseDate(first(tags, 'citation_publication_date', 'citation_date', 'citation_online_date', 'dc.date', 'article:published_time'));
120
+ const articleType = first(tags, 'citation_article_type', 'dc.type');
121
+ return {
122
+ ...(title && { title: escapeInline(title) }),
123
+ ...(authors.length > 0 && { authors }),
124
+ ...(affiliations.length > 0 && { affiliations }),
125
+ ...(Object.keys(identifiers).length > 0 && { identifiers }),
126
+ ...(Object.keys(venue).length > 0 && { venue }),
127
+ ...(published && { published }),
128
+ ...(keywords.length > 0 && { keywords }),
129
+ ...((licenseUrl || licenseText) && {
130
+ license: { ...optional('url', licenseUrl), ...optional('text', licenseText) },
131
+ }),
132
+ ...(language && { language }),
133
+ ...(articleType && { articleType }),
134
+ };
135
+ }
136
+ function optional(key, value) {
137
+ return (value ? { [key]: value } : {});
138
+ }
139
+ /** The abstract the tags carry, for a page whose body has no abstract section. */
140
+ export function metaAbstract(tags) {
141
+ return first(tags, 'citation_abstract', 'dc.description', 'dcterms.abstract');
142
+ }
143
+ /**
144
+ * References from `citation_reference` tags, for a page whose reference list could not
145
+ * be read. Each tag packs fields as `citation_title=…; citation_author=…; …`.
146
+ */
147
+ export function metaReferences(tags) {
148
+ return all(tags, 'citation_reference').flatMap((value, index) => {
149
+ // Some publishers put the printed citation in the tag instead of fields.
150
+ if (!/(?:^|;)\s*citation_\w+=/.test(value)) {
151
+ const doi = normalizeDoi(/\b10\.\d{4,9}\/[^\s;]+/.exec(value)?.[0]);
152
+ return [{ label: String(index + 1), text: escapeInline(value), ...(doi && { doi }) }];
153
+ }
154
+ const fields = new Map();
155
+ for (const part of value.split(/;\s*(?=citation_\w+=)/)) {
156
+ const eq = part.indexOf('=');
157
+ if (eq === -1)
158
+ continue;
159
+ const key = part.slice(0, eq).trim().toLowerCase();
160
+ const field = part
161
+ .slice(eq + 1)
162
+ .trim()
163
+ .replace(/;$/, '');
164
+ if (!field)
165
+ continue;
166
+ const values = fields.get(key);
167
+ if (values)
168
+ values.push(field);
169
+ else
170
+ fields.set(key, [field]);
171
+ }
172
+ const get = (key) => fields.get(key)?.[0];
173
+ const authors = fields.get('citation_author') ?? [];
174
+ const title = get('citation_title');
175
+ const source = get('citation_journal_title') ??
176
+ get('citation_inbook_title') ??
177
+ get('citation_conference_title') ??
178
+ get('citation_publisher');
179
+ const year = /\d{4}/.exec(get('citation_year') ?? get('citation_publication_date') ?? get('citation_date') ?? '')?.[0];
180
+ const doi = normalizeDoi(get('citation_doi'));
181
+ const pmid = get('citation_pmid')?.replace(/\D/g, '');
182
+ const volume = get('citation_volume');
183
+ const pages = get('citation_pages') ?? get('citation_firstpage');
184
+ const text = [
185
+ authors.length > 0 && `${escapeInline(authors.join(', '))}.`,
186
+ title && `${escapeInline(title.replace(/\.$/, ''))}.`,
187
+ source && `*${escapeInline(source)}*.`,
188
+ [year, volume && `${escapeInline(volume)}${pages ? `:${escapeInline(pages)}` : ''}`]
189
+ .filter(Boolean)
190
+ .join(';'),
191
+ doi && `doi:${escapeInline(doi)}`,
192
+ ]
193
+ .filter(Boolean)
194
+ .join(' ')
195
+ .trim();
196
+ if (!text)
197
+ return [];
198
+ return [
199
+ {
200
+ label: String(index + 1),
201
+ text,
202
+ ...(authors.length > 0 && { authors }),
203
+ ...(title && { title }),
204
+ ...(source && { source }),
205
+ ...(year && { year }),
206
+ ...(doi && { doi }),
207
+ ...(pmid && { pmid }),
208
+ },
209
+ ];
210
+ });
211
+ }
212
+ //# sourceMappingURL=metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../src/formats/html/metadata.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAQtD,gEAAgE;AAChE,MAAM,UAAU,YAAY,CAAC,QAAkB;IAC7C,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACpE,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;aAC5E,IAAI,EAAE;aACN,WAAW,EAAE,CAAC;QACjB,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QAC1E,OAAO,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,KAAK,CAAC,IAAe,EAAE,GAAG,KAAe;IAChD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,C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KAAK,EAAE,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC;gBACxB,IAAI;gBACJ,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC;gBACtC,GAAG,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,CAAC;gBACvB,GAAG,CAAC,MAAM,IAAI,EAAE,MAAM,EAAE,CAAC;gBACzB,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,CAAC;gBACrB,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,CAAC;gBACnB,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,CAAC;aACtB;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @fileoverview `parseHtml`: a publisher or preprint-server article page →
3
+ * `ScholarlyDocument`. Front matter comes from the page's `citation_*` and Dublin Core
4
+ * tags; the article container is the smallest page region holding nearly all of its
5
+ * prose; headings inside it become the section tree. Structure is inferred from
6
+ * presentation, so the result is `partial` quality.
7
+ * @module src/formats/html/parse
8
+ */
9
+ import { type ParseOptions, type ParseResult } from '../../model/result.js';
10
+ /** Options for {@link parseHtml}. */
11
+ export interface HtmlOptions extends ParseOptions {
12
+ /** The page's URL, so relative image and link targets resolve. */
13
+ baseUrl?: string;
14
+ }
15
+ /** Parse a publisher article page. Requires the optional `linkedom` peer. */
16
+ export declare function parseHtml(input: string | Uint8Array, options?: HtmlOptions): Promise<ParseResult>;
17
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/formats/html/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAsBH,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,WAAW,EAEjB,MAAM,uBAAuB,CAAC;AAU/B,qCAAqC;AACrC,MAAM,WAAW,WAAY,SAAQ,YAAY;IAC/C,kEAAkE;IAClE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAID,6EAA6E;AAC7E,wBAAgB,SAAS,CACvB,KAAK,EAAE,MAAM,GAAG,UAAU,EAC1B,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,WAAW,CAAC,CAEtB"}
@@ -0,0 +1,405 @@
1
+ /**
2
+ * @fileoverview `parseHtml`: a publisher or preprint-server article page →
3
+ * `ScholarlyDocument`. Front matter comes from the page's `citation_*` and Dublin Core
4
+ * tags; the article container is the smallest page region holding nearly all of its
5
+ * prose; headings inside it become the section tree. Structure is inferred from
6
+ * presentation, so the result is `partial` quality.
7
+ * @module src/formats/html/parse
8
+ */
9
+ import { childNodes, isElement, loadDocument, TEXT_NODE, tagOf, textOfElement, } from '../../html/dom.js';
10
+ import { interstitialReason } from '../../html/interstitial.js';
11
+ import { createDiagnostics } from '../../model/diagnostics.js';
12
+ import { largest } from '../../model/extremes.js';
13
+ import { decodeText, exceedsBudget } from '../../model/input.js';
14
+ import { failed, guardAsync, parsed, } from '../../model/result.js';
15
+ import { issueId } from '../../model/section-ids.js';
16
+ import { kindFromTitle, splitSectionNumber } from '../../model/section-kinds.js';
17
+ import { escapeInline } from '../../render/escape.js';
18
+ import { floatKind, flowBlocks, isLinkList } from './blocks.js';
19
+ import { isFurniture, nameTokens } from './context.js';
20
+ import { inlineText } from './inline.js';
21
+ import { extractMetadata, metaAbstract, metaReferences, readMetaTags } from './metadata.js';
22
+ import { extractReferences } from './references.js';
23
+ const DEFAULT_MAX_INPUT_BYTES = 32 * 1024 * 1024;
24
+ /** Parse a publisher article page. Requires the optional `linkedom` peer. */
25
+ export function parseHtml(input, options = {}) {
26
+ return guardAsync(() => readHtml(input, options));
27
+ }
28
+ async function readHtml(input, options) {
29
+ const maxBytes = options.maxInputBytes ?? DEFAULT_MAX_INPUT_BYTES;
30
+ if (exceedsBudget(input, maxBytes))
31
+ return failed('too-large', `Input exceeds the ${maxBytes}-byte budget`);
32
+ const source = decodeText(input);
33
+ if (!/<(?:html|body|head|meta|div|p|article)[\s>]/i.test(source)) {
34
+ return failed('wrong-format', 'Not an HTML page: no html, head, or body markup');
35
+ }
36
+ const blocked = interstitialReason(source);
37
+ if (blocked)
38
+ return failed('blocked', blocked);
39
+ const document = await loadDocument(source);
40
+ const ctx = {
41
+ baseUrl: options.baseUrl,
42
+ diag: createDiagnostics(),
43
+ footnotes: [],
44
+ sectionIds: new Set(),
45
+ };
46
+ const tags = readMetaTags(document);
47
+ const root = contentRoot(document);
48
+ const titleHeading = root ? findTitleHeading(root) : undefined;
49
+ const metadata = extractMetadata(document, tags, titleHeading ? inlineText(titleHeading, ctx) : undefined);
50
+ const outline = root
51
+ ? buildOutline(root, titleHeading)
52
+ : { beforeTitle: 0, lead: [], sections: [] };
53
+ const { abstracts, back, body, references } = classify(outline, titleHeading !== undefined, ctx);
54
+ if (abstracts.length === 0) {
55
+ const fallback = metaAbstract(tags);
56
+ if (fallback) {
57
+ abstracts.push({
58
+ kind: 'main',
59
+ sections: [
60
+ {
61
+ blocks: [{ text: escapeInline(fallback), type: 'paragraph' }],
62
+ id: issueId(ctx.sectionIds, undefined, 'abstract'),
63
+ kind: 'body',
64
+ sections: [],
65
+ },
66
+ ],
67
+ });
68
+ }
69
+ }
70
+ const finalReferences = references.length > 0 ? references : metaReferences(tags);
71
+ if (!metadata.title && abstracts.length === 0 && body.length === 0) {
72
+ return failed('empty', 'The page carries no title, abstract, or article text');
73
+ }
74
+ if (!metadata.title)
75
+ ctx.diag.warn('no-title', 'The page names no title');
76
+ if (abstracts.length === 0)
77
+ ctx.diag.warn('no-abstract', 'The page has no abstract');
78
+ if (body.length === 0)
79
+ ctx.diag.warn('no-body', 'The page has no article text');
80
+ ctx.diag.warn('structure-inferred', 'Sections were inferred from the page headings');
81
+ const result = {
82
+ abstracts,
83
+ back,
84
+ body,
85
+ diagnostics: ctx.diag.finish('partial'),
86
+ floats: [],
87
+ footnotes: ctx.footnotes,
88
+ format: 'html',
89
+ metadata,
90
+ references: finalReferences,
91
+ };
92
+ return parsed(result);
93
+ }
94
+ // ─── Content root ───────────────────────────────────────────────────────────
95
+ /** Prose a region holds: the text of its paragraphs, furniture excluded. */
96
+ function proseLength(element) {
97
+ let total = 0;
98
+ for (const p of Array.from(element.querySelectorAll('p'))) {
99
+ if (!p.parentElement?.closest('aside, nav, footer, [role="complementary"], [role="navigation"]')) {
100
+ total += (p.textContent ?? '').length;
101
+ }
102
+ }
103
+ return total;
104
+ }
105
+ /**
106
+ * The article region: of the page's `<article>` and `<main>` regions and the body, the
107
+ * smallest one holding at least 90% of the prose the richest one holds. A related-article
108
+ * card is an `<article>` too, but holds little prose.
109
+ */
110
+ function contentRoot(document) {
111
+ const body = document.body ?? document.documentElement;
112
+ if (!body)
113
+ return;
114
+ const candidates = [body, ...Array.from(body.querySelectorAll('main, article, [role="main"]'))];
115
+ const scored = candidates.map((element) => ({
116
+ element,
117
+ prose: proseLength(element),
118
+ size: (element.textContent ?? '').length,
119
+ }));
120
+ const best = largest(scored.map((c) => c.prose));
121
+ return scored.filter((c) => c.prose >= best * 0.9).sort((a, b) => a.size - b.size)[0]?.element;
122
+ }
123
+ const HEADING = /^h([1-6])$/;
124
+ const HEADING_SELECTOR = 'h1, h2, h3, h4, h5, h6';
125
+ /** The page's article-title heading: the first `<h1>` in the region. */
126
+ function findTitleHeading(root) {
127
+ return Array.from(root.querySelectorAll('h1')).find((h) => isOutlineHeading(h, root));
128
+ }
129
+ /** True when nothing between `heading` and `root` is furniture or a figure or table. */
130
+ function isOutlineHeading(heading, root) {
131
+ for (let el = heading; el && el !== root; el = el.parentElement) {
132
+ if (isFurniture(el) || (el !== heading && floatKind(el)))
133
+ return false;
134
+ }
135
+ return true;
136
+ }
137
+ /**
138
+ * The region as a heading tree. Each element is either split around the section
139
+ * headings inside it or, when it holds none, kept whole as section content.
140
+ */
141
+ function buildOutline(root, titleHeading) {
142
+ const outline = { beforeTitle: 0, lead: [], sections: [] };
143
+ const stack = [];
144
+ const append = (node) => (stack.at(-1)?.nodes ?? outline.lead).push(node);
145
+ const titleText = textOfElement(titleHeading);
146
+ // Pages repeat the title in a sticky header; every heading reading as the title is the title.
147
+ const isTitle = (el) => el === titleHeading ||
148
+ (titleText !== '' && HEADING.test(tagOf(el)) && textOfElement(el) === titleText);
149
+ const visit = (parent) => {
150
+ for (const node of childNodes(parent)) {
151
+ if (!isElement(node)) {
152
+ append(node);
153
+ continue;
154
+ }
155
+ if (isTitle(node)) {
156
+ if (node !== titleHeading)
157
+ continue;
158
+ outline.beforeTitle = outline.sections.length;
159
+ stack.length = 0;
160
+ continue;
161
+ }
162
+ if (isFurniture(node))
163
+ continue;
164
+ // An empty heading (a label left to the stylesheet) marks no boundary.
165
+ const level = HEADING.exec(tagOf(node))?.[1];
166
+ if (level && textOfElement(node)) {
167
+ const section = {
168
+ heading: node,
169
+ level: Number(level),
170
+ nodes: [],
171
+ sections: [],
172
+ };
173
+ while ((stack.at(-1)?.level ?? 0) >= section.level)
174
+ stack.pop();
175
+ (stack.at(-1)?.sections ?? outline.sections).push(section);
176
+ stack.push(section);
177
+ }
178
+ else if (!floatKind(node) &&
179
+ Array.from(node.querySelectorAll(HEADING_SELECTOR)).some((h) => !isTitle(h) && isOutlineHeading(h, node))) {
180
+ visit(node);
181
+ }
182
+ else {
183
+ append(node);
184
+ }
185
+ }
186
+ };
187
+ visit(root);
188
+ return outline;
189
+ }
190
+ // ─── Classification ─────────────────────────────────────────────────────────
191
+ const REFERENCES_TITLE = /^(?:references?(?: and notes| cited)?|bibliography|literature cited|works cited|reference list|cited literature|notes and references)$/i;
192
+ /** Page furniture that arrives with a heading of its own. */
193
+ const FURNITURE_TITLE = /^(?:ask a research question|information|article details|figures?|tables?|figures and tables|similar (?:content|articles).*|related (?:articles|content|research)|recommended(?: articles)?|comments?|explore related subjects|about this article|rights and permissions|cite this article|article metrics|metrics|share(?: this article)?|author information|authors? and affiliations|associated data|download references|outline|keywords?|subjects?|article (?:information|info)|citations?|cited by|further reading|you may also (?:like|be interested in))$/i;
194
+ const ABSTRACT_TITLES = [
195
+ [/^(?:abstract|summary|structured abstract)$/i, 'main'],
196
+ [
197
+ /^(?:author summary|lay summary|plain[- ]language summary|significance(?: statement)?|executive summary|non-technical summary|in brief|editor'?s summary)$/i,
198
+ 'plain-language',
199
+ ],
200
+ [/^graphical abstract$/i, 'graphical'],
201
+ [/^(?:highlights|research highlights|key points|key findings)$/i, 'other'],
202
+ ];
203
+ function abstractKind(title) {
204
+ return ABSTRACT_TITLES.find(([pattern]) => pattern.test(title))?.[1];
205
+ }
206
+ /**
207
+ * Sort the outline's top-level sections: abstracts ahead of the body, the reference
208
+ * list, back matter by title, and furniture dropped. After the reference list only back
209
+ * matter is kept; publishers put recommendations, comments, and licensing boxes there.
210
+ */
211
+ function classify(outline, hasTitleHeading, ctx) {
212
+ const result = { abstracts: [], back: [], body: [], references: [] };
213
+ const plainTitle = (raw) => textOfElement(raw.heading).replace(/[:.]\s*$/, '');
214
+ const hasAbstractHeading = outline.sections.some((s) => abstractKind(plainTitle(s)) !== undefined);
215
+ // Content ahead of the first heading is the article's byline and dates when the page has a title heading or an abstract.
216
+ if (!hasTitleHeading && !hasAbstractHeading) {
217
+ const blocks = flowBlocks(outline.lead, ctx);
218
+ if (blocks.length > 0)
219
+ result.body.push({
220
+ blocks,
221
+ id: issueId(ctx.sectionIds, undefined, 's0'),
222
+ kind: 'body',
223
+ sections: [],
224
+ });
225
+ }
226
+ let seenAbstract = false;
227
+ let seenBody = false;
228
+ let afterReferences = false;
229
+ for (const raw of outline.sections.slice(outline.beforeTitle)) {
230
+ const title = plainTitle(raw);
231
+ // With an abstract heading on the page, headings ahead of it belong to the byline (author names, article type).
232
+ if (hasAbstractHeading && !seenAbstract && !abstractKind(title))
233
+ continue;
234
+ if (REFERENCES_TITLE.test(title)) {
235
+ if (result.references.length === 0)
236
+ result.references = extractReferences(allNodes(raw), ctx);
237
+ afterReferences = true;
238
+ continue;
239
+ }
240
+ const kind = kindFromTitle(title);
241
+ if (FURNITURE_TITLE.test(title) || (afterReferences && !kind)) {
242
+ // Furniture with a box of its own: what follows the box, before the next heading, is article text.
243
+ const container = openedContainer(raw.heading);
244
+ if (container && !afterReferences) {
245
+ const outside = (node) => !container.contains(node) && !(isElement(node) && isLinkList(node));
246
+ const blocks = flowBlocks(raw.nodes.filter(outside), ctx);
247
+ const sections = raw.sections
248
+ .filter((sub) => !container.contains(sub.heading))
249
+ .map((sub) => convert(sub, 'body', ctx, false))
250
+ .filter((sub) => sub !== undefined);
251
+ if (blocks.length > 0 || sections.length > 0) {
252
+ result.body.push({
253
+ blocks,
254
+ id: issueId(ctx.sectionIds, undefined, `s${ctx.sectionIds.size + 1}`),
255
+ kind: 'body',
256
+ sections,
257
+ });
258
+ seenBody = true;
259
+ }
260
+ }
261
+ continue;
262
+ }
263
+ const abstract = seenBody ? undefined : abstractKind(title);
264
+ if (abstract) {
265
+ seenAbstract = true;
266
+ const main = abstract === 'main' && result.abstracts.some((a) => a.kind === 'main') ? 'other' : abstract;
267
+ const sections = abstractSections(abstractScope(raw), ctx);
268
+ if (sections.length > 0) {
269
+ result.abstracts.push({
270
+ kind: main,
271
+ sections,
272
+ ...(!/^abstract$/i.test(title) && { title: inlineText(raw.heading, ctx) || title }),
273
+ });
274
+ }
275
+ continue;
276
+ }
277
+ const section = convert(raw, kind ?? 'body', ctx, false);
278
+ if (!section)
279
+ continue;
280
+ if (kind) {
281
+ result.back.push(section);
282
+ }
283
+ else {
284
+ result.body.push(section);
285
+ seenBody = true;
286
+ }
287
+ }
288
+ result.abstracts.sort((a, b) => Number(b.kind === 'main') - Number(a.kind === 'main'));
289
+ return result;
290
+ }
291
+ /** Every node of a raw section, its subsections' headings and content included. */
292
+ function allNodes(raw) {
293
+ return [...raw.nodes, ...raw.sections.flatMap((sub) => [sub.heading, ...allNodes(sub)])];
294
+ }
295
+ /**
296
+ * An abstract ends with its own container when the heading opens one (`<div class=
297
+ * "abstract"><h2>Abstract</h2>…</div>`): the article information a page sets after
298
+ * that container, before the next heading, is not part of the abstract.
299
+ */
300
+ function abstractScope(raw) {
301
+ const container = openedContainer(raw.heading);
302
+ if (!container)
303
+ return raw;
304
+ return { ...raw, nodes: raw.nodes.filter((node) => container.contains(node)) };
305
+ }
306
+ /**
307
+ * An abstract's sections, its parts at the top level as a JATS abstract's `<sec>`s are:
308
+ * content ahead of the first part is an untitled section of its own. A page that sets
309
+ * the parts without headings — sibling blocks each led by a bold label, as Cambridge's
310
+ * `<div class="sec"><span class="bold">Background</span><p>…` — has them read as parts.
311
+ */
312
+ function abstractSections(raw, ctx) {
313
+ const labelled = raw.sections.length === 0 ? labelledParts(raw.nodes, ctx) : undefined;
314
+ if (labelled)
315
+ return labelled;
316
+ const section = convert(raw, 'body', ctx, true);
317
+ if (!section)
318
+ return [];
319
+ if (section.blocks.length === 0) {
320
+ ctx.sectionIds.delete(section.id);
321
+ return section.sections;
322
+ }
323
+ return [
324
+ { blocks: section.blocks, id: section.id, kind: 'body', sections: [] },
325
+ ...section.sections,
326
+ ];
327
+ }
328
+ /** Nodes that carry content: elements other than furniture, and text that is not only whitespace. */
329
+ function significant(nodes) {
330
+ return nodes.filter((node) => isElement(node)
331
+ ? !isFurniture(node)
332
+ : node.nodeType === TEXT_NODE && (node.textContent ?? '').trim() !== '');
333
+ }
334
+ /** A part's label: a short bold element opening `element`, with a paragraph after it. */
335
+ function partLabel(element) {
336
+ const [first, ...rest] = significant(childNodes(element));
337
+ if (!first || !isElement(first))
338
+ return;
339
+ const bold = tagOf(first) === 'b' ||
340
+ tagOf(first) === 'strong' ||
341
+ nameTokens(first.getAttribute('class')).includes('bold');
342
+ const label = textOfElement(first);
343
+ if (!bold || !label || label.length > 60)
344
+ return;
345
+ return rest.some((node) => isElement(node) && tagOf(node) === 'p') ? first : undefined;
346
+ }
347
+ /** The nodes the parts sit among, single wrappers (`div.abstract-content > div.abstract`) looked through. */
348
+ function partSiblings(nodes) {
349
+ const children = significant(nodes);
350
+ const [only] = children;
351
+ return children.length === 1 && only && isElement(only) && !partLabel(only)
352
+ ? partSiblings(childNodes(only))
353
+ : children;
354
+ }
355
+ /** Sibling blocks each led by a bold label, as titled sections; undefined unless there are two or more and nothing else. */
356
+ function labelledParts(nodes, ctx) {
357
+ const parts = partSiblings(nodes).map((node) => {
358
+ const label = isElement(node) ? partLabel(node) : undefined;
359
+ return label && isElement(node) ? { element: node, label } : undefined;
360
+ });
361
+ if (parts.length < 2)
362
+ return;
363
+ const sections = [];
364
+ for (const part of parts) {
365
+ if (!part)
366
+ return;
367
+ const content = childNodes(part.element).filter((node) => node !== part.label);
368
+ const title = inlineText(part.label, ctx).replace(/[:.]\s*$/, '');
369
+ const sourceId = part.element.getAttribute('id') ?? undefined;
370
+ sections.push({
371
+ blocks: flowBlocks(content, ctx),
372
+ id: issueId(ctx.sectionIds, sourceId, `s${ctx.sectionIds.size + 1}`),
373
+ kind: 'body',
374
+ sections: [],
375
+ ...(title && { title }),
376
+ });
377
+ }
378
+ return sections;
379
+ }
380
+ /** The element a heading opens: its parent, when nothing with text comes before the heading in it. */
381
+ function openedContainer(heading) {
382
+ const parent = heading.parentElement;
383
+ if (!parent)
384
+ return;
385
+ for (let el = heading.previousElementSibling; el; el = el.previousElementSibling) {
386
+ if (textOfElement(el))
387
+ return;
388
+ }
389
+ return parent;
390
+ }
391
+ function convert(raw, kind, ctx, untitled) {
392
+ const { label, title } = splitSectionNumber(inlineText(raw.heading, ctx) || undefined, undefined);
393
+ const sourceId = raw.heading.getAttribute('id') ?? openedContainer(raw.heading)?.getAttribute('id') ?? undefined;
394
+ const id = issueId(ctx.sectionIds, sourceId, untitled ? 'abstract' : `s${ctx.sectionIds.size + 1}`);
395
+ const blocks = flowBlocks(raw.nodes, ctx);
396
+ const sections = raw.sections
397
+ .map((sub) => convert(sub, kind, ctx, false))
398
+ .filter((s) => s !== undefined);
399
+ if (blocks.length === 0 && sections.length === 0) {
400
+ ctx.sectionIds.delete(id);
401
+ return;
402
+ }
403
+ return { blocks, id, kind, ...(label && { label }), sections, ...(title && { title }) };
404
+ }
405
+ //# sourceMappingURL=parse.js.map