@behackl/citation-js-extras 0.2.1 → 0.4.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/README.md +79 -279
- package/dist/index.d.ts +92 -22
- package/dist/index.js +491 -222
- package/dist/math.d.ts +4 -0
- package/dist/math.js +17 -6
- package/dist/types.d.ts +143 -17
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -2,316 +2,116 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
Turn a BibTeX file into an HTML publication list with
|
|
6
|
+
[citation-js](https://citation.js.org/): any CSL style, titles linked to the
|
|
7
|
+
paper, badges for DOI, arXiv, MathSciNet and zbMATH, and mathematics in titles.
|
|
8
|
+
|
|
9
|
+
- **Every BibTeX field stays available.** citation-js drops fields it doesn't
|
|
10
|
+
know (`status`, `project`, `mrnumber`, …); here they stay on each entry, for
|
|
11
|
+
grouping, filtering and links.
|
|
12
|
+
- **Links, printed once.** The title links to the paper and identifiers become
|
|
13
|
+
badges. The style doesn't print a linked DOI or URL a second time as text.
|
|
14
|
+
- **Exports work as they are.** `doi:10…` and `https://doi.org/10…`, arXiv ids
|
|
15
|
+
in biblatex's `eprint` field, titles with quotes, `\emph` or `&`.
|
|
16
|
+
- **Mathematics.** `$…$` in titles survives the formatting and is typeset by
|
|
17
|
+
the renderer you pass in, such as KaTeX or MathJax.
|
|
18
|
+
- **Your layout.** The markup is configurable; links are available as data;
|
|
19
|
+
hooks reach into the formatted citation.
|
|
12
20
|
|
|
13
21
|
## Install
|
|
14
22
|
|
|
15
23
|
```bash
|
|
16
24
|
npm install @behackl/citation-js-extras citation-js
|
|
17
|
-
# or
|
|
18
|
-
pnpm add @behackl/citation-js-extras citation-js
|
|
19
25
|
```
|
|
20
26
|
|
|
21
|
-
`citation-js` is a
|
|
27
|
+
`citation-js` is a peer dependency.
|
|
22
28
|
|
|
23
29
|
## Quick start
|
|
24
30
|
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// Render HTML
|
|
39
|
-
const html = bib.formatHtml(sorted, {
|
|
40
|
-
titleLink: ["url", "doi", "arxiv"],
|
|
41
|
-
badges: [
|
|
42
|
-
{ field: "doi", label: "doi", url: "https://doi.org/$1", className: "badge-doi" },
|
|
43
|
-
{
|
|
44
|
-
field: "arxiv",
|
|
45
|
-
label: "arXiv",
|
|
46
|
-
url: "https://arxiv.org/abs/$1",
|
|
47
|
-
match: /^(.+?)(?:v\d+)?$/,
|
|
48
|
-
className: "badge-arxiv",
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
});
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## Preserving mathematics
|
|
55
|
-
|
|
56
|
-
Citation.js normally converts TeX math to text, losing delimiters and potentially
|
|
57
|
-
complex expressions. Enable preservation before parsing:
|
|
58
|
-
|
|
59
|
-
```ts
|
|
60
|
-
const bib = new Bibliography({
|
|
61
|
-
data: "./references.bib",
|
|
62
|
-
preserveMath: true,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// Restore HTML-escaped original TeX for client-side MathJax:
|
|
66
|
-
const html = bib.formatHtml(bib.entries);
|
|
67
|
-
|
|
68
|
-
// Or typeset at build time with your own synchronous renderer:
|
|
69
|
-
const rendered = bib.formatHtml(bib.entries, {
|
|
70
|
-
renderMath: (tex, { display }) => myMathRenderer(tex, display),
|
|
71
|
-
});
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
`myMathRenderer` is an application-supplied function returning **trusted HTML**
|
|
75
|
-
(e.g. MathJax SVG or KaTeX output). No math renderer is bundled. Configure it for
|
|
76
|
-
untrusted TeX as appropriate; the callback output is inserted verbatim, not
|
|
77
|
-
sanitized. Treat renderer output as untrusted HTML unless you control both the
|
|
78
|
-
renderer configuration and the TeX: substitute it only after the surrounding
|
|
79
|
-
HTML has been sanitized (see below). Exceptions propagate to the caller. `renderMath` also works with
|
|
80
|
-
`formatEntry`; it has no effect unless `preserveMath` was enabled.
|
|
81
|
-
|
|
82
|
-
Supported delimiters are `$…$`, `$$…$$`, `\(…\)`, and `\[…\]`.
|
|
83
|
-
Escape literal dollars as `\$`. Empty or unclosed expressions throw with the
|
|
84
|
-
citation key and field name. This is a delimiter scanner, not a TeX validator:
|
|
85
|
-
unsupported commands and mathematical validity are the renderer's responsibility.
|
|
86
|
-
|
|
87
|
-
Protection covers `title`, `subtitle`, `titleaddon`, `shorttitle`, `booktitle`,
|
|
88
|
-
`booksubtitle`, `booktitleaddon`, `maintitle`, `mainsubtitle`, `maintitleaddon`,
|
|
89
|
-
`journaltitle`, `journalsubtitle`, `journal`, `note`, `annote`, `abstract`, and
|
|
90
|
-
`howpublished`. Fields still need to be supported by Citation.js and the chosen
|
|
91
|
-
CSL style to appear in the output. Names, identifiers, URLs, and custom metadata
|
|
92
|
-
are not protected. BibTeX strings and concatenations are resolved before protection;
|
|
93
|
-
inherited cross-reference text is protected during conversion.
|
|
94
|
-
|
|
95
|
-
Original `.raw` and `.custom` values remain unchanged. With preservation enabled,
|
|
96
|
-
`.csl` contains internal placeholders: use the formatting methods for HTML and
|
|
97
|
-
raw fields for original source text, not `.csl` for plain-text exports. Placeholders
|
|
98
|
-
also mean CSL title-based sorting/disambiguation operates on protected text rather
|
|
99
|
-
than mathematical meaning. Existing caller-controlled ordering is retained.
|
|
100
|
-
|
|
101
|
-
Restoration runs after title linking, badges, and URL linkification. Neither
|
|
102
|
-
renderer output nor restored TeX is fed back through these HTML helpers. Disabling
|
|
103
|
-
preservation (the default) retains the previous behavior.
|
|
104
|
-
|
|
105
|
-
If `renderMath` throws, the error names the entry it came from
|
|
106
|
-
(`entry doe:2024: Undefined control sequence: \\kk`), so a broken formula can be
|
|
107
|
-
traced to a line in the `.bib` file.
|
|
108
|
-
|
|
109
|
-
### Sanitizing formatted output
|
|
110
|
-
|
|
111
|
-
Rendered mathematics does **not** survive an HTML sanitizer with default
|
|
112
|
-
settings: KaTeX and MathJax output relies on `class`, `style` and MathML
|
|
113
|
-
elements that `rehype-sanitize` strips, leaving empty boxes. Sanitize the
|
|
114
|
-
citation HTML *first*, then insert the trusted renderer output:
|
|
115
|
-
|
|
116
|
-
```js
|
|
117
|
-
const math = [];
|
|
118
|
-
const html = bib.formatHtml(entries, {
|
|
119
|
-
// Stand in for each formula while the HTML is sanitized ...
|
|
120
|
-
renderMath: (tex, { display }) => {
|
|
121
|
-
math.push(renderWithKatex(tex, display));
|
|
122
|
-
return `mathplaceholder${math.length - 1}end`;
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
const safe = sanitize(html);
|
|
126
|
-
// ... then substitute the rendered markup back in.
|
|
127
|
-
const final = safe.replace(/mathplaceholder(\d+)end/g, (_, i) => math[Number(i)]);
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
Two related gotchas when using `rehype-sanitize`:
|
|
131
|
-
|
|
132
|
-
- its `defaultSchema` allows `className` only with an explicit value list *per
|
|
133
|
-
tag*, and that per-tag rule overrides anything added under `'*'`; to keep
|
|
134
|
-
badge or list classes, merge your class names into the existing entry for
|
|
135
|
-
that tag
|
|
136
|
-
- pick a placeholder that cannot occur in your bibliography (append characters
|
|
137
|
-
until it is absent from the source)
|
|
138
|
-
|
|
139
|
-
This recipe deliberately reinserts renderer output *after* sanitizing, so it is
|
|
140
|
-
only as safe as the renderer: a renderer configured to emit arbitrary markup
|
|
141
|
-
(for instance KaTeX with `trust: true`) can reintroduce `<script>`. Restrict the
|
|
142
|
-
renderer configuration, or sanitize its output separately with a schema that
|
|
143
|
-
keeps the elements and attributes mathematics needs.
|
|
144
|
-
|
|
145
|
-
## Development checks
|
|
146
|
-
|
|
147
|
-
```sh
|
|
148
|
-
pnpm install --frozen-lockfile
|
|
149
|
-
pnpm test # Unit tests and actual MathJax SVG integration (base + AMS)
|
|
150
|
-
pnpm test:package # Build, pack, install into a temporary consumer, and test exports
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
The package check validates ESM imports, TypeScript declarations under both
|
|
154
|
-
NodeNext and Bundler resolution, and MathJax rendering through the installed
|
|
155
|
-
tarball. Its temporary consumer is removed afterwards. Installation prefers the
|
|
156
|
-
local cache but may need registry access on a fresh machine. CI runs both checks.
|
|
157
|
-
MathJax is a development-only dependency, not a runtime dependency for consumers.
|
|
158
|
-
Use Node 24 LTS for these development checks, matching CI and publishing.
|
|
159
|
-
|
|
160
|
-
## API
|
|
161
|
-
|
|
162
|
-
### `new Bibliography(options)`
|
|
163
|
-
|
|
164
|
-
| Option | Type | Description |
|
|
165
|
-
|---|---|---|
|
|
166
|
-
| `data` | `string` | BibTeX input — a raw string or a file path. |
|
|
167
|
-
| `cslStyle` | `string?` | CSL style — a registered template name, raw XML, or a file path. Defaults to `'apa'`. |
|
|
168
|
-
| `customFields` | `string[]?` | BibTeX field names to preserve. These appear on each entry under `.custom`. |
|
|
169
|
-
| `preserveMath` | `boolean?` | Preserve math in display-text fields through CSL formatting. Defaults to `false`. |
|
|
170
|
-
| `titleLink` | `string[]?` | Default fields used for the title link, checked in order. Defaults to `['url', 'doi', 'arxiv']`. |
|
|
171
|
-
| `badges` | `BadgeConfig[]?` | Default badge configuration, used by every `formatHtml`/`formatEntry` call. No badges are rendered unless set. |
|
|
172
|
-
| `linkifyUrls` | `boolean?` | Default for URL linkification. Defaults to `true`. |
|
|
173
|
-
|
|
174
|
-
`titleLink`, `badges` and `linkifyUrls` are usually the same for every call, so
|
|
175
|
-
they can be set once here; a value passed to `formatHtml`/`formatEntry` overrides
|
|
176
|
-
the default for that call.
|
|
177
|
-
|
|
178
|
-
### `bib.entries`
|
|
179
|
-
|
|
180
|
-
All parsed entries as `BibEntry[]`:
|
|
181
|
-
|
|
182
|
-
```ts
|
|
183
|
-
interface BibEntry {
|
|
184
|
-
csl: Record<string, any>; // CSL-JSON data (for citation-js)
|
|
185
|
-
key: string; // BibTeX citation key
|
|
186
|
-
year: number | null; // extracted from CSL `issued`
|
|
187
|
-
custom: Record<string, string>; // declared custom fields
|
|
188
|
-
raw: Record<string, any>; // all raw BibTeX properties
|
|
31
|
+
```bibtex
|
|
32
|
+
@article{lindqvist2025,
|
|
33
|
+
author = {Lindqvist, Maja and Sato, Ren},
|
|
34
|
+
title = {Sobolev estimates for $L^p$ averages},
|
|
35
|
+
journal = {Annals of Invented Analysis},
|
|
36
|
+
volume = {12},
|
|
37
|
+
pages = {1--44},
|
|
38
|
+
year = {2025},
|
|
39
|
+
doi = {10.5555/aia.2025.12},
|
|
40
|
+
eprint = {2501.01234},
|
|
41
|
+
eprinttype = {arxiv},
|
|
42
|
+
status = {published},
|
|
189
43
|
}
|
|
190
44
|
```
|
|
191
45
|
|
|
192
|
-
### `bib.filter(criteria)`
|
|
193
|
-
|
|
194
|
-
Filter entries by custom field values. All criteria must match (AND logic).
|
|
195
|
-
|
|
196
|
-
```ts
|
|
197
|
-
bib.filter({ "publication-status": "published" });
|
|
198
|
-
bib.filter({ "publication-status": "published", project: "ABC-123" });
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
### `bib.sort(entries, options?)`
|
|
202
|
-
|
|
203
|
-
Return a sorted **copy** of the entries (the input is not mutated).
|
|
204
|
-
|
|
205
46
|
```ts
|
|
206
|
-
|
|
207
|
-
bib.sort(entries, { by: "year", order: "asc" });
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
### `bib.formatHtml(entries, options?)`
|
|
47
|
+
import { Bibliography, badgePresets } from "@behackl/citation-js-extras";
|
|
211
48
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
badges: [ /* ... */ ],
|
|
218
|
-
list: "ol", // 'ol', 'ul', or 'div' (div uses <div class="csl-entry"> children)
|
|
219
|
-
listAttributes: { reversed: true },
|
|
220
|
-
linkifyUrls: true,
|
|
49
|
+
const bib = new Bibliography({
|
|
50
|
+
data: "./publications.bib", // a file path or BibTeX text
|
|
51
|
+
cslStyle: "apa", // a built-in style, a .csl file, or CSL XML
|
|
52
|
+
customFields: ["status"], // non-standard fields to keep on `entry.custom`
|
|
53
|
+
badges: [badgePresets.doi, badgePresets.arxiv],
|
|
221
54
|
});
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
Entries are formatted in one citeproc pass, so style-dependent state (for example numeric labels in Vancouver) remains correct.
|
|
225
|
-
|
|
226
|
-
An empty entry list returns an empty string, not an empty wrapper element.
|
|
227
|
-
|
|
228
|
-
### `bib.formatEntry(entry, options?)`
|
|
229
|
-
|
|
230
|
-
Render a single entry as an HTML string (no list wrapper). The title link targets the actual CSL title text, regardless of italics.
|
|
231
|
-
|
|
232
|
-
Accepts the same title linking, badge and `linkifyUrls` options as `formatHtml` and applies them identically (`list`/`listAttributes` are ignored — there is no wrapper). Bare URLs are linkified unless `linkifyUrls: false` is set, either per call or on the constructor.
|
|
233
|
-
|
|
234
|
-
For citation styles that depend on multi-entry context (numbered labels, ibid behavior, etc.), prefer `formatHtml(...)`.
|
|
235
|
-
|
|
236
|
-
Title links are only created for safe URL schemes (`http`, `https`, `mailto`) or normalized DOI/arXiv links.
|
|
237
55
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
Badges are small inline links appended to each entry. They are configured declaratively:
|
|
241
|
-
|
|
242
|
-
```ts
|
|
243
|
-
interface BadgeConfig {
|
|
244
|
-
field: string; // BibTeX field name to read
|
|
245
|
-
label: string; // display text (e.g. "doi", "arXiv")
|
|
246
|
-
url: string; // URL template — $1 is replaced by the field value
|
|
247
|
-
match?: RegExp; // optional: validate/transform the field value
|
|
248
|
-
className?: string; // CSS class(es) for the <a> element
|
|
249
|
-
}
|
|
56
|
+
const published = bib.sort(bib.filter({ status: "published" }), { by: "date" });
|
|
57
|
+
const html = bib.formatHtml(published);
|
|
250
58
|
```
|
|
251
59
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
When `match` is provided, the field value is tested against the regex. If it doesn't match, the badge is skipped. If it matches, `$1` in the URL is replaced by the **first capture group** (or the full match if there are no capture groups):
|
|
260
|
-
|
|
261
|
-
```ts
|
|
262
|
-
// Strip version suffix from arXiv IDs:
|
|
263
|
-
{ field: "arxiv", label: "arXiv",
|
|
264
|
-
url: "https://arxiv.org/abs/$1",
|
|
265
|
-
match: /^(.+?)(?:v\d+)?$/ }
|
|
266
|
-
// "2301.00001v3" → capture group "2301.00001" → href=".../2301.00001"
|
|
267
|
-
|
|
268
|
-
// Only link if the field looks like a valid identifier:
|
|
269
|
-
{ field: "zbl", label: "zbMATH",
|
|
270
|
-
url: "https://zbmath.org/?q=an:$1",
|
|
271
|
-
match: /^(\d+\.\d+)$/ }
|
|
272
|
-
// "7654.12345" → match → linked
|
|
273
|
-
// "not-a-number" → no match → badge skipped
|
|
60
|
+
```html
|
|
61
|
+
<ol reversed class="csl-bib-body">
|
|
62
|
+
<li data-csl-entry-id="lindqvist2025" class="csl-entry">Lindqvist, M., & Sato, R. (2025).
|
|
63
|
+
<a href="https://doi.org/10.5555/aia.2025.12">Sobolev estimates for $L^p$ averages</a>.
|
|
64
|
+
<i>Annals of Invented Analysis</i>, <i>12</i>, 1–44.
|
|
65
|
+
<span class="bib-links"><a href="https://doi.org/10.5555/aia.2025.12">DOI</a> <a href="https://arxiv.org/abs/2501.01234">arXiv</a></span></li>
|
|
66
|
+
</ol>
|
|
274
67
|
```
|
|
275
68
|
|
|
276
|
-
|
|
69
|
+
Line breaks added for readability. APA would normally print the DOI after the
|
|
70
|
+
journal; here it is linked as the title link and as a badge instead.
|
|
277
71
|
|
|
278
|
-
|
|
72
|
+
## Mathematics
|
|
279
73
|
|
|
280
|
-
|
|
74
|
+
With `preserveMath`, formulas in titles reach your renderer intact:
|
|
281
75
|
|
|
282
76
|
```ts
|
|
283
|
-
import
|
|
77
|
+
import katex from "katex";
|
|
284
78
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
## Custom CSL styles
|
|
290
|
-
|
|
291
|
-
Pass a file path or raw XML to `cslStyle`. You can also pass the name of any template already registered with citation-js:
|
|
292
|
-
|
|
293
|
-
```ts
|
|
294
|
-
const bib = new Bibliography({
|
|
295
|
-
data: bibtex,
|
|
296
|
-
cslStyle: "./styles/my-department.csl",
|
|
297
|
-
customFields: ["publication-status"],
|
|
79
|
+
const bib = new Bibliography({ data: "./publications.bib", preserveMath: true });
|
|
80
|
+
const html = bib.formatHtml(bib.entries, {
|
|
81
|
+
renderMath: (tex, { display }) => katex.renderToString(tex, { displayMode: display }),
|
|
82
|
+
sanitize: (html) => mySanitizer(html), // optional; runs before the math is inserted
|
|
298
83
|
});
|
|
299
84
|
```
|
|
300
85
|
|
|
301
|
-
|
|
86
|
+
See [Mathematics and sanitizing](docs/math.md).
|
|
302
87
|
|
|
303
|
-
|
|
88
|
+
## Customising
|
|
304
89
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
90
|
+
| To change | Use | Details |
|
|
91
|
+
|---|---|---|
|
|
92
|
+
| which fields you can read | `customFields`; `entry.raw` has every field | [API](docs/api.md#new-bibliographyoptions) |
|
|
93
|
+
| which links follow an entry | `badges`: presets, `$1` templates, or functions | [Links and badges](docs/links.md#badges) |
|
|
94
|
+
| where the title links to | `titleLink` | [Links and badges](docs/links.md#title-links) |
|
|
95
|
+
| attributes of the links (class, `target`, a base path) | `linkAttributes` | [Links and badges](docs/links.md#link-attributes) |
|
|
96
|
+
| how entries read | the CSL style (`cslStyle`) and locale (`lang`) | [Layout](docs/layout.md#styles-and-locales) |
|
|
97
|
+
| the markup around entries | `list`, `listAttributes`, `itemAttributes`, `badgeListClassName` | [Layout](docs/layout.md#markup) |
|
|
98
|
+
| a layout of your own | `links(entry)`, `appendBadges`, `wrapVariable` | [Layout](docs/layout.md#laying-out-entries-yourself) |
|
|
99
|
+
| a "Copy BibTeX" button | `bibtex(entry)` | [Layout](docs/layout.md#copying-an-entrys-bibtex) |
|
|
100
|
+
| what reaches the page | `sanitize`, `renderMath` | [Mathematics](docs/math.md) |
|
|
101
|
+
| order and selection | `sort`, `filter`, or array methods on `bib.entries` | [API](docs/api.md#bibsortentries-options) |
|
|
102
|
+
|
|
103
|
+
Formatting options can be given to the constructor as defaults, or to each
|
|
104
|
+
`formatHtml`/`formatEntry` call.
|
|
105
|
+
|
|
106
|
+
## Documentation
|
|
107
|
+
|
|
108
|
+
- [API reference](docs/api.md)
|
|
109
|
+
- [Links and badges](docs/links.md)
|
|
110
|
+
- [Mathematics and sanitizing](docs/math.md)
|
|
111
|
+
- [Layout: markup, styles, custom layouts](docs/layout.md)
|
|
112
|
+
- [How it works](docs/how-it-works.md)
|
|
113
|
+
|
|
114
|
+
[Changelog](CHANGELOG.md) · [Contributing](CONTRIBUTING.md)
|
|
315
115
|
|
|
316
116
|
## License
|
|
317
117
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,54 @@
|
|
|
1
|
-
import type { BibEntry, BibliographyOptions, FormatOptions } from "./types.js";
|
|
2
|
-
export type { BadgeConfig, BibEntry, BibliographyOptions, FormatDefaults, FormatOptions, MathRenderer, } from "./types.js";
|
|
1
|
+
import type { BibEntry, BibliographyOptions, BibtexOptions, EntryLinks, FormatOptions } from "./types.js";
|
|
2
|
+
export type { BadgeConfig, BadgeFunction, BadgeLink, BibEntry, BibliographyOptions, BibtexOptions, EntryLinks, FormatDefaults, FormatOptions, HtmlAttributes, Link, MathRenderer, TitleLink, } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Ready-made badges for the identifiers of mathematical bibliographies. Their
|
|
5
|
+
* matchers accept the spellings found in real exports (`doi:10…`,
|
|
6
|
+
* `https://doi.org/10…`, `arXiv:2301.00001v2`, `MR1234567`). Use them as they
|
|
7
|
+
* are, or spread one to change a property:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* badges: [{ ...badgePresets.doi, className: "badge" }, badgePresets.arxiv]
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* The title link uses the same preset for these fields, so both always agree.
|
|
14
|
+
*/
|
|
15
|
+
export declare const badgePresets: Readonly<{
|
|
16
|
+
doi: Readonly<{
|
|
17
|
+
field: "doi";
|
|
18
|
+
label: "DOI";
|
|
19
|
+
url: "https://doi.org/$1";
|
|
20
|
+
match: RegExp;
|
|
21
|
+
}>;
|
|
22
|
+
arxiv: Readonly<{
|
|
23
|
+
field: "arxiv";
|
|
24
|
+
label: "arXiv";
|
|
25
|
+
url: "https://arxiv.org/abs/$1";
|
|
26
|
+
match: RegExp;
|
|
27
|
+
}>;
|
|
28
|
+
mrnumber: Readonly<{
|
|
29
|
+
field: "mrnumber";
|
|
30
|
+
label: "MR";
|
|
31
|
+
url: "https://mathscinet.ams.org/mathscinet-getitem?mr=$1";
|
|
32
|
+
match: RegExp;
|
|
33
|
+
}>;
|
|
34
|
+
zbl: Readonly<{
|
|
35
|
+
field: "zbl";
|
|
36
|
+
label: "zbMATH";
|
|
37
|
+
url: "https://zbmath.org/?q=an:$1";
|
|
38
|
+
match: RegExp;
|
|
39
|
+
}>;
|
|
40
|
+
}>;
|
|
3
41
|
export declare class Bibliography {
|
|
4
42
|
/** The CSL template name to use for formatting. */
|
|
5
43
|
readonly templateName: string;
|
|
6
44
|
/** All parsed entries. */
|
|
7
45
|
readonly entries: BibEntry[];
|
|
8
46
|
private readonly customFieldNames;
|
|
47
|
+
private readonly bibtexEntries;
|
|
9
48
|
private readonly math?;
|
|
10
49
|
/** Formatting defaults from the constructor; each call may override them. */
|
|
11
50
|
private readonly formatDefaults;
|
|
51
|
+
private rendering?;
|
|
12
52
|
constructor(options: BibliographyOptions);
|
|
13
53
|
/**
|
|
14
54
|
* Return entries whose custom fields match **all** given key/value pairs.
|
|
@@ -18,14 +58,15 @@ export declare class Bibliography {
|
|
|
18
58
|
*/
|
|
19
59
|
filter(criteria: Record<string, string>): BibEntry[];
|
|
20
60
|
/**
|
|
21
|
-
* Return a sorted **copy** of the given entries.
|
|
61
|
+
* Return a sorted **copy** of the given entries. Ties keep their input order.
|
|
22
62
|
*
|
|
23
63
|
* @param entries - entries to sort (not mutated)
|
|
24
|
-
* @param by - `'year'` (default)
|
|
64
|
+
* @param by - `'year'` (default), `'date'` (year, then month, then day; a
|
|
65
|
+
* missing part counts as 0), or a custom field name
|
|
25
66
|
* @param order - `'desc'` (default) or `'asc'`
|
|
26
67
|
*/
|
|
27
68
|
sort(entries: BibEntry[], { by, order }?: {
|
|
28
|
-
by?: string;
|
|
69
|
+
by?: "year" | "date" | (string & {});
|
|
29
70
|
order?: "asc" | "desc";
|
|
30
71
|
}): BibEntry[];
|
|
31
72
|
/**
|
|
@@ -34,32 +75,61 @@ export declare class Bibliography {
|
|
|
34
75
|
*/
|
|
35
76
|
formatEntry(entry: BibEntry, options?: FormatOptions): string;
|
|
36
77
|
/**
|
|
37
|
-
*
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
*
|
|
42
|
-
*
|
|
78
|
+
* Format a list of entries as a complete HTML bibliography.
|
|
79
|
+
*/
|
|
80
|
+
formatHtml(entries: BibEntry[], options?: FormatOptions): string;
|
|
81
|
+
/**
|
|
82
|
+
* The links an entry gets with these options: its title link and badges.
|
|
83
|
+
* The same resolution the formatted HTML uses, so the two always agree; for
|
|
84
|
+
* rendering badges yourself, pair it with `appendBadges: false`.
|
|
85
|
+
*/
|
|
86
|
+
links(entry: BibEntry, options?: FormatOptions): EntryLinks;
|
|
87
|
+
/**
|
|
88
|
+
* The entry as BibTeX that stands on its own, e.g. for readers to copy:
|
|
89
|
+
* `@string` abbreviations are resolved and the fields of `crossref` parents
|
|
90
|
+
* filled in using biblatex's title-remapping rules. Missing parents leave
|
|
91
|
+
* `crossref` unresolved, so the copy may still require its parent.
|
|
92
|
+
* Field values are the TeX of the `.bib` file. Requires this bibliography's
|
|
93
|
+
* original key and raw object; shallow entry copies are accepted.
|
|
94
|
+
*/
|
|
95
|
+
bibtex(entry: BibEntry, options?: BibtexOptions): string;
|
|
96
|
+
/**
|
|
97
|
+
* An entry's fields with those inherited through `crossref`, using the same
|
|
98
|
+
* biblatex title-remapping rules as citation-js (`plugin-bibtex`'s
|
|
99
|
+
* `mapping/crossref.js`). Keep the mapping and exclusion tests in sync.
|
|
43
100
|
*/
|
|
44
|
-
private
|
|
101
|
+
private withInherited;
|
|
45
102
|
/** Per-call options win over the defaults given to the constructor. */
|
|
46
103
|
private mergeOptions;
|
|
47
104
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
105
|
+
* Entry HTML without wrapper, shared by `formatEntry` and `formatHtml` so
|
|
106
|
+
* both honour the same options. Links are resolved first: they decide what
|
|
107
|
+
* the style may print and what is added afterwards.
|
|
51
108
|
*/
|
|
52
|
-
private
|
|
109
|
+
private renderItems;
|
|
53
110
|
/**
|
|
54
|
-
*
|
|
111
|
+
* Called by citeproc for every variable it renders. Everything the library
|
|
112
|
+
* adds to the citation text happens here, one variable at a time, instead of
|
|
113
|
+
* by searching the finished HTML:
|
|
114
|
+
*
|
|
115
|
+
* - the title link, around the exact output of the title variable, so no
|
|
116
|
+
* quotes, markup or capitalisation the style applies can hide the title;
|
|
117
|
+
* - bare URLs in a variable (e.g. in a `note`) become links. Formulas are
|
|
118
|
+
* still placeholders here, so MathML's xmlns URL is never linked;
|
|
119
|
+
* - the consumer's `wrapVariable`, outermost.
|
|
55
120
|
*/
|
|
56
|
-
|
|
121
|
+
private wrapVariable;
|
|
122
|
+
/** Sanitize while formulas are placeholders, then insert rendered math. */
|
|
123
|
+
private finish;
|
|
124
|
+
private resolveLinks;
|
|
57
125
|
private registerStyle;
|
|
126
|
+
/**
|
|
127
|
+
* Render entries with citeproc, as `cite.format("bibliography")` does, but
|
|
128
|
+
* through an engine that has our variable wrapper: citeproc only accepts it
|
|
129
|
+
* when the engine is created. Styles and locales come from citation-js's
|
|
130
|
+
* registries, and the data is prepared the same way.
|
|
131
|
+
*/
|
|
58
132
|
private renderCslEntries;
|
|
59
|
-
private decorateEntryHtml;
|
|
60
|
-
private resolveTitleLink;
|
|
61
|
-
private linkTitle;
|
|
62
|
-
private renderBadges;
|
|
63
133
|
}
|
|
64
134
|
/**
|
|
65
135
|
* Auto-linkify bare `http(s)://` URLs in HTML that aren't already inside
|