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
package/dist/html/dom.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Node, and Workers without a browser.
|
|
5
5
|
* @module src/html/dom
|
|
6
6
|
*/
|
|
7
|
+
import { MAX_XML_DEPTH } from '../model/limits.js';
|
|
7
8
|
import { MissingPeerError } from '../model/result.js';
|
|
8
9
|
let linkedom;
|
|
9
10
|
/**
|
|
@@ -14,7 +15,7 @@ let linkedom;
|
|
|
14
15
|
* a lone `<` escapes as plain text that the next node then turns into a tag. Merging
|
|
15
16
|
* adjacent text nodes lets escaping see each run whole.
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
+
async function loadDocument(html) {
|
|
18
19
|
linkedom ??= import('linkedom').catch((error) => {
|
|
19
20
|
linkedom = undefined;
|
|
20
21
|
throw new MissingPeerError('Install "linkedom" to parse HTML: bun add linkedom', {
|
|
@@ -25,8 +26,25 @@ export async function loadDocument(html) {
|
|
|
25
26
|
document.documentElement?.normalize();
|
|
26
27
|
return document;
|
|
27
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Parse HTML into a document no element of which nests deeper than `MAX_XML_DEPTH`, and
|
|
31
|
+
* count the tags left out to get there. Each tag of an element that would open deeper is
|
|
32
|
+
* removed before `linkedom` parses, its text kept (see {@link boundNesting}): the DOM
|
|
33
|
+
* engine and every recursive walk over its tree then work at a depth real pages never
|
|
34
|
+
* reach, in time linear in the page. Throws as {@link loadDocument} does.
|
|
35
|
+
*/
|
|
36
|
+
export async function loadBoundedDocument(html) {
|
|
37
|
+
const bounded = boundNesting(html, MAX_XML_DEPTH);
|
|
38
|
+
return { document: await loadDocument(bounded.html), droppedTags: bounded.dropped };
|
|
39
|
+
}
|
|
40
|
+
/** The `truncated-input` warning for a page {@link loadBoundedDocument} dropped tags from. */
|
|
41
|
+
export function truncatedNestingMessage(droppedTags) {
|
|
42
|
+
return `Markup nested deeper than ${MAX_XML_DEPTH} levels: ${droppedTags} tags left out, their text kept`;
|
|
43
|
+
}
|
|
28
44
|
export const ELEMENT_NODE = 1;
|
|
29
45
|
export const TEXT_NODE = 3;
|
|
46
|
+
/** A CDATA section's node type: text that `textContent` counts, as it does a text node's. */
|
|
47
|
+
export const CDATA_SECTION_NODE = 4;
|
|
30
48
|
export const COMMENT_NODE = 8;
|
|
31
49
|
/** True for an element node. */
|
|
32
50
|
export function isElement(node) {
|
|
@@ -67,4 +85,444 @@ export function resolveUrl(url, base) {
|
|
|
67
85
|
return url;
|
|
68
86
|
}
|
|
69
87
|
}
|
|
88
|
+
// ─── Nesting bound ──────────────────────────────────────────────────────────
|
|
89
|
+
//
|
|
90
|
+
// The scan mirrors how htmlparser2 10.1.0, which `linkedom` parses with, reads markup and
|
|
91
|
+
// keeps its stack of open elements, so the depth it counts is the depth `linkedom` builds.
|
|
92
|
+
// The HTML standard's tree builder would count differently: htmlparser2 closes an element
|
|
93
|
+
// implicitly only while it is innermost (`<p><li><td>` repeated nests), and reads `<x/>`
|
|
94
|
+
// as an open tag outside `<math>` and `<svg>`.
|
|
95
|
+
/** Elements htmlparser2 never puts on its stack. */
|
|
96
|
+
const VOID_TAGS = new Set([
|
|
97
|
+
'area',
|
|
98
|
+
'base',
|
|
99
|
+
'basefont',
|
|
100
|
+
'br',
|
|
101
|
+
'col',
|
|
102
|
+
'command',
|
|
103
|
+
'embed',
|
|
104
|
+
'frame',
|
|
105
|
+
'hr',
|
|
106
|
+
'img',
|
|
107
|
+
'input',
|
|
108
|
+
'isindex',
|
|
109
|
+
'keygen',
|
|
110
|
+
'link',
|
|
111
|
+
'meta',
|
|
112
|
+
'param',
|
|
113
|
+
'source',
|
|
114
|
+
'track',
|
|
115
|
+
'wbr',
|
|
116
|
+
]);
|
|
117
|
+
const P_TAG = new Set(['p']);
|
|
118
|
+
const FORM_TAGS = new Set([
|
|
119
|
+
'button',
|
|
120
|
+
'datalist',
|
|
121
|
+
'input',
|
|
122
|
+
'optgroup',
|
|
123
|
+
'option',
|
|
124
|
+
'select',
|
|
125
|
+
'textarea',
|
|
126
|
+
]);
|
|
127
|
+
const TABLE_SECTIONS = new Set(['tbody', 'thead']);
|
|
128
|
+
const DEFINITION_TAGS = new Set(['dd', 'dt']);
|
|
129
|
+
const RUBY_TAGS = new Set(['rp', 'rt']);
|
|
130
|
+
/** For each tag, the elements its open tag closes while one of them is innermost. */
|
|
131
|
+
const IMPLIED_CLOSES = new Map([
|
|
132
|
+
['tr', new Set(['td', 'th', 'tr'])],
|
|
133
|
+
['th', new Set(['th'])],
|
|
134
|
+
['td', new Set(['td', 'th', 'thead'])],
|
|
135
|
+
['body', new Set(['head', 'link', 'script'])],
|
|
136
|
+
['li', new Set(['li'])],
|
|
137
|
+
...['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'].map((tag) => [
|
|
138
|
+
tag,
|
|
139
|
+
P_TAG,
|
|
140
|
+
]),
|
|
141
|
+
...['select', 'input', 'output', 'button', 'datalist', 'textarea'].map((tag) => [tag, FORM_TAGS]),
|
|
142
|
+
['option', new Set(['option'])],
|
|
143
|
+
['optgroup', new Set(['optgroup', 'option'])],
|
|
144
|
+
['dd', DEFINITION_TAGS],
|
|
145
|
+
['dt', DEFINITION_TAGS],
|
|
146
|
+
...[
|
|
147
|
+
'address',
|
|
148
|
+
'article',
|
|
149
|
+
'aside',
|
|
150
|
+
'blockquote',
|
|
151
|
+
'details',
|
|
152
|
+
'div',
|
|
153
|
+
'dl',
|
|
154
|
+
'fieldset',
|
|
155
|
+
'figcaption',
|
|
156
|
+
'figure',
|
|
157
|
+
'footer',
|
|
158
|
+
'form',
|
|
159
|
+
'header',
|
|
160
|
+
'hr',
|
|
161
|
+
'main',
|
|
162
|
+
'nav',
|
|
163
|
+
'ol',
|
|
164
|
+
'pre',
|
|
165
|
+
'section',
|
|
166
|
+
'table',
|
|
167
|
+
'ul',
|
|
168
|
+
].map((tag) => [tag, P_TAG]),
|
|
169
|
+
['rt', RUBY_TAGS],
|
|
170
|
+
['rp', RUBY_TAGS],
|
|
171
|
+
['tbody', TABLE_SECTIONS],
|
|
172
|
+
['tfoot', TABLE_SECTIONS],
|
|
173
|
+
]);
|
|
174
|
+
/** Elements whose content is foreign, where `<x/>` closes itself. */
|
|
175
|
+
const FOREIGN_TAGS = new Set(['math', 'svg']);
|
|
176
|
+
/** Elements whose content is HTML again inside foreign content. */
|
|
177
|
+
const INTEGRATION_TAGS = new Set([
|
|
178
|
+
'annotation-xml',
|
|
179
|
+
'desc',
|
|
180
|
+
'foreignobject',
|
|
181
|
+
'mi',
|
|
182
|
+
'mn',
|
|
183
|
+
'mo',
|
|
184
|
+
'ms',
|
|
185
|
+
'mtext',
|
|
186
|
+
'title',
|
|
187
|
+
]);
|
|
188
|
+
/**
|
|
189
|
+
* Raw-text elements, by the names htmlparser2 recognizes them by, each with the close tag
|
|
190
|
+
* that ends its text. The tokenizer matches a name letter by letter and takes one branch
|
|
191
|
+
* for a name opening with `t` or `x`, so `<xitle>` is read as raw text to `</title>`.
|
|
192
|
+
*/
|
|
193
|
+
const RAW_TEXT = new Map([
|
|
194
|
+
['script', 'script'],
|
|
195
|
+
['style', 'style'],
|
|
196
|
+
['title', 'title'],
|
|
197
|
+
['xitle', 'title'],
|
|
198
|
+
['textarea', 'textarea'],
|
|
199
|
+
['xextarea', 'textarea'],
|
|
200
|
+
['xmp', 'xmp'],
|
|
201
|
+
['tmp', 'xmp'],
|
|
202
|
+
]);
|
|
203
|
+
const LT = 0x3c;
|
|
204
|
+
const GT = 0x3e;
|
|
205
|
+
const SLASH = 0x2f;
|
|
206
|
+
const EXCLAMATION = 0x21;
|
|
207
|
+
const QUESTION = 0x3f;
|
|
208
|
+
const QUOTE = 0x22;
|
|
209
|
+
const APOSTROPHE = 0x27;
|
|
210
|
+
const EQUALS = 0x3d;
|
|
211
|
+
/** An open tag's name: up to a space, `/`, or `>`. A close tag's: up to a space or `>`. */
|
|
212
|
+
const OPEN_NAME = /[^\t\n\f\r />]*/y;
|
|
213
|
+
const CLOSE_NAME = /[^\t\n\f\r >]*/y;
|
|
214
|
+
function isSpace(code) {
|
|
215
|
+
return code === 0x20 || code === 0x0a || code === 0x09 || code === 0x0c || code === 0x0d;
|
|
216
|
+
}
|
|
217
|
+
function isAsciiLetter(code) {
|
|
218
|
+
return (code >= 0x41 && code <= 0x5a) || (code >= 0x61 && code <= 0x7a);
|
|
219
|
+
}
|
|
220
|
+
/** Where a sticky pattern's match from `from` ends. */
|
|
221
|
+
function matchEnd(pattern, text, from) {
|
|
222
|
+
pattern.lastIndex = from;
|
|
223
|
+
pattern.exec(text);
|
|
224
|
+
return pattern.lastIndex;
|
|
225
|
+
}
|
|
226
|
+
/** The index after the first `token` at or past `from`; the end of the text when there is none. */
|
|
227
|
+
function after(text, token, from) {
|
|
228
|
+
const at = text.indexOf(token, from);
|
|
229
|
+
return at === -1 ? text.length : at + token.length;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* `html` with the tags of every element that would open deeper than `max` levels taken
|
|
233
|
+
* out, and how many tags that was. Each tag removed becomes a space, so the words either
|
|
234
|
+
* side stay apart, and the element's text stays where it was; a close tag whose open tag
|
|
235
|
+
* was removed goes too, and so does every tag inside its element. One pass, in time
|
|
236
|
+
* linear in the markup: an element is found by name in one step rather than by searching
|
|
237
|
+
* the stack, as htmlparser2 does per close tag.
|
|
238
|
+
*
|
|
239
|
+
* htmlparser2 also keeps a stack of foreign-content flags, which it grows by `unshift`: a
|
|
240
|
+
* `<math>`, `<svg>`, or element of {@link INTEGRATION_TAGS} adds one, and only a close tag
|
|
241
|
+
* of one of those names removes one, so each element of them that closes otherwise (`<math/>`,
|
|
242
|
+
* `<b><mi></b>`) leaves its flag behind. Past `max` flags, such an element is removed too.
|
|
243
|
+
*
|
|
244
|
+
* Text htmlparser2 reads raw (`<script>`, `<style>`, `<title>`, `<textarea>`, `<xmp>`) and
|
|
245
|
+
* comments hold no tags. A raw-text element that is itself removed loses its content when
|
|
246
|
+
* that is code (script, style) and keeps it, escaped, otherwise.
|
|
247
|
+
*/
|
|
248
|
+
export function boundNesting(html, max) {
|
|
249
|
+
const scan = {
|
|
250
|
+
copied: 0,
|
|
251
|
+
dropped: 0,
|
|
252
|
+
foreignAll: [false],
|
|
253
|
+
foreignKept: [false],
|
|
254
|
+
html,
|
|
255
|
+
kept: 0,
|
|
256
|
+
max,
|
|
257
|
+
open: [],
|
|
258
|
+
openAt: new Map(),
|
|
259
|
+
out: [],
|
|
260
|
+
};
|
|
261
|
+
for (let at = html.indexOf('<'); at !== -1 && at < html.length; at = html.indexOf('<', at)) {
|
|
262
|
+
at = readMarkup(scan, at);
|
|
263
|
+
}
|
|
264
|
+
if (scan.dropped === 0)
|
|
265
|
+
return { dropped: 0, html };
|
|
266
|
+
scan.out.push(html.slice(scan.copied));
|
|
267
|
+
return { dropped: scan.dropped, html: scan.out.join('') };
|
|
268
|
+
}
|
|
269
|
+
/** Read the markup a `<` opens, if any; returns where text resumes. */
|
|
270
|
+
function readMarkup(scan, lt) {
|
|
271
|
+
const { html } = scan;
|
|
272
|
+
const next = html.charCodeAt(lt + 1);
|
|
273
|
+
if (next === EXCLAMATION)
|
|
274
|
+
return declarationEnd(html, lt);
|
|
275
|
+
if (next === QUESTION)
|
|
276
|
+
return after(html, '>', lt + 2);
|
|
277
|
+
if (next === SLASH)
|
|
278
|
+
return readCloseTag(scan, lt);
|
|
279
|
+
if (isAsciiLetter(next))
|
|
280
|
+
return readOpenTag(scan, lt);
|
|
281
|
+
return lt + 1;
|
|
282
|
+
}
|
|
283
|
+
/** The end of a `<!…>` construct: a comment, a CDATA section, or a declaration. */
|
|
284
|
+
function declarationEnd(html, lt) {
|
|
285
|
+
if (html.startsWith('--', lt + 2))
|
|
286
|
+
return after(html, '-->', lt + 2);
|
|
287
|
+
const third = html.charAt(lt + 2);
|
|
288
|
+
// `<!-x` is a declaration from the character after the `x`.
|
|
289
|
+
if (third === '-')
|
|
290
|
+
return after(html, '>', lt + 4);
|
|
291
|
+
if (third === '[') {
|
|
292
|
+
let matched = 0;
|
|
293
|
+
while (matched < 6 && html.charAt(lt + 3 + matched) === 'CDATA['.charAt(matched))
|
|
294
|
+
matched++;
|
|
295
|
+
return matched === 6 ? after(html, ']]>', lt + 9) : after(html, '>', lt + 3 + matched);
|
|
296
|
+
}
|
|
297
|
+
return after(html, '>', lt + 3);
|
|
298
|
+
}
|
|
299
|
+
function readCloseTag(scan, lt) {
|
|
300
|
+
const { html } = scan;
|
|
301
|
+
let at = lt + 2;
|
|
302
|
+
while (isSpace(html.charCodeAt(at)))
|
|
303
|
+
at++;
|
|
304
|
+
if (at >= html.length)
|
|
305
|
+
return html.length;
|
|
306
|
+
const first = html.charCodeAt(at);
|
|
307
|
+
if (first === GT)
|
|
308
|
+
return at + 1;
|
|
309
|
+
// `</` and anything but a letter opens a comment that runs to the next `>`.
|
|
310
|
+
if (!isAsciiLetter(first))
|
|
311
|
+
return after(html, '>', at);
|
|
312
|
+
const nameEnd = matchEnd(CLOSE_NAME, html, at);
|
|
313
|
+
if (nameEnd >= html.length)
|
|
314
|
+
return html.length;
|
|
315
|
+
const end = after(html, '>', nameEnd);
|
|
316
|
+
closeTag(scan, html.slice(at, nameEnd).toLowerCase(), lt, end, false);
|
|
317
|
+
return end;
|
|
318
|
+
}
|
|
319
|
+
function readOpenTag(scan, lt) {
|
|
320
|
+
const { html } = scan;
|
|
321
|
+
const nameEnd = matchEnd(OPEN_NAME, html, lt + 1);
|
|
322
|
+
const tag = openTagEnd(html, nameEnd);
|
|
323
|
+
if (!tag)
|
|
324
|
+
return html.length;
|
|
325
|
+
const name = html.slice(lt + 1, nameEnd).toLowerCase();
|
|
326
|
+
const kept = openTag(scan, name, tag.selfClosing, lt, tag.end);
|
|
327
|
+
const closer = tag.selfClosing ? undefined : RAW_TEXT.get(name);
|
|
328
|
+
return closer ? readRawText(scan, closer, tag.end, kept) : tag.end;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* The index after an open tag whose name ends at `from`, and whether it ends `/>`.
|
|
332
|
+
* Attributes are read as htmlparser2 reads them, so a `>` in a quoted value does not end
|
|
333
|
+
* the tag. Undefined when the markup ends first, as htmlparser2 then drops the tag.
|
|
334
|
+
*/
|
|
335
|
+
function openTagEnd(html, from) {
|
|
336
|
+
// 0: before an attribute name; 1: after a `/`; 2: in a name; 3: after a name;
|
|
337
|
+
// 4: before a value; 5: in an unquoted value.
|
|
338
|
+
let state = 0;
|
|
339
|
+
for (let at = from; at < html.length; at++) {
|
|
340
|
+
const code = html.charCodeAt(at);
|
|
341
|
+
switch (state) {
|
|
342
|
+
case 0:
|
|
343
|
+
if (code === GT)
|
|
344
|
+
return { end: at + 1, selfClosing: false };
|
|
345
|
+
if (code === SLASH)
|
|
346
|
+
state = 1;
|
|
347
|
+
else if (!isSpace(code))
|
|
348
|
+
state = 2;
|
|
349
|
+
break;
|
|
350
|
+
case 1:
|
|
351
|
+
if (code === GT)
|
|
352
|
+
return { end: at + 1, selfClosing: true };
|
|
353
|
+
if (!isSpace(code)) {
|
|
354
|
+
state = 0;
|
|
355
|
+
at--;
|
|
356
|
+
}
|
|
357
|
+
break;
|
|
358
|
+
case 2:
|
|
359
|
+
if (code === EQUALS || code === SLASH || code === GT || isSpace(code)) {
|
|
360
|
+
state = 3;
|
|
361
|
+
at--;
|
|
362
|
+
}
|
|
363
|
+
break;
|
|
364
|
+
case 3:
|
|
365
|
+
if (code === EQUALS)
|
|
366
|
+
state = 4;
|
|
367
|
+
else if (code === SLASH || code === GT) {
|
|
368
|
+
state = 0;
|
|
369
|
+
at--;
|
|
370
|
+
}
|
|
371
|
+
else if (!isSpace(code))
|
|
372
|
+
state = 2;
|
|
373
|
+
break;
|
|
374
|
+
case 4:
|
|
375
|
+
if (code === QUOTE || code === APOSTROPHE) {
|
|
376
|
+
at = html.indexOf(code === QUOTE ? '"' : "'", at + 1);
|
|
377
|
+
if (at === -1)
|
|
378
|
+
return;
|
|
379
|
+
state = 0;
|
|
380
|
+
}
|
|
381
|
+
else if (!isSpace(code)) {
|
|
382
|
+
state = 5;
|
|
383
|
+
at--;
|
|
384
|
+
}
|
|
385
|
+
break;
|
|
386
|
+
default:
|
|
387
|
+
if (code === GT || isSpace(code)) {
|
|
388
|
+
state = 0;
|
|
389
|
+
at--;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* The text of a raw-text element, up to the close tag that ends it, which is then read
|
|
397
|
+
* like any close tag. htmlparser2 matches that tag as `</name` and a space or `>`,
|
|
398
|
+
* comparing each character `| 0x20`, which also takes `\x1C` for `<` and `\x0F` for `/`.
|
|
399
|
+
*/
|
|
400
|
+
function readRawText(scan, closer, from, kept) {
|
|
401
|
+
const { html } = scan;
|
|
402
|
+
const at = rawTextEnd(html, closer, from);
|
|
403
|
+
const end = at === -1 ? html.length : at;
|
|
404
|
+
if (!kept) {
|
|
405
|
+
// With its open tag gone the text would be read as markup.
|
|
406
|
+
const text = html.slice(from, end);
|
|
407
|
+
replace(scan, from, end, closer === 'script' || closer === 'style'
|
|
408
|
+
? ''
|
|
409
|
+
: closer === 'title'
|
|
410
|
+
? text.replace(/</g, '<')
|
|
411
|
+
: text.replace(/&/g, '&').replace(/</g, '<'));
|
|
412
|
+
}
|
|
413
|
+
if (at === -1)
|
|
414
|
+
return html.length;
|
|
415
|
+
const tagEnd = after(html, '>', at + 2 + closer.length);
|
|
416
|
+
closeTag(scan, closer, at, tagEnd, !kept);
|
|
417
|
+
return tagEnd;
|
|
418
|
+
}
|
|
419
|
+
/** Where the close tag that ends raw text named `name` starts; -1 when none does. */
|
|
420
|
+
function rawTextEnd(html, name, from) {
|
|
421
|
+
const sequence = `</${name}`;
|
|
422
|
+
let matched = 0;
|
|
423
|
+
for (let at = from; at < html.length; at++) {
|
|
424
|
+
const code = html.charCodeAt(at);
|
|
425
|
+
if (matched === sequence.length) {
|
|
426
|
+
if (code === GT || isSpace(code))
|
|
427
|
+
return at - sequence.length;
|
|
428
|
+
matched = 0;
|
|
429
|
+
}
|
|
430
|
+
if ((code | 0x20) === sequence.charCodeAt(matched))
|
|
431
|
+
matched++;
|
|
432
|
+
else if (matched > 0)
|
|
433
|
+
matched = code === LT ? 1 : 0;
|
|
434
|
+
else if (name !== 'title') {
|
|
435
|
+
// Outside a title the tokenizer skips to the next `<` and counts it matched.
|
|
436
|
+
at = html.indexOf('<', at + 1);
|
|
437
|
+
if (at === -1)
|
|
438
|
+
return -1;
|
|
439
|
+
matched = 1;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return -1;
|
|
443
|
+
}
|
|
444
|
+
/** Read an open tag into the stack; false when its element is too deep and the tag was dropped. */
|
|
445
|
+
function openTag(scan, name, selfClosing, start, end) {
|
|
446
|
+
const { open } = scan;
|
|
447
|
+
const closes = IMPLIED_CLOSES.get(name);
|
|
448
|
+
while (closes?.has(open.at(-1) ?? ''))
|
|
449
|
+
pop(scan);
|
|
450
|
+
const flagged = FOREIGN_TAGS.has(name) || INTEGRATION_TAGS.has(name);
|
|
451
|
+
// No name with a flag implies a close, so a tag dropped here closed nothing the output keeps.
|
|
452
|
+
const kept = hasRoom(scan) && !(flagged && scan.foreignKept.length > scan.max);
|
|
453
|
+
if (!VOID_TAGS.has(name)) {
|
|
454
|
+
push(scan, name);
|
|
455
|
+
if (kept)
|
|
456
|
+
scan.kept++;
|
|
457
|
+
if (flagged) {
|
|
458
|
+
const foreign = FOREIGN_TAGS.has(name);
|
|
459
|
+
scan.foreignAll.push(foreign);
|
|
460
|
+
if (kept)
|
|
461
|
+
scan.foreignKept.push(foreign);
|
|
462
|
+
}
|
|
463
|
+
if (selfClosing && (kept ? scan.foreignKept : scan.foreignAll).at(-1))
|
|
464
|
+
pop(scan);
|
|
465
|
+
}
|
|
466
|
+
if (!kept) {
|
|
467
|
+
scan.dropped++;
|
|
468
|
+
replace(scan, start, end, ' ');
|
|
469
|
+
}
|
|
470
|
+
return kept;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Read a close tag into the stack, dropping it when the element it closes was dropped.
|
|
474
|
+
* `ofDropped` marks the tag ending the text of a raw-text element that was dropped: it
|
|
475
|
+
* goes with its element, so it closes nothing the output keeps.
|
|
476
|
+
*/
|
|
477
|
+
function closeTag(scan, name, start, end, ofDropped) {
|
|
478
|
+
const { open } = scan;
|
|
479
|
+
let kept;
|
|
480
|
+
if (VOID_TAGS.has(name)) {
|
|
481
|
+
// `</br>` makes a `<br>`; any other void close tag is ignored.
|
|
482
|
+
kept = !ofDropped && (name !== 'br' || hasRoom(scan));
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
const at = scan.openAt.get(name)?.at(-1);
|
|
486
|
+
// An unmatched `</p>` makes a `<p>`.
|
|
487
|
+
if (at === undefined)
|
|
488
|
+
kept = !ofDropped && (name !== 'p' || hasRoom(scan));
|
|
489
|
+
else
|
|
490
|
+
kept = !ofDropped && at < scan.kept;
|
|
491
|
+
if (FOREIGN_TAGS.has(name) || INTEGRATION_TAGS.has(name)) {
|
|
492
|
+
scan.foreignAll.pop();
|
|
493
|
+
if (kept)
|
|
494
|
+
scan.foreignKept.pop();
|
|
495
|
+
}
|
|
496
|
+
if (at !== undefined && (kept || at >= scan.kept))
|
|
497
|
+
while (open.length > at)
|
|
498
|
+
pop(scan);
|
|
499
|
+
}
|
|
500
|
+
if (!kept) {
|
|
501
|
+
scan.dropped++;
|
|
502
|
+
replace(scan, start, end, ' ');
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
function push(scan, name) {
|
|
506
|
+
const indexes = scan.openAt.get(name);
|
|
507
|
+
if (indexes)
|
|
508
|
+
indexes.push(scan.open.length);
|
|
509
|
+
else
|
|
510
|
+
scan.openAt.set(name, [scan.open.length]);
|
|
511
|
+
scan.open.push(name);
|
|
512
|
+
}
|
|
513
|
+
function pop(scan) {
|
|
514
|
+
const name = scan.open.pop();
|
|
515
|
+
if (name !== undefined)
|
|
516
|
+
scan.openAt.get(name)?.pop();
|
|
517
|
+
scan.kept = Math.min(scan.kept, scan.open.length);
|
|
518
|
+
}
|
|
519
|
+
/** True when an element opened now would be kept: none open is dropped, and it is not too deep. */
|
|
520
|
+
function hasRoom(scan) {
|
|
521
|
+
return scan.open.length === scan.kept && scan.kept < scan.max;
|
|
522
|
+
}
|
|
523
|
+
/** Write the source up to `start`, then `text` in place of `start`…`end`. */
|
|
524
|
+
function replace(scan, start, end, text) {
|
|
525
|
+
scan.out.push(scan.html.slice(scan.copied, start), text);
|
|
526
|
+
scan.copied = end;
|
|
527
|
+
}
|
|
70
528
|
//# sourceMappingURL=dom.js.map
|
package/dist/html/dom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom.js","sourceRoot":"","sources":["../../src/html/dom.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAItD,IAAI,QAA6C,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,IAAY;IAC7C,QAAQ,KAAM,MAAM,CAAC,UAAU,CAA6B,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QACpF,QAAQ,GAAG,SAAS,CAAC;QACrB,MAAM,IAAI,gBAAgB,CAAC,oDAAoD,EAAE;YAC/E,KAAK,EAAE,KAAK;SACb,CAAC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CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TeX for a MathML `<math>` element: its `application/x-tex` annotation (KaTeX and
|
|
3
|
+
* LaTeXML keep one), else its `alttext`, else the presentation markup linearized. Empty
|
|
4
|
+
* when all three are.
|
|
5
|
+
*/
|
|
6
|
+
export declare function domMathTex(math: Element): string;
|
|
7
|
+
//# sourceMappingURL=math.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../src/html/math.ts"],"names":[],"mappings":"AAyBA;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAShD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview TeX for MathML in an HTML page: the TeX the page keeps beside it, else
|
|
3
|
+
* the presentation markup linearized as `mathmlToTex` does for JATS. Nodes are read
|
|
4
|
+
* through standard DOM properties only, so nothing here loads `linkedom`, and the XML
|
|
5
|
+
* subpaths, which import `src/xml/mathml.ts`, load no DOM code.
|
|
6
|
+
* @module src/html/math
|
|
7
|
+
*/
|
|
8
|
+
import { mathmlToTex } from '../xml/mathml.js';
|
|
9
|
+
import { isElement, TEXT_NODE, tagOf } from './dom.js';
|
|
10
|
+
/** A DOM read as MathML: elements by their lowercase local name, and text. Comments are skipped. */
|
|
11
|
+
const DOM_NODES = {
|
|
12
|
+
attr: (node, name) => (isElement(node) ? (node.getAttribute(name) ?? undefined) : undefined),
|
|
13
|
+
children: (node) => Array.from(node.childNodes).filter((child) => isElement(child) || child.nodeType === TEXT_NODE),
|
|
14
|
+
isText: (node) => node.nodeType === TEXT_NODE,
|
|
15
|
+
name: (node) => {
|
|
16
|
+
if (!isElement(node))
|
|
17
|
+
return;
|
|
18
|
+
const tag = tagOf(node);
|
|
19
|
+
return tag.slice(tag.indexOf(':') + 1);
|
|
20
|
+
},
|
|
21
|
+
text: (node) => node.nodeType === TEXT_NODE ? (node.textContent ?? '').replace(/\u00AD/g, '') : '',
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* TeX for a MathML `<math>` element: its `application/x-tex` annotation (KaTeX and
|
|
25
|
+
* LaTeXML keep one), else its `alttext`, else the presentation markup linearized. Empty
|
|
26
|
+
* when all three are.
|
|
27
|
+
*/
|
|
28
|
+
export function domMathTex(math) {
|
|
29
|
+
const annotation = Array.from(math.getElementsByTagName('annotation')).find((a) => (a.getAttribute('encoding') ?? '').toLowerCase() === 'application/x-tex');
|
|
30
|
+
return ((annotation?.textContent ?? '').trim() ||
|
|
31
|
+
(math.getAttribute('alttext') ?? '').trim() ||
|
|
32
|
+
mathmlToTex(math, DOM_NODES));
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=math.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.js","sourceRoot":"","sources":["../../src/html/math.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAkB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEvD,oGAAoG;AACpG,MAAM,SAAS,GAAoB;IACjC,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5F,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CACjB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC;IACjG,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS;IAC7C,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE;QACb,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YAAE,OAAO;QAC7B,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;QACxB,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IACzC,CAAC;IACD,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CACb,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE;CACrF,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,IAAa;IACtC,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CACzE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,KAAK,mBAAmB,CAChF,CAAC;IACF,OAAO,CACL,CAAC,UAAU,EAAE,WAAW,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;QACtC,CAAC,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;QAC3C,WAAW,CAAO,IAAI,EAAE,SAAS,CAAC,CACnC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview arXiv IDs as the model holds them, in arXiv's preferred external form: a
|
|
3
|
+
* new-style `YYMM.NNNNN` or an old-style `archive/YYMMNNN` without the subject class an
|
|
4
|
+
* old-style ID may carry (`math.GT/0309136` → `math/0309136`), with any version the
|
|
5
|
+
* source prints kept (`2105.00001v2`). One grammar serves every format: the LaTeXML,
|
|
6
|
+
* HTML, and PDF references read the ID an `arXiv` label, an arxiv.org link, or an
|
|
7
|
+
* old-style form in an entry's text gives, the LaTeXML watermark and page URL read the
|
|
8
|
+
* paper's own ID here, and a field the source types as an arXiv ID (JATS `pub-id-type`
|
|
9
|
+
* `arxiv`, TEI `<idno type="arXiv">`, HTML `citation_arxiv_id`) is read here too.
|
|
10
|
+
* @module src/model/arxiv
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* `value` as an arXiv ID in the model's form, when the whole of it is one: a new-style ID
|
|
14
|
+
* whose month exists and whose number has the four digits of 0704–1412 or the five from
|
|
15
|
+
* 1501, or an old-style ID whose archive arXiv used before April 2007 and whose YYMM falls
|
|
16
|
+
* in 9107–0703, its subject class dropped. A version is kept, and must be `v1` or later.
|
|
17
|
+
* Undefined otherwise.
|
|
18
|
+
*/
|
|
19
|
+
export declare function arxivId(value: string): string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* The arXiv ID a link to a paper names in its `/abs/` or `/pdf/` path on arxiv.org,
|
|
22
|
+
* ar5iv.org, or a subdomain of either (`https://arxiv.org/pdf/2105.00001v1.pdf` →
|
|
23
|
+
* `2105.00001v1`, `https://export.arxiv.org/abs/hep-th/9711200`), read as
|
|
24
|
+
* {@link arxivId} reads one. A link to any other host or path, or whose path holds more
|
|
25
|
+
* than the ID, names none.
|
|
26
|
+
*/
|
|
27
|
+
export declare function arxivFromUrl(url: string | undefined): string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* A field the source types as an arXiv ID, as the model holds it: the ID read as
|
|
30
|
+
* {@link arxivId} reads one, or the one an arxiv.org link names, without an `arXiv`
|
|
31
|
+
* label or a bracketed subject class after it (`arXiv:math.GT/0309136v1 [math.GT]` →
|
|
32
|
+
* `math/0309136v1`, `https://arxiv.org/abs/2105.00001v3` → `2105.00001v3`). Undefined
|
|
33
|
+
* for anything else (`pending`, `n/a`, `hep-th/0805123`), so every format reads the same
|
|
34
|
+
* value from the same field.
|
|
35
|
+
*/
|
|
36
|
+
export declare function normalizeArxiv(value: string | undefined): string | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* The arXiv ID of the page a LaTeXML render was served at: an arxiv.org or ar5iv
|
|
39
|
+
* `/html/` or `/abs/` URL (`https://ar5iv.labs.arxiv.org/html/math.GT/0309136` →
|
|
40
|
+
* `math/0309136`), read as {@link arxivId} reads one.
|
|
41
|
+
*/
|
|
42
|
+
export declare function arxivFromPageUrl(url: string | undefined): string | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* The first arXiv ID in `text`, read as {@link arxivId} reads one: after an `arXiv`
|
|
45
|
+
* label in any case (`arXiv:hep-th/9711200`, `arXiv 1706.03762`), in an arxiv.org link
|
|
46
|
+
* (`https://arxiv.org/abs/2105.00001v3`), or bare in the old style (`…, hep-th/9711200.`).
|
|
47
|
+
* A bare new-style number (`1999.12345`) could be anything, so it needs the label or
|
|
48
|
+
* link. Each candidate is read once, so the text is read in one pass.
|
|
49
|
+
*/
|
|
50
|
+
export declare function arxivInText(text: string): string | undefined;
|
|
51
|
+
//# sourceMappingURL=arxiv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arxiv.d.ts","sourceRoot":"","sources":["../../src/model/arxiv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAmFH;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAoBzD;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAExE;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAG5E;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAE5E;AAUD;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAQ5D"}
|