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.
- package/CHANGELOG.md +7 -0
- package/LICENSE +201 -0
- package/README.md +118 -0
- package/changelog/0.1.x/0.1.0.md +17 -0
- package/changelog/template.md +150 -0
- package/dist/detect.d.ts +11 -0
- package/dist/detect.d.ts.map +1 -0
- package/dist/detect.js +51 -0
- package/dist/detect.js.map +1 -0
- package/dist/formats/html/blocks.d.ts +29 -0
- package/dist/formats/html/blocks.d.ts.map +1 -0
- package/dist/formats/html/blocks.js +527 -0
- package/dist/formats/html/blocks.js.map +1 -0
- package/dist/formats/html/context.d.ts +19 -0
- package/dist/formats/html/context.d.ts.map +1 -0
- package/dist/formats/html/context.js +122 -0
- package/dist/formats/html/context.js.map +1 -0
- package/dist/formats/html/index.d.ts +7 -0
- package/dist/formats/html/index.d.ts.map +1 -0
- package/dist/formats/html/index.js +7 -0
- package/dist/formats/html/index.js.map +1 -0
- package/dist/formats/html/inline.d.ts +26 -0
- package/dist/formats/html/inline.d.ts.map +1 -0
- package/dist/formats/html/inline.js +253 -0
- package/dist/formats/html/inline.js.map +1 -0
- package/dist/formats/html/metadata.d.ts +30 -0
- package/dist/formats/html/metadata.d.ts.map +1 -0
- package/dist/formats/html/metadata.js +212 -0
- package/dist/formats/html/metadata.js.map +1 -0
- package/dist/formats/html/parse.d.ts +17 -0
- package/dist/formats/html/parse.d.ts.map +1 -0
- package/dist/formats/html/parse.js +405 -0
- package/dist/formats/html/parse.js.map +1 -0
- package/dist/formats/html/references.d.ts +12 -0
- package/dist/formats/html/references.d.ts.map +1 -0
- package/dist/formats/html/references.js +123 -0
- package/dist/formats/html/references.js.map +1 -0
- package/dist/formats/jats/blocks.d.ts +52 -0
- package/dist/formats/jats/blocks.d.ts.map +1 -0
- package/dist/formats/jats/blocks.js +614 -0
- package/dist/formats/jats/blocks.js.map +1 -0
- package/dist/formats/jats/context.d.ts +17 -0
- package/dist/formats/jats/context.d.ts.map +1 -0
- package/dist/formats/jats/context.js +2 -0
- package/dist/formats/jats/context.js.map +1 -0
- package/dist/formats/jats/fragment.d.ts +7 -0
- package/dist/formats/jats/fragment.d.ts.map +1 -0
- package/dist/formats/jats/fragment.js +42 -0
- package/dist/formats/jats/fragment.js.map +1 -0
- package/dist/formats/jats/front.d.ts +25 -0
- package/dist/formats/jats/front.d.ts.map +1 -0
- package/dist/formats/jats/front.js +380 -0
- package/dist/formats/jats/front.js.map +1 -0
- package/dist/formats/jats/index.d.ts +8 -0
- package/dist/formats/jats/index.d.ts.map +1 -0
- package/dist/formats/jats/index.js +8 -0
- package/dist/formats/jats/index.js.map +1 -0
- package/dist/formats/jats/inline.d.ts +24 -0
- package/dist/formats/jats/inline.d.ts.map +1 -0
- package/dist/formats/jats/inline.js +274 -0
- package/dist/formats/jats/inline.js.map +1 -0
- package/dist/formats/jats/parse.d.ts +9 -0
- package/dist/formats/jats/parse.d.ts.map +1 -0
- package/dist/formats/jats/parse.js +247 -0
- package/dist/formats/jats/parse.js.map +1 -0
- package/dist/formats/jats/references.d.ts +25 -0
- package/dist/formats/jats/references.d.ts.map +1 -0
- package/dist/formats/jats/references.js +406 -0
- package/dist/formats/jats/references.js.map +1 -0
- package/dist/formats/jats/tables.d.ts +18 -0
- package/dist/formats/jats/tables.d.ts.map +1 -0
- package/dist/formats/jats/tables.js +105 -0
- package/dist/formats/jats/tables.js.map +1 -0
- package/dist/formats/jats/text.d.ts +23 -0
- package/dist/formats/jats/text.d.ts.map +1 -0
- package/dist/formats/jats/text.js +114 -0
- package/dist/formats/jats/text.js.map +1 -0
- package/dist/formats/latexml/blocks.d.ts +13 -0
- package/dist/formats/latexml/blocks.d.ts.map +1 -0
- package/dist/formats/latexml/blocks.js +454 -0
- package/dist/formats/latexml/blocks.js.map +1 -0
- package/dist/formats/latexml/context.d.ts +19 -0
- package/dist/formats/latexml/context.d.ts.map +1 -0
- package/dist/formats/latexml/context.js +18 -0
- package/dist/formats/latexml/context.js.map +1 -0
- package/dist/formats/latexml/index.d.ts +7 -0
- package/dist/formats/latexml/index.d.ts.map +1 -0
- package/dist/formats/latexml/index.js +7 -0
- package/dist/formats/latexml/index.js.map +1 -0
- package/dist/formats/latexml/inline.d.ts +16 -0
- package/dist/formats/latexml/inline.d.ts.map +1 -0
- package/dist/formats/latexml/inline.js +113 -0
- package/dist/formats/latexml/inline.js.map +1 -0
- package/dist/formats/latexml/parse.d.ts +16 -0
- package/dist/formats/latexml/parse.d.ts.map +1 -0
- package/dist/formats/latexml/parse.js +405 -0
- package/dist/formats/latexml/parse.js.map +1 -0
- package/dist/formats/pdf/blocks.d.ts +14 -0
- package/dist/formats/pdf/blocks.d.ts.map +1 -0
- package/dist/formats/pdf/blocks.js +203 -0
- package/dist/formats/pdf/blocks.js.map +1 -0
- package/dist/formats/pdf/index.d.ts +7 -0
- package/dist/formats/pdf/index.d.ts.map +1 -0
- package/dist/formats/pdf/index.js +7 -0
- package/dist/formats/pdf/index.js.map +1 -0
- package/dist/formats/pdf/inline.d.ts +8 -0
- package/dist/formats/pdf/inline.d.ts.map +1 -0
- package/dist/formats/pdf/inline.js +91 -0
- package/dist/formats/pdf/inline.js.map +1 -0
- package/dist/formats/pdf/layout.d.ts +33 -0
- package/dist/formats/pdf/layout.d.ts.map +1 -0
- package/dist/formats/pdf/layout.js +358 -0
- package/dist/formats/pdf/layout.js.map +1 -0
- package/dist/formats/pdf/lines.d.ts +40 -0
- package/dist/formats/pdf/lines.d.ts.map +1 -0
- package/dist/formats/pdf/lines.js +104 -0
- package/dist/formats/pdf/lines.js.map +1 -0
- package/dist/formats/pdf/load.d.ts +43 -0
- package/dist/formats/pdf/load.d.ts.map +1 -0
- package/dist/formats/pdf/load.js +126 -0
- package/dist/formats/pdf/load.js.map +1 -0
- package/dist/formats/pdf/parse.d.ts +9 -0
- package/dist/formats/pdf/parse.d.ts.map +1 -0
- package/dist/formats/pdf/parse.js +126 -0
- package/dist/formats/pdf/parse.js.map +1 -0
- package/dist/formats/pdf/references.d.ts +14 -0
- package/dist/formats/pdf/references.d.ts.map +1 -0
- package/dist/formats/pdf/references.js +104 -0
- package/dist/formats/pdf/references.js.map +1 -0
- package/dist/formats/pdf/structure.d.ts +29 -0
- package/dist/formats/pdf/structure.d.ts.map +1 -0
- package/dist/formats/pdf/structure.js +533 -0
- package/dist/formats/pdf/structure.js.map +1 -0
- package/dist/formats/tei/index.d.ts +7 -0
- package/dist/formats/tei/index.d.ts.map +1 -0
- package/dist/formats/tei/index.js +7 -0
- package/dist/formats/tei/index.js.map +1 -0
- package/dist/formats/tei/inline.d.ts +24 -0
- package/dist/formats/tei/inline.d.ts.map +1 -0
- package/dist/formats/tei/inline.js +107 -0
- package/dist/formats/tei/inline.js.map +1 -0
- package/dist/formats/tei/parse.d.ts +4 -0
- package/dist/formats/tei/parse.d.ts.map +1 -0
- package/dist/formats/tei/parse.js +560 -0
- package/dist/formats/tei/parse.js.map +1 -0
- package/dist/html/dom.d.ts +35 -0
- package/dist/html/dom.d.ts.map +1 -0
- package/dist/html/dom.js +70 -0
- package/dist/html/dom.js.map +1 -0
- package/dist/html/interstitial.d.ts +14 -0
- package/dist/html/interstitial.d.ts.map +1 -0
- package/dist/html/interstitial.js +67 -0
- package/dist/html/interstitial.js.map +1 -0
- package/dist/html/tables.d.ts +12 -0
- package/dist/html/tables.d.ts.map +1 -0
- package/dist/html/tables.js +62 -0
- package/dist/html/tables.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/model/diagnostics.d.ts +15 -0
- package/dist/model/diagnostics.d.ts.map +1 -0
- package/dist/model/diagnostics.js +37 -0
- package/dist/model/diagnostics.js.map +1 -0
- package/dist/model/document.d.ts +289 -0
- package/dist/model/document.d.ts.map +1 -0
- package/dist/model/document.js +13 -0
- package/dist/model/document.js.map +1 -0
- package/dist/model/extremes.d.ts +11 -0
- package/dist/model/extremes.d.ts.map +1 -0
- package/dist/model/extremes.js +23 -0
- package/dist/model/extremes.js.map +1 -0
- package/dist/model/index.d.ts +8 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +2 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/input.d.ts +14 -0
- package/dist/model/input.d.ts.map +1 -0
- package/dist/model/input.js +47 -0
- package/dist/model/input.js.map +1 -0
- package/dist/model/result.d.ts +53 -0
- package/dist/model/result.d.ts.map +1 -0
- package/dist/model/result.js +40 -0
- package/dist/model/result.js.map +1 -0
- package/dist/model/section-ids.d.ts +8 -0
- package/dist/model/section-ids.d.ts.map +1 -0
- package/dist/model/section-ids.js +28 -0
- package/dist/model/section-ids.js.map +1 -0
- package/dist/model/section-kinds.d.ts +19 -0
- package/dist/model/section-kinds.d.ts.map +1 -0
- package/dist/model/section-kinds.js +42 -0
- package/dist/model/section-kinds.js.map +1 -0
- package/dist/model/table-grid.d.ts +40 -0
- package/dist/model/table-grid.d.ts.map +1 -0
- package/dist/model/table-grid.js +79 -0
- package/dist/model/table-grid.js.map +1 -0
- package/dist/parse.d.ts +18 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js +35 -0
- package/dist/parse.js.map +1 -0
- package/dist/render/escape.d.ts +53 -0
- package/dist/render/escape.d.ts.map +1 -0
- package/dist/render/escape.js +94 -0
- package/dist/render/escape.js.map +1 -0
- package/dist/render/index.d.ts +8 -0
- package/dist/render/index.d.ts.map +1 -0
- package/dist/render/index.js +8 -0
- package/dist/render/index.js.map +1 -0
- package/dist/render/inline.d.ts +39 -0
- package/dist/render/inline.d.ts.map +1 -0
- package/dist/render/inline.js +87 -0
- package/dist/render/inline.js.map +1 -0
- package/dist/render/markdown.d.ts +35 -0
- package/dist/render/markdown.d.ts.map +1 -0
- package/dist/render/markdown.js +279 -0
- package/dist/render/markdown.js.map +1 -0
- package/dist/render/sections.d.ts +25 -0
- package/dist/render/sections.d.ts.map +1 -0
- package/dist/render/sections.js +45 -0
- package/dist/render/sections.js.map +1 -0
- package/dist/render/text.d.ts +13 -0
- package/dist/render/text.d.ts.map +1 -0
- package/dist/render/text.js +66 -0
- package/dist/render/text.js.map +1 -0
- package/dist/xml/mathml.d.ts +24 -0
- package/dist/xml/mathml.d.ts.map +1 -0
- package/dist/xml/mathml.js +201 -0
- package/dist/xml/mathml.js.map +1 -0
- package/dist/xml/ordered.d.ts +49 -0
- package/dist/xml/ordered.d.ts.map +1 -0
- package/dist/xml/ordered.js +151 -0
- package/dist/xml/ordered.js.map +1 -0
- package/dist/xml/well-formed.d.ts +15 -0
- package/dist/xml/well-formed.d.ts.map +1 -0
- package/dist/xml/well-formed.js +120 -0
- package/dist/xml/well-formed.js.map +1 -0
- package/package.json +137 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escape.d.ts","sourceRoot":"","sources":["../../src/render/escape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CASjD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQrD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,sFAAsF;AACtF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,oFAAoF;AACpF,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,SAAI,GAAG,MAAM,CAG3D;AAED,6EAA6E;AAC7E,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI7C;AAKD,iEAAiE;AACjE,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE9C;AAKD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Escaping for text that came from a source document and is about to
|
|
3
|
+
* become inline Markdown. The goal is text that reads naturally and cannot turn into
|
|
4
|
+
* markup it never was: emphasis, links, math, strikethrough, or live HTML.
|
|
5
|
+
*
|
|
6
|
+
* Escaping is minimal on purpose. A backslash before every punctuation mark is valid
|
|
7
|
+
* Markdown but unreadable to a person or a model, so each rule escapes only where the
|
|
8
|
+
* character could start a construct.
|
|
9
|
+
* @module src/render/escape
|
|
10
|
+
*/
|
|
11
|
+
import { largest } from '../model/extremes.js';
|
|
12
|
+
/** ASCII punctuation CommonMark allows a backslash to escape. */
|
|
13
|
+
const ESCAPABLE_AFTER_BACKSLASH = /\\(?=[!-/:-@[-`{-~])/g;
|
|
14
|
+
/**
|
|
15
|
+
* Escape source text for use inside inline Markdown.
|
|
16
|
+
*
|
|
17
|
+
* - `\` before punctuation, `*`, `` ` ``, `$` (math delimiter), `~` (GFM strikethrough) — always.
|
|
18
|
+
* - `_` — only where it could delimit emphasis, so `snake_case` and `H_2` stay readable.
|
|
19
|
+
* - `](` — the sequence that would turn bracketed text into a link.
|
|
20
|
+
* - `<` — only before a letter, `/`, `!`, or `?`, where it could open an HTML tag.
|
|
21
|
+
* - `&` — only where it would read as an entity reference.
|
|
22
|
+
*
|
|
23
|
+
* Soft hyphens are dropped: they only mark where a word may break.
|
|
24
|
+
*/
|
|
25
|
+
export function escapeInline(text) {
|
|
26
|
+
return text
|
|
27
|
+
.replace(/\u00AD/g, '')
|
|
28
|
+
.replace(ESCAPABLE_AFTER_BACKSLASH, '\\\\')
|
|
29
|
+
.replace(/[*`$~]/g, '\\$&')
|
|
30
|
+
.replace(/(^|[^\p{L}\p{N}])_|_(?=$|[^\p{L}\p{N}])/gu, (match) => match.replace('_', '\\_'))
|
|
31
|
+
.replace(/\]\(/g, '\\](')
|
|
32
|
+
.replace(/<(?=[A-Za-z/!?])/g, '\\<')
|
|
33
|
+
.replace(/&(?=#?[A-Za-z0-9]+;)/g, '\\&');
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Escape a character sequence that would change meaning at the start of a block:
|
|
37
|
+
* an ATX heading, a quote, a list marker, a thematic break, a table row, or a link
|
|
38
|
+
* reference definition.
|
|
39
|
+
*/
|
|
40
|
+
export function escapeBlockStart(text) {
|
|
41
|
+
return text
|
|
42
|
+
.replace(/^(#{1,6})(?=\s|$)/, '\\$1')
|
|
43
|
+
.replace(/^([>|])/, '\\$1')
|
|
44
|
+
.replace(/^([-+])(?=\s)/, '\\$1')
|
|
45
|
+
.replace(/^(\d{1,9})([.)])(?=\s)/, '$1\\$2')
|
|
46
|
+
.replace(/^(=+|-{3,})\s*$/, '\\$1')
|
|
47
|
+
.replace(/^\[(?=[^\]]*\]:)/, '\\[');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Keep TeX from reading as markup where a Markdown renderer without math support treats
|
|
51
|
+
* `$…$` as ordinary text: a `<` that could open an HTML tag and a `](` that could open a
|
|
52
|
+
* link get a space between them, which math mode ignores.
|
|
53
|
+
*/
|
|
54
|
+
export function escapeTex(tex) {
|
|
55
|
+
return tex.replace(/<(?=[A-Za-z/!?])/g, '< ').replace(/\]\(/g, '] (');
|
|
56
|
+
}
|
|
57
|
+
/** Escape a value for a GFM table cell: pipes and line breaks would break the row. */
|
|
58
|
+
export function escapeTableCell(text) {
|
|
59
|
+
return foldLineBreaks(text.replace(/\|/g, '\\|'));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Each whitespace run holding a line break folded to one space, in one pass: `\s*\n\s*`
|
|
63
|
+
* rescans a long run of spaces from every position in it.
|
|
64
|
+
*/
|
|
65
|
+
export function foldLineBreaks(text) {
|
|
66
|
+
return text.replace(/\s+/g, (run) => (run.includes('\n') ? ' ' : run));
|
|
67
|
+
}
|
|
68
|
+
/** The shortest backtick fence that no run of backticks inside `text` can close. */
|
|
69
|
+
export function codeFence(text, minimum = 3) {
|
|
70
|
+
const longest = Math.max(0, largest([...text.matchAll(/`+/g)].map((m) => m[0].length)));
|
|
71
|
+
return '`'.repeat(Math.max(minimum, longest + 1));
|
|
72
|
+
}
|
|
73
|
+
/** Wrap text as an inline code span that no backtick inside it can close. */
|
|
74
|
+
export function codeSpan(text) {
|
|
75
|
+
const fence = codeFence(text, 1);
|
|
76
|
+
const pad = text.startsWith('`') || text.endsWith('`') ? ' ' : '';
|
|
77
|
+
return `${fence}${pad}${text}${pad}${fence}`;
|
|
78
|
+
}
|
|
79
|
+
/** URL schemes a rendered link may carry. Anything else stays plain text. */
|
|
80
|
+
const SAFE_URL = /^(?:https?|ftp|mailto):/i;
|
|
81
|
+
/** True when `url` is safe to emit as a Markdown link target. */
|
|
82
|
+
export function isSafeUrl(url) {
|
|
83
|
+
return SAFE_URL.test(url.trim());
|
|
84
|
+
}
|
|
85
|
+
/** Parentheses, which `encodeURIComponent` leaves as they are. */
|
|
86
|
+
const PARENTHESES = { '(': '%28', ')': '%29' };
|
|
87
|
+
/**
|
|
88
|
+
* Escape a URL for use as a Markdown link destination: whitespace, angle brackets, and
|
|
89
|
+
* parentheses (an unbalanced one ends the destination) are percent-encoded.
|
|
90
|
+
*/
|
|
91
|
+
export function escapeUrl(url) {
|
|
92
|
+
return url.trim().replace(/[\s()<>]/g, (c) => PARENTHESES[c] ?? encodeURIComponent(c));
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=escape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escape.js","sourceRoot":"","sources":["../../src/render/escape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,iEAAiE;AACjE,MAAM,yBAAyB,GAAG,uBAAuB,CAAC;AAE1D;;;;;;;;;;G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AAC;AAEjF;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;AACzF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Public surface of the renderers.
|
|
3
|
+
* @module src/render
|
|
4
|
+
*/
|
|
5
|
+
export { type MarkdownOptions, toMarkdown } from './markdown.js';
|
|
6
|
+
export { type FlatSection, toSections } from './sections.js';
|
|
7
|
+
export { toText } from './text.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/render/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,KAAK,eAAe,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,KAAK,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/render/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAwB,UAAU,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAoB,UAAU,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wrap already-rendered Markdown in an emphasis marker (`*`, `**`, `~~`). Whitespace at
|
|
3
|
+
* the edges moves outside the markers, where CommonMark requires it, and empty content
|
|
4
|
+
* renders as itself.
|
|
5
|
+
*/
|
|
6
|
+
export declare function emphasis(markdown: string, marker: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* A superscript. Citation numbers become a bracketed marker (`[12,13]`), so they do not
|
|
9
|
+
* fuse with the word before them; anything else uses TeX-style notation (`10^{-5}`,
|
|
10
|
+
* `x^2`) that stays readable as plain text.
|
|
11
|
+
*
|
|
12
|
+
* `isCitation` is the parser's judgment that the superscript holds only citation links;
|
|
13
|
+
* an unlinked run of several citation numbers is recognized from its text.
|
|
14
|
+
*/
|
|
15
|
+
export declare function superscript(markdown: string, plain: string, isCitation: boolean): string;
|
|
16
|
+
/** A subscript in TeX-style notation: `CO_2`, `IC_{50}`. */
|
|
17
|
+
export declare function subscript(markdown: string, plain: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* A link. An unsafe scheme (`javascript:`, `data:`) renders as its text only, or as the
|
|
20
|
+
* target as escaped text when there is none; a link whose text is its own URL renders as
|
|
21
|
+
* an autolink.
|
|
22
|
+
*/
|
|
23
|
+
export declare function link(markdown: string, url: string | undefined): string;
|
|
24
|
+
/**
|
|
25
|
+
* Where a formula stands that the source publishes only as an image: its content is not
|
|
26
|
+
* in the text, and the marker keeps the sentence around it from reading as complete.
|
|
27
|
+
*/
|
|
28
|
+
export declare const FORMULA_IMAGE = "[formula]";
|
|
29
|
+
/** Inline math: `$tex$`. Empty TeX renders nothing. */
|
|
30
|
+
export declare function inlineMath(tex: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Inline Markdown with each pair of touching inline formulas joined into one: `$a$$b$`
|
|
33
|
+
* would read as a display-math delimiter. Source text never yields `$$` (its dollar
|
|
34
|
+
* signs are escaped), so every `$$` in inline Markdown is such a seam.
|
|
35
|
+
*/
|
|
36
|
+
export declare function joinAdjacentMath(markdown: string): string;
|
|
37
|
+
/** Inline code. */
|
|
38
|
+
export declare function inlineCode(text: string): string;
|
|
39
|
+
//# sourceMappingURL=inline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline.d.ts","sourceRoot":"","sources":["../../src/render/inline.ts"],"names":[],"mappings":"AAQA;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAIjE;AAQD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAG,MAAM,CAOxF;AAED,4DAA4D;AAC5D,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAIjE;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAMtE;AAOD;;;GAGG;AACH,eAAO,MAAM,aAAa,cAAc,CAAC;AAEzC,uDAAuD;AACvD,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG9C;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,mBAAmB;AACnB,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/C"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Builders for inline Markdown that every format parser shares, so a
|
|
3
|
+
* superscript, a link, or an inline formula reads the same whether it came from JATS,
|
|
4
|
+
* TEI, or HTML.
|
|
5
|
+
* @module src/render/inline
|
|
6
|
+
*/
|
|
7
|
+
import { codeSpan, escapeInline, escapeTex, escapeUrl, isSafeUrl } from './escape.js';
|
|
8
|
+
/**
|
|
9
|
+
* Wrap already-rendered Markdown in an emphasis marker (`*`, `**`, `~~`). Whitespace at
|
|
10
|
+
* the edges moves outside the markers, where CommonMark requires it, and empty content
|
|
11
|
+
* renders as itself.
|
|
12
|
+
*/
|
|
13
|
+
export function emphasis(markdown, marker) {
|
|
14
|
+
const match = /^(\s*)([\s\S]*?)(\s*)$/.exec(markdown);
|
|
15
|
+
const [, lead = '', core = '', trail = ''] = match ?? [];
|
|
16
|
+
return core ? `${lead}${marker}${core}${marker}${trail}` : markdown;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Two or more citation numbers joined by commas or dashes (`12,13`, `4–7`). A single
|
|
20
|
+
* number is left alone: `10<sup>5</sup>` is an exponent, not a citation.
|
|
21
|
+
*/
|
|
22
|
+
const CITATION_RUN = /^\d+(?:\s*[,\u2012\u2013\u2014-]\s*\d+)+$/;
|
|
23
|
+
/**
|
|
24
|
+
* A superscript. Citation numbers become a bracketed marker (`[12,13]`), so they do not
|
|
25
|
+
* fuse with the word before them; anything else uses TeX-style notation (`10^{-5}`,
|
|
26
|
+
* `x^2`) that stays readable as plain text.
|
|
27
|
+
*
|
|
28
|
+
* `isCitation` is the parser's judgment that the superscript holds only citation links;
|
|
29
|
+
* an unlinked run of several citation numbers is recognized from its text.
|
|
30
|
+
*/
|
|
31
|
+
export function superscript(markdown, plain, isCitation) {
|
|
32
|
+
const text = plain.trim();
|
|
33
|
+
if (!text)
|
|
34
|
+
return '';
|
|
35
|
+
if (isCitation || CITATION_RUN.test(text)) {
|
|
36
|
+
return `[${text.replace(/^\[|\]$/g, '').replace(/\s+/g, '')}]`;
|
|
37
|
+
}
|
|
38
|
+
return [...text].length === 1 ? `^${markdown.trim()}` : `^{${markdown.trim()}}`;
|
|
39
|
+
}
|
|
40
|
+
/** A subscript in TeX-style notation: `CO_2`, `IC_{50}`. */
|
|
41
|
+
export function subscript(markdown, plain) {
|
|
42
|
+
const text = plain.trim();
|
|
43
|
+
if (!text)
|
|
44
|
+
return '';
|
|
45
|
+
return [...text].length === 1 ? `_${markdown.trim()}` : `_{${markdown.trim()}}`;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A link. An unsafe scheme (`javascript:`, `data:`) renders as its text only, or as the
|
|
49
|
+
* target as escaped text when there is none; a link whose text is its own URL renders as
|
|
50
|
+
* an autolink.
|
|
51
|
+
*/
|
|
52
|
+
export function link(markdown, url) {
|
|
53
|
+
const target = url?.trim();
|
|
54
|
+
if (!target || !isSafeUrl(target))
|
|
55
|
+
return markdown || escapeInline(target ?? '');
|
|
56
|
+
const text = markdown.trim();
|
|
57
|
+
if (!text || text === target || text === escapeUrlText(target))
|
|
58
|
+
return `<${escapeUrl(target)}>`;
|
|
59
|
+
return `[${text}](${escapeUrl(target)})`;
|
|
60
|
+
}
|
|
61
|
+
/** How `escapeInline` would have rendered a bare URL, to recognize link text equal to it. */
|
|
62
|
+
function escapeUrlText(url) {
|
|
63
|
+
return url.replace(/[*`$~]/g, '\\$&').replace(/_/g, '\\_');
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Where a formula stands that the source publishes only as an image: its content is not
|
|
67
|
+
* in the text, and the marker keeps the sentence around it from reading as complete.
|
|
68
|
+
*/
|
|
69
|
+
export const FORMULA_IMAGE = '[formula]';
|
|
70
|
+
/** Inline math: `$tex$`. Empty TeX renders nothing. */
|
|
71
|
+
export function inlineMath(tex) {
|
|
72
|
+
const expression = tex.replace(/\s+/g, ' ').trim();
|
|
73
|
+
return expression ? `$${escapeTex(expression)}$` : '';
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Inline Markdown with each pair of touching inline formulas joined into one: `$a$$b$`
|
|
77
|
+
* would read as a display-math delimiter. Source text never yields `$$` (its dollar
|
|
78
|
+
* signs are escaped), so every `$$` in inline Markdown is such a seam.
|
|
79
|
+
*/
|
|
80
|
+
export function joinAdjacentMath(markdown) {
|
|
81
|
+
return markdown.replace(/(?<!\\)\$\$/g, '');
|
|
82
|
+
}
|
|
83
|
+
/** Inline code. */
|
|
84
|
+
export function inlineCode(text) {
|
|
85
|
+
return text ? codeSpan(text) : '';
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=inline.js.map
|
|
@@ -0,0 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CAAC,CAAC,IAAI,EAAE,CAAC;IACnD,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AACxD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,OAAO,QAAQ,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED,mBAAmB;AACnB,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview `ScholarlyDocument` → Markdown (CommonMark + GFM tables).
|
|
3
|
+
* @module src/render/markdown
|
|
4
|
+
*/
|
|
5
|
+
import type { Abstract, Block, ScholarlyDocument, Section, SectionKind } from '../model/document.js';
|
|
6
|
+
/** What to include when rendering. Everything is included by default. */
|
|
7
|
+
export interface MarkdownOptions {
|
|
8
|
+
/** `main` renders only the main abstract, or the first non-graphical one when none is marked main. */
|
|
9
|
+
abstracts?: 'all' | 'main' | 'none';
|
|
10
|
+
/** Back matter: appendices, acknowledgments, declarations, sub-articles. */
|
|
11
|
+
back?: boolean;
|
|
12
|
+
footnotes?: boolean;
|
|
13
|
+
/** Title, authors, venue, identifiers, and license. */
|
|
14
|
+
metadata?: boolean;
|
|
15
|
+
references?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Render only these sections (by ID, from `toSections` or the model), each with its
|
|
18
|
+
* subsections. Abstracts, metadata, footnotes, and references are left out.
|
|
19
|
+
*/
|
|
20
|
+
sections?: string[];
|
|
21
|
+
}
|
|
22
|
+
/** Render a document as Markdown. */
|
|
23
|
+
export declare function toMarkdown(document: ScholarlyDocument, options?: MarkdownOptions): string;
|
|
24
|
+
/** An abstract's heading: its own title, else its kind's. */
|
|
25
|
+
export declare function abstractHeading(abstract: Abstract): string;
|
|
26
|
+
/**
|
|
27
|
+
* A section heading's text: label, then title, else the kind's default where the
|
|
28
|
+
* section opens that kind (an untitled part of a titled appendix is not a new one).
|
|
29
|
+
*/
|
|
30
|
+
export declare function headingText(section: Section, parentKind: SectionKind | undefined): string | undefined;
|
|
31
|
+
/** Render a section and its subsections, its heading at `level` (capped at 6). */
|
|
32
|
+
export declare function renderSection(section: Section, level: number, parentKind?: SectionKind): string;
|
|
33
|
+
/** Render blocks separated by blank lines. */
|
|
34
|
+
export declare function renderBlocks(blocks: Block[]): string;
|
|
35
|
+
//# sourceMappingURL=markdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/render/markdown.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EACV,QAAQ,EAER,KAAK,EAEL,iBAAiB,EACjB,OAAO,EACP,WAAW,EAEZ,MAAM,sBAAsB,CAAC;AAY9B,yEAAyE;AACzE,MAAM,WAAW,eAAe;IAC9B,sGAAsG;IACtG,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;IACpC,4EAA4E;IAC5E,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,uDAAuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAsBD,qCAAqC;AACrC,wBAAgB,UAAU,CAAC,QAAQ,EAAE,iBAAiB,EAAE,OAAO,GAAE,eAAoB,GAAG,MAAM,CA6B7F;AAyED,6DAA6D;AAC7D,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAE1D;AAQD;;;GAGG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,WAAW,GAAG,SAAS,GAClC,MAAM,GAAG,SAAS,CAOpB;AAED,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,WAAW,GAAG,MAAM,CAW/F;AAED,8CAA8C;AAC9C,wBAAgB,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAEpD"}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { largest } from '../model/extremes.js';
|
|
2
|
+
import { codeFence, escapeBlockStart, escapeInline, escapeTableCell, escapeTex, foldLineBreaks, } from './escape.js';
|
|
3
|
+
import { FORMULA_IMAGE, link } from './inline.js';
|
|
4
|
+
/** Headings for sections the source leaves untitled, by kind. */
|
|
5
|
+
const KIND_HEADINGS = {
|
|
6
|
+
acknowledgments: 'Acknowledgments',
|
|
7
|
+
appendix: 'Appendix',
|
|
8
|
+
body: undefined,
|
|
9
|
+
'data-availability': 'Data availability',
|
|
10
|
+
declarations: 'Declarations',
|
|
11
|
+
notes: 'Notes',
|
|
12
|
+
'sub-article': 'Sub-article',
|
|
13
|
+
};
|
|
14
|
+
const ABSTRACT_HEADINGS = {
|
|
15
|
+
graphical: 'Graphical abstract',
|
|
16
|
+
main: 'Abstract',
|
|
17
|
+
other: 'Summary',
|
|
18
|
+
'plain-language': 'Plain-language summary',
|
|
19
|
+
teaser: 'Summary',
|
|
20
|
+
translated: 'Abstract (translated)',
|
|
21
|
+
};
|
|
22
|
+
/** Render a document as Markdown. */
|
|
23
|
+
export function toMarkdown(document, options = {}) {
|
|
24
|
+
if (options.sections)
|
|
25
|
+
return renderSelected(document, options.sections);
|
|
26
|
+
const parts = [];
|
|
27
|
+
if (options.metadata !== false)
|
|
28
|
+
parts.push(...renderMetadata(document));
|
|
29
|
+
const abstracts = selectAbstracts(document.abstracts, options.abstracts ?? 'all');
|
|
30
|
+
for (const abstract of abstracts)
|
|
31
|
+
parts.push(renderAbstract(abstract));
|
|
32
|
+
for (const section of document.body)
|
|
33
|
+
parts.push(renderSection(section, 2));
|
|
34
|
+
if (options.back !== false) {
|
|
35
|
+
for (const section of document.back)
|
|
36
|
+
parts.push(renderSection(section, 2));
|
|
37
|
+
}
|
|
38
|
+
if (document.floats.length > 0)
|
|
39
|
+
parts.push(`## Figures and tables\n\n${renderBlocks(document.floats)}`);
|
|
40
|
+
if (options.footnotes !== false && document.footnotes.length > 0) {
|
|
41
|
+
const lines = document.footnotes.map((fn) => `- ${fn.label ? `**${escapeInline(fn.label)}** ${fn.text}` : escapeBlockStart(fn.text)}`);
|
|
42
|
+
parts.push(`## Footnotes\n\n${lines.join('\n')}`);
|
|
43
|
+
}
|
|
44
|
+
if (options.references !== false && document.references.length > 0) {
|
|
45
|
+
const lines = document.references.map((ref) => `- ${ref.label ? `[${escapeInline(ref.label)}] ${ref.text}` : escapeBlockStart(ref.text)}`);
|
|
46
|
+
parts.push(`## References\n\n${lines.join('\n')}`);
|
|
47
|
+
}
|
|
48
|
+
return `${parts.filter(Boolean).join('\n\n')}\n`;
|
|
49
|
+
}
|
|
50
|
+
function selectAbstracts(abstracts, mode) {
|
|
51
|
+
if (mode === 'none')
|
|
52
|
+
return [];
|
|
53
|
+
if (mode === 'all')
|
|
54
|
+
return abstracts;
|
|
55
|
+
const main = abstracts.find((a) => a.kind === 'main') ?? abstracts.find((a) => a.kind !== 'graphical');
|
|
56
|
+
return main ? [main] : [];
|
|
57
|
+
}
|
|
58
|
+
function renderSelected(document, ids) {
|
|
59
|
+
const wanted = new Set(ids);
|
|
60
|
+
const found = [];
|
|
61
|
+
const visit = (sections, level) => {
|
|
62
|
+
for (const section of sections) {
|
|
63
|
+
if (wanted.has(section.id))
|
|
64
|
+
found.push(renderSection(section, level));
|
|
65
|
+
else
|
|
66
|
+
visit(section.sections, level + 1);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
visit(document.body, 2);
|
|
70
|
+
visit(document.back, 2);
|
|
71
|
+
for (const abstract of document.abstracts)
|
|
72
|
+
visit(abstract.sections, 3);
|
|
73
|
+
return found.length > 0 ? `${found.join('\n\n')}\n` : '';
|
|
74
|
+
}
|
|
75
|
+
function renderMetadata(document) {
|
|
76
|
+
const { metadata } = document;
|
|
77
|
+
const lines = [];
|
|
78
|
+
if (metadata.title) {
|
|
79
|
+
lines.push(`# ${metadata.title}${metadata.subtitle ? `: ${metadata.subtitle}` : ''}`);
|
|
80
|
+
}
|
|
81
|
+
const details = [];
|
|
82
|
+
if (metadata.authors?.length)
|
|
83
|
+
details.push(metadata.authors.map((a) => escapeInline(a.name)).join(', '));
|
|
84
|
+
const pages = metadata.venue?.pages ?? metadata.venue?.elocationId;
|
|
85
|
+
const venue = [
|
|
86
|
+
metadata.venue?.title && `*${escapeInline(metadata.venue.title)}*`,
|
|
87
|
+
metadata.published?.year,
|
|
88
|
+
metadata.venue?.volume &&
|
|
89
|
+
`${escapeInline(metadata.venue.volume)}${metadata.venue.issue ? `(${escapeInline(metadata.venue.issue)})` : ''}`,
|
|
90
|
+
pages && escapeInline(pages),
|
|
91
|
+
].filter(Boolean);
|
|
92
|
+
if (venue.length > 0)
|
|
93
|
+
details.push(venue.join(', '));
|
|
94
|
+
const idParts = identifierParts(metadata.identifiers ?? {});
|
|
95
|
+
if (idParts.length > 0)
|
|
96
|
+
details.push(idParts.join(' · '));
|
|
97
|
+
if (metadata.license?.url)
|
|
98
|
+
details.push(`License: ${link('', metadata.license.url)}`);
|
|
99
|
+
else if (metadata.license?.text)
|
|
100
|
+
details.push(`License: ${escapeInline(truncate(metadata.license.text, 240))}`);
|
|
101
|
+
for (const work of metadata.related ?? []) {
|
|
102
|
+
const parts = [work.text, ...identifierParts(work), work.url && link('', work.url)];
|
|
103
|
+
details.push(`Related (${escapeInline(work.relation)}): ${parts.filter(Boolean).join(' · ')}`);
|
|
104
|
+
}
|
|
105
|
+
if (details.length > 0)
|
|
106
|
+
lines.push(details.join(' \n'));
|
|
107
|
+
return lines;
|
|
108
|
+
}
|
|
109
|
+
/** A work's identifiers as `DOI: …`, `PMID: …`, `PMCID: …`, `arXiv: …`. */
|
|
110
|
+
function identifierParts(ids) {
|
|
111
|
+
return [
|
|
112
|
+
ids.doi && `DOI: ${escapeInline(ids.doi)}`,
|
|
113
|
+
ids.pmid && `PMID: ${escapeInline(ids.pmid)}`,
|
|
114
|
+
ids.pmcid && `PMCID: ${escapeInline(ids.pmcid)}`,
|
|
115
|
+
ids.arxiv && `arXiv: ${escapeInline(ids.arxiv)}`,
|
|
116
|
+
].filter((part) => Boolean(part));
|
|
117
|
+
}
|
|
118
|
+
/** Text cut at a word boundary to at most `max` characters, with an ellipsis when cut. */
|
|
119
|
+
function truncate(text, max) {
|
|
120
|
+
if (text.length <= max)
|
|
121
|
+
return text;
|
|
122
|
+
const cut = text.slice(0, max);
|
|
123
|
+
return `${cut.slice(0, Math.max(cut.lastIndexOf(' '), max / 2))}…`;
|
|
124
|
+
}
|
|
125
|
+
/** An abstract's heading: its own title, else its kind's. */
|
|
126
|
+
export function abstractHeading(abstract) {
|
|
127
|
+
return abstract.title ?? ABSTRACT_HEADINGS[abstract.kind];
|
|
128
|
+
}
|
|
129
|
+
function renderAbstract(abstract) {
|
|
130
|
+
const body = abstract.sections.map((section) => renderSection(section, 3)).filter(Boolean);
|
|
131
|
+
if (body.length === 0)
|
|
132
|
+
return '';
|
|
133
|
+
return [`## ${abstractHeading(abstract)}`, ...body].join('\n\n');
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* A section heading's text: label, then title, else the kind's default where the
|
|
137
|
+
* section opens that kind (an untitled part of a titled appendix is not a new one).
|
|
138
|
+
*/
|
|
139
|
+
export function headingText(section, parentKind) {
|
|
140
|
+
const title = section.title ?? (section.kind === parentKind ? undefined : KIND_HEADINGS[section.kind]);
|
|
141
|
+
if (!title)
|
|
142
|
+
return section.label ? escapeInline(section.label) : undefined;
|
|
143
|
+
return section.label && !title.startsWith(section.label)
|
|
144
|
+
? `${escapeInline(section.label)} ${title}`
|
|
145
|
+
: title;
|
|
146
|
+
}
|
|
147
|
+
/** Render a section and its subsections, its heading at `level` (capped at 6). */
|
|
148
|
+
export function renderSection(section, level, parentKind) {
|
|
149
|
+
const parts = [];
|
|
150
|
+
const heading = headingText(section, parentKind);
|
|
151
|
+
if (heading)
|
|
152
|
+
parts.push(`${'#'.repeat(Math.min(level, 6))} ${heading}`);
|
|
153
|
+
const blocks = renderBlocks(section.blocks);
|
|
154
|
+
if (blocks)
|
|
155
|
+
parts.push(blocks);
|
|
156
|
+
for (const sub of section.sections) {
|
|
157
|
+
const rendered = renderSection(sub, level + 1, section.kind);
|
|
158
|
+
if (rendered)
|
|
159
|
+
parts.push(rendered);
|
|
160
|
+
}
|
|
161
|
+
return parts.join('\n\n');
|
|
162
|
+
}
|
|
163
|
+
/** Render blocks separated by blank lines. */
|
|
164
|
+
export function renderBlocks(blocks) {
|
|
165
|
+
return blocks.map(renderBlock).filter(Boolean).join('\n\n');
|
|
166
|
+
}
|
|
167
|
+
function labeled(label, caption) {
|
|
168
|
+
const head = label ? `**${escapeInline(label.replace(/[.:]\s*$/, ''))}.**` : '';
|
|
169
|
+
return [head, caption].filter(Boolean).join(' ');
|
|
170
|
+
}
|
|
171
|
+
function renderBlock(block) {
|
|
172
|
+
switch (block.type) {
|
|
173
|
+
case 'paragraph':
|
|
174
|
+
return escapeBlockStart(block.text);
|
|
175
|
+
case 'list':
|
|
176
|
+
return renderList(block.items, block.ordered, block.title);
|
|
177
|
+
case 'table':
|
|
178
|
+
return renderTable(block);
|
|
179
|
+
case 'figure':
|
|
180
|
+
return block.label || block.caption || block.alt
|
|
181
|
+
? labeled(block.label ?? 'Figure', block.caption ?? escapeInline(block.alt ?? ''))
|
|
182
|
+
: '';
|
|
183
|
+
case 'supplement': {
|
|
184
|
+
const text = labeled(block.label ?? 'Supplementary material', block.caption);
|
|
185
|
+
return block.href ? `${text} (file: ${escapeInline(block.href)})` : text;
|
|
186
|
+
}
|
|
187
|
+
case 'formula': {
|
|
188
|
+
const label = block.label?.replace(/^\((.*)\)$/, '$1').trim();
|
|
189
|
+
if (block.tex)
|
|
190
|
+
return displayMath(block.tex, label);
|
|
191
|
+
const body = block.text === undefined ? FORMULA_IMAGE : escapeInline(block.text);
|
|
192
|
+
return `${escapeBlockStart(body)}${label ? ` (${escapeInline(label)})` : ''}`;
|
|
193
|
+
}
|
|
194
|
+
case 'code': {
|
|
195
|
+
const fence = codeFence(block.text);
|
|
196
|
+
const language = block.language && CODE_LANGUAGE.test(block.language) ? block.language : '';
|
|
197
|
+
return `${fence}${language}\n${block.text}\n${fence}`;
|
|
198
|
+
}
|
|
199
|
+
case 'quote':
|
|
200
|
+
return quoteLines(renderBlocks(block.blocks));
|
|
201
|
+
case 'box': {
|
|
202
|
+
const title = [block.label && escapeInline(block.label), block.title]
|
|
203
|
+
.filter(Boolean)
|
|
204
|
+
.join(' ');
|
|
205
|
+
const inner = [
|
|
206
|
+
title ? `**${title}**` : '',
|
|
207
|
+
renderBlocks(block.blocks),
|
|
208
|
+
...block.sections.map((s) => renderSection(s, 4)),
|
|
209
|
+
].filter(Boolean);
|
|
210
|
+
return inner.length > 0 ? quoteLines(inner.join('\n\n')) : '';
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/** A code block's language as a fence info string: a name, nothing that could end the line. */
|
|
215
|
+
const CODE_LANGUAGE = /^[\w+#.-]{1,32}$/;
|
|
216
|
+
/** What a `\tag{}` label keeps: text that can neither end the group nor start TeX markup. */
|
|
217
|
+
const TAG_UNSAFE = /[^\p{L}\p{N}\s.,:;'’′*+\-–—()[\]]/gu;
|
|
218
|
+
/**
|
|
219
|
+
* A display formula on one line between `$$` fences, so no line of the source TeX can
|
|
220
|
+
* close the block early. TeX reads a line break as a space, so the formula is unchanged.
|
|
221
|
+
*/
|
|
222
|
+
function displayMath(tex, label) {
|
|
223
|
+
const tag = label?.replace(TAG_UNSAFE, '').replace(/\s+/g, ' ').trim();
|
|
224
|
+
const line = `${foldLineBreaks(tex).trim()}${tag ? ` \\tag{${tag}}` : ''}`;
|
|
225
|
+
return `$$\n${escapeTex(line)}\n$$`;
|
|
226
|
+
}
|
|
227
|
+
function quoteLines(markdown) {
|
|
228
|
+
return markdown
|
|
229
|
+
.split('\n')
|
|
230
|
+
.map((line) => (line ? `> ${line}` : '>'))
|
|
231
|
+
.join('\n');
|
|
232
|
+
}
|
|
233
|
+
function renderList(items, ordered, title) {
|
|
234
|
+
const lines = [];
|
|
235
|
+
if (title)
|
|
236
|
+
lines.push(`**${title}**`, '');
|
|
237
|
+
items.forEach((item, index) => {
|
|
238
|
+
const marker = ordered ? `${index + 1}. ` : '- ';
|
|
239
|
+
const indent = ' '.repeat(marker.length);
|
|
240
|
+
const body = renderBlocks(item)
|
|
241
|
+
.split('\n')
|
|
242
|
+
.map((line, i) => (i === 0 ? `${marker}${line}` : line ? `${indent}${line}` : ''))
|
|
243
|
+
.join('\n');
|
|
244
|
+
lines.push(body);
|
|
245
|
+
});
|
|
246
|
+
return lines.join('\n');
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* A GFM table. GFM allows one header row, so several source header rows are merged
|
|
250
|
+
* column by column; a table without header rows gets an empty header so no data row is
|
|
251
|
+
* mislabeled as one.
|
|
252
|
+
*/
|
|
253
|
+
function renderTable(table) {
|
|
254
|
+
const parts = [];
|
|
255
|
+
if (table.label || table.caption)
|
|
256
|
+
parts.push(labeled(table.label ?? 'Table', table.caption));
|
|
257
|
+
if (table.rows.length === 0) {
|
|
258
|
+
parts.push(`*Table content not available (${table.unextractable ?? 'no-rows'}).*`);
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
const width = largest(table.rows.map((row) => row.length));
|
|
262
|
+
const cell = (value) => escapeTableCell(value ?? '');
|
|
263
|
+
const headerRows = table.rows.slice(0, table.headerRows);
|
|
264
|
+
const header = Array.from({ length: width }, (_, col) => {
|
|
265
|
+
const values = headerRows.map((row) => row[col] ?? '').filter(Boolean);
|
|
266
|
+
return [...new Set(values)].join(' / ');
|
|
267
|
+
});
|
|
268
|
+
const line = (cells) => `| ${Array.from({ length: width }, (_, i) => cell(cells[i])).join(' | ')} |`;
|
|
269
|
+
parts.push([
|
|
270
|
+
line(header),
|
|
271
|
+
`|${' --- |'.repeat(width)}`,
|
|
272
|
+
...table.rows.slice(table.headerRows).map(line),
|
|
273
|
+
].join('\n'));
|
|
274
|
+
}
|
|
275
|
+
if (table.footnotes?.length)
|
|
276
|
+
parts.push(table.footnotes.map(escapeBlockStart).join(' \n'));
|
|
277
|
+
return parts.join('\n\n');
|
|
278
|
+
}
|
|
279
|
+
//# sourceMappingURL=markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../src/render/markdown.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,SAAS,EACT,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAmBlD,iEAAiE;AACjE,MAAM,aAAa,GAA4C;IAC7D,eAAe,EAAE,iBAAiB;IAClC,QAAQ,EAAE,UAAU;IACpB,IAAI,EAAE,SAAS;IACf,mBAAmB,EAAE,mBAAmB;IACxC,YAAY,EAAE,cAAc;IAC5B,KAAK,EAAE,OAAO;IACd,aAAa,EAAE,aAAa;CAC7B,CAAC;AAEF,MAAM,iBAAiB,GAAiC;IACtD,SAAS,EAAE,oBAAoB;IAC/B,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,SAAS;IAChB,gBAAgB,EAAE,wBAAwB;IAC1C,MAAM,EAAE,SAAS;IACjB,UAAU,EAAE,uBAAuB;CACpC,CAAC;AAEF,qCAAqC;AACrC,M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AK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;QAC/E,KAAK,CAAC,IAAI,CACR;YACE,IAAI,CAAC,MAAM,CAAC;YACZ,IAAI,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;YAC5B,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;SAChD,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;IACJ,CAAC;IACD,IAAI,KAAK,CAAC,SAAS,EAAE,MAAM;QAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5F,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview `ScholarlyDocument` → a flat list of sections in reading order, each
|
|
3
|
+
* rendered on its own with its size. This is what a pager needs to show an outline and
|
|
4
|
+
* serve one section, or one window of the document, at a time.
|
|
5
|
+
* @module src/render/sections
|
|
6
|
+
*/
|
|
7
|
+
import type { ScholarlyDocument, SectionKind } from '../model/document.js';
|
|
8
|
+
/** One section, flattened out of the tree. */
|
|
9
|
+
export interface FlatSection {
|
|
10
|
+
/** Characters in {@link markdown}. */
|
|
11
|
+
chars: number;
|
|
12
|
+
id: string;
|
|
13
|
+
kind: SectionKind | 'abstract';
|
|
14
|
+
/** Heading depth, 1 for a top-level section. */
|
|
15
|
+
level: number;
|
|
16
|
+
/** The section's own heading and blocks. Subsections are separate entries. */
|
|
17
|
+
markdown: string;
|
|
18
|
+
/** Titles from the top-level section down to this one. */
|
|
19
|
+
path: string[];
|
|
20
|
+
/** The heading `toMarkdown` gives the section: label and title, or its kind's name when untitled. */
|
|
21
|
+
title?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Every section, abstracts first, then body, then back matter. */
|
|
24
|
+
export declare function toSections(document: ScholarlyDocument): FlatSection[];
|
|
25
|
+
//# sourceMappingURL=sections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sections.d.ts","sourceRoot":"","sources":["../../src/render/sections.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAY,iBAAiB,EAAW,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAG9F,8CAA8C;AAC9C,MAAM,WAAW,WAAW;IAC1B,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC;IAC/B,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,8EAA8E;IAC9E,QAAQ,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,qGAAqG;IACrG,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,mEAAmE;AACnE,wBAAgB,UAAU,CAAC,QAAQ,EAAE,iBAAiB,GAAG,WAAW,EAAE,CAOrE"}
|