postext 1.11.3 → 1.12.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.
Files changed (162) hide show
  1. package/dist/__tests__/exports.test.js +24 -0
  2. package/dist/__tests__/exports.test.js.map +1 -1
  3. package/dist/__tests__/parse/anchors.test.d.ts +2 -0
  4. package/dist/__tests__/parse/anchors.test.d.ts.map +1 -0
  5. package/dist/__tests__/parse/anchors.test.js +71 -0
  6. package/dist/__tests__/parse/anchors.test.js.map +1 -0
  7. package/dist/__tests__/parse/citations.test.d.ts +2 -0
  8. package/dist/__tests__/parse/citations.test.d.ts.map +1 -0
  9. package/dist/__tests__/parse/citations.test.js +106 -0
  10. package/dist/__tests__/parse/citations.test.js.map +1 -0
  11. package/dist/__tests__/parse/containers.test.js +1 -1
  12. package/dist/__tests__/parse/containers.test.js.map +1 -1
  13. package/dist/__tests__/pipeline/citationNotes.test.d.ts +2 -0
  14. package/dist/__tests__/pipeline/citationNotes.test.d.ts.map +1 -0
  15. package/dist/__tests__/pipeline/citationNotes.test.js +46 -0
  16. package/dist/__tests__/pipeline/citationNotes.test.js.map +1 -0
  17. package/dist/__tests__/pipeline/crossRefs.test.d.ts +2 -0
  18. package/dist/__tests__/pipeline/crossRefs.test.d.ts.map +1 -0
  19. package/dist/__tests__/pipeline/crossRefs.test.js +170 -0
  20. package/dist/__tests__/pipeline/crossRefs.test.js.map +1 -0
  21. package/dist/__tests__/pipeline/footnoteNumberGap.test.d.ts +2 -0
  22. package/dist/__tests__/pipeline/footnoteNumberGap.test.d.ts.map +1 -0
  23. package/dist/__tests__/pipeline/footnoteNumberGap.test.js +75 -0
  24. package/dist/__tests__/pipeline/footnoteNumberGap.test.js.map +1 -0
  25. package/dist/bundle/book.d.ts.map +1 -1
  26. package/dist/bundle/book.js +22 -4
  27. package/dist/bundle/book.js.map +1 -1
  28. package/dist/citations/bibtex.d.ts +19 -0
  29. package/dist/citations/bibtex.d.ts.map +1 -0
  30. package/dist/citations/bibtex.js +376 -0
  31. package/dist/citations/bibtex.js.map +1 -0
  32. package/dist/citations/context.d.ts +64 -0
  33. package/dist/citations/context.d.ts.map +1 -0
  34. package/dist/citations/context.js +115 -0
  35. package/dist/citations/context.js.map +1 -0
  36. package/dist/citations/data.d.ts +35 -0
  37. package/dist/citations/data.d.ts.map +1 -0
  38. package/dist/citations/data.js +158 -0
  39. package/dist/citations/data.js.map +1 -0
  40. package/dist/citations/html.d.ts +16 -0
  41. package/dist/citations/html.d.ts.map +1 -0
  42. package/dist/citations/html.js +99 -0
  43. package/dist/citations/html.js.map +1 -0
  44. package/dist/citations/registry.d.ts +30 -0
  45. package/dist/citations/registry.d.ts.map +1 -0
  46. package/dist/citations/registry.js +51 -0
  47. package/dist/citations/registry.js.map +1 -0
  48. package/dist/citations/types.d.ts +138 -0
  49. package/dist/citations/types.d.ts.map +1 -0
  50. package/dist/citations/types.js +9 -0
  51. package/dist/citations/types.js.map +1 -0
  52. package/dist/defaults/citations.d.ts +5 -0
  53. package/dist/defaults/citations.d.ts.map +1 -0
  54. package/dist/defaults/citations.js +99 -0
  55. package/dist/defaults/citations.js.map +1 -0
  56. package/dist/defaults/crossRefs.d.ts +7 -0
  57. package/dist/defaults/crossRefs.d.ts.map +1 -0
  58. package/dist/defaults/crossRefs.js +35 -0
  59. package/dist/defaults/crossRefs.js.map +1 -0
  60. package/dist/defaults/index.d.ts +2 -0
  61. package/dist/defaults/index.d.ts.map +1 -1
  62. package/dist/defaults/index.js +18 -0
  63. package/dist/defaults/index.js.map +1 -1
  64. package/dist/html-backend.d.ts.map +1 -1
  65. package/dist/html-backend.js +79 -19
  66. package/dist/html-backend.js.map +1 -1
  67. package/dist/index.d.ts +10 -4
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +9 -2
  70. package/dist/index.js.map +1 -1
  71. package/dist/knuthPlass/richAdapter.d.ts +2 -0
  72. package/dist/knuthPlass/richAdapter.d.ts.map +1 -1
  73. package/dist/knuthPlass/richAdapter.js +1 -1
  74. package/dist/knuthPlass/richAdapter.js.map +1 -1
  75. package/dist/measure/cache.js +1 -1
  76. package/dist/measure/cache.js.map +1 -1
  77. package/dist/measure/rich.d.ts +4 -0
  78. package/dist/measure/rich.d.ts.map +1 -1
  79. package/dist/measure/rich.js +9 -2
  80. package/dist/measure/rich.js.map +1 -1
  81. package/dist/parse/attrs.d.ts.map +1 -1
  82. package/dist/parse/attrs.js +31 -4
  83. package/dist/parse/attrs.js.map +1 -1
  84. package/dist/parse/blockParser.d.ts.map +1 -1
  85. package/dist/parse/blockParser.js +68 -8
  86. package/dist/parse/blockParser.js.map +1 -1
  87. package/dist/parse/citations.d.ts +41 -0
  88. package/dist/parse/citations.d.ts.map +1 -0
  89. package/dist/parse/citations.js +214 -0
  90. package/dist/parse/citations.js.map +1 -0
  91. package/dist/parse/index.d.ts +1 -1
  92. package/dist/parse/index.d.ts.map +1 -1
  93. package/dist/parse/index.js.map +1 -1
  94. package/dist/parse/indexMarks.d.ts +2 -7
  95. package/dist/parse/indexMarks.d.ts.map +1 -1
  96. package/dist/parse/indexMarks.js +65 -20
  97. package/dist/parse/indexMarks.js.map +1 -1
  98. package/dist/parse/inlineFormatting.d.ts +2 -2
  99. package/dist/parse/inlineFormatting.d.ts.map +1 -1
  100. package/dist/parse/inlineFormatting.js +41 -14
  101. package/dist/parse/inlineFormatting.js.map +1 -1
  102. package/dist/parse/types.d.ts +54 -4
  103. package/dist/parse/types.d.ts.map +1 -1
  104. package/dist/pipeline/anchors.d.ts +28 -0
  105. package/dist/pipeline/anchors.d.ts.map +1 -0
  106. package/dist/pipeline/anchors.js +123 -0
  107. package/dist/pipeline/anchors.js.map +1 -0
  108. package/dist/pipeline/build.d.ts.map +1 -1
  109. package/dist/pipeline/build.js +51 -11
  110. package/dist/pipeline/build.js.map +1 -1
  111. package/dist/pipeline/citations.d.ts +80 -0
  112. package/dist/pipeline/citations.d.ts.map +1 -0
  113. package/dist/pipeline/citations.js +437 -0
  114. package/dist/pipeline/citations.js.map +1 -0
  115. package/dist/pipeline/config.d.ts.map +1 -1
  116. package/dist/pipeline/config.js +3 -1
  117. package/dist/pipeline/config.js.map +1 -1
  118. package/dist/pipeline/contentWarnings.d.ts +7 -1
  119. package/dist/pipeline/contentWarnings.d.ts.map +1 -1
  120. package/dist/pipeline/contentWarnings.js +57 -3
  121. package/dist/pipeline/contentWarnings.js.map +1 -1
  122. package/dist/pipeline/continuation.d.ts +2 -1
  123. package/dist/pipeline/continuation.d.ts.map +1 -1
  124. package/dist/pipeline/continuation.js +3 -0
  125. package/dist/pipeline/continuation.js.map +1 -1
  126. package/dist/pipeline/crossRefs.d.ts +79 -0
  127. package/dist/pipeline/crossRefs.d.ts.map +1 -0
  128. package/dist/pipeline/crossRefs.js +207 -0
  129. package/dist/pipeline/crossRefs.js.map +1 -0
  130. package/dist/pipeline/floatPlacement.d.ts.map +1 -1
  131. package/dist/pipeline/floatPlacement.js +2 -1
  132. package/dist/pipeline/floatPlacement.js.map +1 -1
  133. package/dist/pipeline/footnotes.d.ts.map +1 -1
  134. package/dist/pipeline/footnotes.js +5 -3
  135. package/dist/pipeline/footnotes.js.map +1 -1
  136. package/dist/pipeline/index.d.ts +2 -1
  137. package/dist/pipeline/index.d.ts.map +1 -1
  138. package/dist/pipeline/index.js +2 -1
  139. package/dist/pipeline/index.js.map +1 -1
  140. package/dist/pipeline/measureContentBlock.d.ts +4 -0
  141. package/dist/pipeline/measureContentBlock.d.ts.map +1 -1
  142. package/dist/pipeline/measureContentBlock.js +2 -1
  143. package/dist/pipeline/measureContentBlock.js.map +1 -1
  144. package/dist/pipeline/outline.d.ts +3 -0
  145. package/dist/pipeline/outline.d.ts.map +1 -1
  146. package/dist/pipeline/outline.js +38 -1
  147. package/dist/pipeline/outline.js.map +1 -1
  148. package/dist/pipeline/resourceLayout.d.ts +13 -1
  149. package/dist/pipeline/resourceLayout.d.ts.map +1 -1
  150. package/dist/pipeline/resourceLayout.js +22 -2
  151. package/dist/pipeline/resourceLayout.js.map +1 -1
  152. package/dist/pipeline/resourceNumbering.d.ts.map +1 -1
  153. package/dist/pipeline/resourceNumbering.js +2 -1
  154. package/dist/pipeline/resourceNumbering.js.map +1 -1
  155. package/dist/types.d.ts +133 -2
  156. package/dist/types.d.ts.map +1 -1
  157. package/dist/vdt.d.ts +59 -1
  158. package/dist/vdt.d.ts.map +1 -1
  159. package/dist/vdt.js.map +1 -1
  160. package/dist/worker/layout.worker.js +6 -0
  161. package/dist/worker/layout.worker.js.map +1 -1
  162. package/package.json +1 -1
@@ -0,0 +1,64 @@
1
+ /**
2
+ * The citations of a book (#272): every reference its documents define,
3
+ * every citation in reading order, and where each document's citations
4
+ * sit in that order. Numbering, disambiguation and *ibid.* see the whole
5
+ * book, so each document is formatted against its book's context — the
6
+ * host builds it once (`bookCitationContexts`) and hands each chapter its
7
+ * own; a document laid out alone is a book of one.
8
+ */
9
+ import type { ContentBlock } from '../parse';
10
+ import type { CitationClusterInput, CslItem } from './types';
11
+ import { type ReferenceIssue } from './data';
12
+ /** A document's share of its book's citations. */
13
+ export interface CitationContext {
14
+ /** Every reference of the book (the first definition of a key wins). */
15
+ items: CslItem[];
16
+ /** Keys the book lists without citing them (`'*'`: all). */
17
+ nocite: string[];
18
+ /** Every citation of the book in note order: reading order, a citation
19
+ * inside a footnote at its note's place. `noteIndex` is the note a
20
+ * note style sets it in. */
21
+ clusters: CitationClusterInput[];
22
+ /** The index in {@link clusters} of each citation of this document, in
23
+ * the order the document's spans hold them. */
24
+ local: number[];
25
+ /** Some document of the book places the bibliography (`:::bibliography`). */
26
+ placed: boolean;
27
+ /** This document is the book's last (the bibliography goes after it when
28
+ * nothing places it). */
29
+ last: boolean;
30
+ /** Problems with this document's reference data. */
31
+ issues: ReferenceIssue[];
32
+ }
33
+ /** The citations of a parsed document, each with the note it sits in:
34
+ * `note` is the footnote id for a citation in a footnote's text. */
35
+ export declare function citationsOfBlocks(blocks: readonly ContentBlock[]): {
36
+ cluster: CitationClusterInput;
37
+ note?: string;
38
+ }[];
39
+ /** Whether a document has anything for the citations to do: a citation,
40
+ * a `:::references` or `:::bibliography` block, or references in its front
41
+ * matter. */
42
+ export declare function needsCitationContext(blocks: readonly ContentBlock[], metadata: Record<string, unknown> | object | undefined): boolean;
43
+ /** Whether the parsed content places a bibliography. */
44
+ export declare function hasBibliographyDirective(blocks: readonly ContentBlock[]): boolean;
45
+ /** One document of a book, parsed: its front matter and blocks. */
46
+ export interface CitationSource {
47
+ metadata?: Record<string, unknown>;
48
+ blocks: readonly ContentBlock[];
49
+ }
50
+ /** The parsed form of a document's markdown, for {@link bookCitationContexts}. */
51
+ export declare function citationSourceOf(markdown: string): CitationSource;
52
+ /**
53
+ * The citation context of every document of a book, in order. Notes are
54
+ * counted through the book: a footnote marker takes the next note the
55
+ * first time its id is cited, a citation in the text takes a note of its
56
+ * own (where a note style sets it), and a citation in a footnote's text
57
+ * sits in that footnote's note.
58
+ */
59
+ export declare function bookCitationContexts(sources: readonly CitationSource[]): CitationContext[];
60
+ /** A fingerprint of a context's book-wide part: what a chapter's citations
61
+ * and bibliography depend on (a host compares it to know a chapter's
62
+ * layout went stale). */
63
+ export declare function citationContextKey(ctx: CitationContext | undefined): string;
64
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/citations/context.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG7C,OAAO,KAAK,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,QAAQ,CAAC;AAEjE,kDAAkD;AAClD,MAAM,WAAW,eAAe;IAC9B,wEAAwE;IACxE,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,4DAA4D;IAC5D,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB;;iCAE6B;IAC7B,QAAQ,EAAE,oBAAoB,EAAE,CAAC;IACjC;oDACgD;IAChD,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,6EAA6E;IAC7E,MAAM,EAAE,OAAO,CAAC;IAChB;8BAC0B;IAC1B,IAAI,EAAE,OAAO,CAAC;IACd,oDAAoD;IACpD,MAAM,EAAE,cAAc,EAAE,CAAC;CAC1B;AAED;qEACqE;AACrE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,GAAG;IAAE,OAAO,EAAE,oBAAoB,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,CAQrH;AAED;;cAEc;AACd,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAGrI;AAED,wDAAwD;AACxD,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,GAAG,OAAO,CAEjF;AAED,mEAAmE;AACnE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,MAAM,EAAE,SAAS,YAAY,EAAE,CAAC;CACjC;AAED,kFAAkF;AAClF,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CAGjE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,GAAG,eAAe,EAAE,CAkD1F;AAED;;0BAE0B;AAC1B,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,eAAe,GAAG,SAAS,GAAG,MAAM,CAG3E"}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * The citations of a book (#272): every reference its documents define,
3
+ * every citation in reading order, and where each document's citations
4
+ * sit in that order. Numbering, disambiguation and *ibid.* see the whole
5
+ * book, so each document is formatted against its book's context — the
6
+ * host builds it once (`bookCitationContexts`) and hands each chapter its
7
+ * own; a document laid out alone is a book of one.
8
+ */
9
+ import { extractFrontmatter } from '../frontmatter';
10
+ import { parseMarkdownMemo } from '../parse';
11
+ import { documentReferences } from './data';
12
+ /** The citations of a parsed document, each with the note it sits in:
13
+ * `note` is the footnote id for a citation in a footnote's text. */
14
+ export function citationsOfBlocks(blocks) {
15
+ const out = [];
16
+ for (const b of blocks) {
17
+ for (const s of b.spans) {
18
+ if (s.citation)
19
+ out.push({ cluster: s.citation.cluster, ...(b.footnoteDef !== undefined ? { note: b.footnoteDef } : {}) });
20
+ }
21
+ }
22
+ return out;
23
+ }
24
+ /** Whether a document has anything for the citations to do: a citation,
25
+ * a `:::references` or `:::bibliography` block, or references in its front
26
+ * matter. */
27
+ export function needsCitationContext(blocks, metadata) {
28
+ if (metadata && Array.isArray(metadata.references))
29
+ return true;
30
+ return blocks.some((b) => (b.type === 'directive' && (b.directiveName === 'references' || b.directiveName === 'bibliography')) || b.spans.some((s) => s.citation));
31
+ }
32
+ /** Whether the parsed content places a bibliography. */
33
+ export function hasBibliographyDirective(blocks) {
34
+ return blocks.some((b) => b.type === 'directive' && b.directiveName === 'bibliography');
35
+ }
36
+ /** The parsed form of a document's markdown, for {@link bookCitationContexts}. */
37
+ export function citationSourceOf(markdown) {
38
+ const { metadata, content } = extractFrontmatter(markdown);
39
+ return { metadata: metadata, blocks: parseMarkdownMemo(content) };
40
+ }
41
+ /**
42
+ * The citation context of every document of a book, in order. Notes are
43
+ * counted through the book: a footnote marker takes the next note the
44
+ * first time its id is cited, a citation in the text takes a note of its
45
+ * own (where a note style sets it), and a citation in a footnote's text
46
+ * sits in that footnote's note.
47
+ */
48
+ export function bookCitationContexts(sources) {
49
+ const items = [];
50
+ const seen = new Set();
51
+ const nocite = [];
52
+ const issues = [];
53
+ for (const src of sources) {
54
+ const data = documentReferences(src.metadata, src.blocks);
55
+ for (const item of data.items) {
56
+ if (seen.has(item.id))
57
+ continue;
58
+ seen.add(item.id);
59
+ items.push(item);
60
+ }
61
+ for (const k of data.nocite)
62
+ if (!nocite.includes(k))
63
+ nocite.push(k);
64
+ issues.push(data.issues);
65
+ }
66
+ // Note order: number the notes, then sort the citations by note.
67
+ let note = 0;
68
+ const entries = [];
69
+ let seq = 0;
70
+ sources.forEach((src, doc) => {
71
+ const noteOf = new Map();
72
+ const inNotes = [];
73
+ let order = 0;
74
+ for (const b of src.blocks) {
75
+ if (b.footnoteDef !== undefined) {
76
+ for (const s of b.spans)
77
+ if (s.citation)
78
+ inNotes.push({ cluster: s.citation.cluster, note: b.footnoteDef, order: order++ });
79
+ continue;
80
+ }
81
+ for (const s of b.spans) {
82
+ if (s.footnote && !noteOf.has(s.footnote.id))
83
+ noteOf.set(s.footnote.id, ++note);
84
+ if (s.citation)
85
+ entries.push({ cluster: s.citation.cluster, doc, order: order++, noteIndex: ++note, seq: seq++ });
86
+ }
87
+ }
88
+ for (const c of inNotes)
89
+ entries.push({ cluster: c.cluster, doc, order: c.order, noteIndex: noteOf.get(c.note) ?? 0, seq: seq++ });
90
+ });
91
+ const sorted = [...entries].sort((a, b) => a.doc - b.doc || a.noteIndex - b.noteIndex || a.seq - b.seq);
92
+ const clusters = sorted.map((e) => ({ ...e.cluster, noteIndex: e.noteIndex }));
93
+ const placed = sources.some((s) => hasBibliographyDirective(s.blocks));
94
+ return sources.map((_, doc) => {
95
+ const mine = sorted.map((e, i) => ({ e, i })).filter(({ e }) => e.doc === doc).sort((a, b) => a.e.order - b.e.order);
96
+ return {
97
+ items,
98
+ nocite,
99
+ clusters,
100
+ local: mine.map(({ i }) => i),
101
+ placed,
102
+ last: doc === sources.length - 1,
103
+ issues: issues[doc] ?? [],
104
+ };
105
+ });
106
+ }
107
+ /** A fingerprint of a context's book-wide part: what a chapter's citations
108
+ * and bibliography depend on (a host compares it to know a chapter's
109
+ * layout went stale). */
110
+ export function citationContextKey(ctx) {
111
+ if (!ctx)
112
+ return '';
113
+ return JSON.stringify([ctx.items, ctx.nocite, ctx.clusters, ctx.local, ctx.placed, ctx.last]);
114
+ }
115
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/citations/context.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,EAAE,kBAAkB,EAAuB,MAAM,QAAQ,CAAC;AAwBjE;qEACqE;AACrE,MAAM,UAAU,iBAAiB,CAAC,MAA+B;IAC/D,MAAM,GAAG,GAAuD,EAAE,CAAC;IACnE,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACvB,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;YACxB,IAAI,CAAC,CAAC,QAAQ;gBAAE,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAC7H,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;cAEc;AACd,MAAM,UAAU,oBAAoB,CAAC,MAA+B,EAAE,QAAsD;IAC1H,IAAI,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAE,QAAoC,CAAC,UAAU,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7F,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,IAAI,CAAC,CAAC,CAAC,aAAa,KAAK,YAAY,IAAI,CAAC,CAAC,aAAa,KAAK,cAAc,CAAC,CAAC,IAAI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CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACrH,OAAO;YACL,KAAK;YACL,MAAM;YACN,QAAQ;YACR,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;YAC7B,MAAM;YACN,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,MAAM,GAAG,CAAC;YAChC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE;SAC1B,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;0BAE0B;AAC1B,MAAM,UAAU,kBAAkB,CAAC,GAAgC;IACjE,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IACpB,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AAChG,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The references of a document (#268): CSL items written in its front
3
+ * matter (`references:`, as Pandoc reads them) and in `:::references`
4
+ * blocks (BibTeX, CSL-JSON or CSL-YAML), and the works it lists without
5
+ * citing them (`nocite`).
6
+ */
7
+ import type { ContentBlock } from '../parse';
8
+ import type { CslItem } from './types';
9
+ /** Something wrong with the reference data, where it is written. */
10
+ export interface ReferenceIssue {
11
+ message: string;
12
+ sourceStart: number;
13
+ sourceEnd: number;
14
+ }
15
+ /** The references and `nocite` keys of a document. */
16
+ export interface ReferenceData {
17
+ items: CslItem[];
18
+ /** Keys listed without a citation; `'*'` lists every reference. */
19
+ nocite: string[];
20
+ issues: ReferenceIssue[];
21
+ }
22
+ /** A reference as YAML or JSON wrote it, as a CSL item; undefined without
23
+ * an id. Types default to `book`; dates and names are normalised; numbers
24
+ * become strings. */
25
+ export declare function normalizeCslItem(raw: unknown): CslItem | undefined;
26
+ /** The `nocite` field of a front matter: `'@*'`, `'@a, @b'`, `['@a']`. */
27
+ export declare function nociteKeys(value: unknown): string[];
28
+ /** The items of a `:::references` block, in its `format` (`bibtex`,
29
+ * `csl-json`, `csl-yaml`; guessed from the body when unset). */
30
+ export declare function referencesOfBlock(block: ContentBlock, issues: ReferenceIssue[]): CslItem[];
31
+ /** The references of a document: its front matter's `references` and
32
+ * `nocite`, and every `:::references` block, in order. A key written twice
33
+ * keeps its first entry. */
34
+ export declare function documentReferences(metadata: Record<string, unknown> | undefined, blocks: readonly ContentBlock[]): ReferenceData;
35
+ //# sourceMappingURL=data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/citations/data.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAW,OAAO,EAAW,MAAM,SAAS,CAAC;AAGzD,oEAAoE;AACpE,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,sDAAsD;AACtD,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,mEAAmE;IACnE,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,cAAc,EAAE,CAAC;CAC1B;AA6CD;;sBAEsB;AACtB,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAqBlE;AAED,0EAA0E;AAC1E,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,EAAE,CAKnD;AAED;iEACiE;AACjE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,EAAE,CA4B1F;AAED;;6BAE6B;AAC7B,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAAE,MAAM,EAAE,SAAS,YAAY,EAAE,GAAG,aAAa,CAiBhI"}
@@ -0,0 +1,158 @@
1
+ /**
2
+ * The references of a document (#268): CSL items written in its front
3
+ * matter (`references:`, as Pandoc reads them) and in `:::references`
4
+ * blocks (BibTeX, CSL-JSON or CSL-YAML), and the works it lists without
5
+ * citing them (`nocite`).
6
+ */
7
+ import matter from 'gray-matter';
8
+ import { parseBibtex } from './bibtex';
9
+ const DATE_FIELDS = ['issued', 'accessed', 'event-date', 'original-date', 'submitted', 'available-date'];
10
+ const NAME_FIELDS = ['author', 'editor', 'translator', 'container-author', 'collection-editor', 'composer', 'director', 'interviewer', 'recipient', 'reviewed-author', 'editorial-director', 'illustrator', 'chair', 'compiler', 'contributor', 'curator', 'executive-producer', 'guest', 'host', 'narrator', 'organizer', 'performer', 'producer', 'script-writer', 'series-creator'];
11
+ /** A date as YAML or JSON wrote it — `2020`, `2020-05-03`, a `Date`,
12
+ * `{date-parts: …}`, `{year: 2020}` — as a CSL date. */
13
+ function normalizeDate(value) {
14
+ if (value instanceof Date) {
15
+ if (Number.isNaN(value.getTime()))
16
+ return undefined;
17
+ return { 'date-parts': [[value.getUTCFullYear(), value.getUTCMonth() + 1, value.getUTCDate()]] };
18
+ }
19
+ if (typeof value === 'number')
20
+ return { 'date-parts': [[value]] };
21
+ if (typeof value === 'string') {
22
+ const m = /^(-?\d{1,4})(?:-(\d{1,2}))?(?:-(\d{1,2}))?$/.exec(value.trim());
23
+ if (m)
24
+ return { 'date-parts': [[Number(m[1]), ...(m[2] ? [Number(m[2])] : []), ...(m[3] ? [Number(m[3])] : [])]] };
25
+ return { literal: value };
26
+ }
27
+ if (Array.isArray(value)) {
28
+ const first = normalizeDate(value[0]);
29
+ const second = value.length > 1 ? normalizeDate(value[1]) : undefined;
30
+ if (first?.['date-parts'] && second?.['date-parts'])
31
+ return { 'date-parts': [first['date-parts'][0], second['date-parts'][0]] };
32
+ return first;
33
+ }
34
+ if (value && typeof value === 'object') {
35
+ const o = value;
36
+ if (o['date-parts'] || o.literal || o.raw)
37
+ return o;
38
+ if (o.year !== undefined)
39
+ return { 'date-parts': [[Number(o.year), ...(o.month !== undefined ? [Number(o.month)] : []), ...(o.day !== undefined ? [Number(o.day)] : [])]] };
40
+ }
41
+ return undefined;
42
+ }
43
+ /** A name as YAML wrote it: `{family, given}`, or a string — `"García,
44
+ * Ana"`, `"Ana García"`, a Chinese name written whole — as a CSL name. */
45
+ function normalizeName(value) {
46
+ if (value && typeof value === 'object')
47
+ return value;
48
+ if (typeof value !== 'string' || value.trim().length === 0)
49
+ return undefined;
50
+ const text = value.trim();
51
+ const comma = text.indexOf(',');
52
+ if (comma > 0)
53
+ return { family: text.slice(0, comma).trim(), given: text.slice(comma + 1).trim() };
54
+ if (!/\s/.test(text))
55
+ return { family: text };
56
+ const words = text.split(/\s+/);
57
+ return { family: words[words.length - 1], given: words.slice(0, -1).join(' ') };
58
+ }
59
+ /** A reference as YAML or JSON wrote it, as a CSL item; undefined without
60
+ * an id. Types default to `book`; dates and names are normalised; numbers
61
+ * become strings. */
62
+ export function normalizeCslItem(raw) {
63
+ if (!raw || typeof raw !== 'object')
64
+ return undefined;
65
+ const src = raw;
66
+ const id = src.id ?? src['citation-key'];
67
+ if (id === undefined || id === null || String(id).trim().length === 0)
68
+ return undefined;
69
+ const item = { id: String(id).trim(), type: typeof src.type === 'string' ? src.type : 'book' };
70
+ for (const [key, value] of Object.entries(src)) {
71
+ if (key === 'id' || key === 'type')
72
+ continue;
73
+ if (DATE_FIELDS.includes(key)) {
74
+ const date = normalizeDate(value);
75
+ if (date)
76
+ item[key] = date;
77
+ }
78
+ else if (NAME_FIELDS.includes(key)) {
79
+ const list = (Array.isArray(value) ? value : [value]).map(normalizeName).filter((n) => n !== undefined);
80
+ if (list.length > 0)
81
+ item[key] = list;
82
+ }
83
+ else if (typeof value === 'number') {
84
+ item[key] = String(value);
85
+ }
86
+ else if (value !== null && value !== undefined) {
87
+ item[key] = value;
88
+ }
89
+ }
90
+ return item;
91
+ }
92
+ /** The `nocite` field of a front matter: `'@*'`, `'@a, @b'`, `['@a']`. */
93
+ export function nociteKeys(value) {
94
+ const text = Array.isArray(value) ? value.map(String).join(' ') : typeof value === 'string' ? value : '';
95
+ const out = [];
96
+ for (const m of text.matchAll(/@(\*|[\p{L}\p{N}_][\p{L}\p{N}_:.#$%&\-+?<>~/]*[\p{L}\p{N}_]?)/gu))
97
+ out.push(m[1]);
98
+ return out;
99
+ }
100
+ /** The items of a `:::references` block, in its `format` (`bibtex`,
101
+ * `csl-json`, `csl-yaml`; guessed from the body when unset). */
102
+ export function referencesOfBlock(block, issues) {
103
+ const body = block.rawBody ?? '';
104
+ const at = { sourceStart: block.sourceStart, sourceEnd: block.sourceEnd };
105
+ const declared = block.directiveAttrs?.format?.toLowerCase();
106
+ const trimmed = body.trim();
107
+ if (trimmed.length === 0)
108
+ return [];
109
+ const format = declared ?? (trimmed.startsWith('@') ? 'bibtex' : trimmed.startsWith('[') || trimmed.startsWith('{') ? 'csl-json' : 'csl-yaml');
110
+ try {
111
+ if (format === 'bibtex' || format === 'biblatex' || format === 'bib') {
112
+ const read = [];
113
+ const items = parseBibtex(body, read);
114
+ for (const issue of read)
115
+ issues.push({ message: issue.message, ...at });
116
+ return items;
117
+ }
118
+ if (format === 'csl-json' || format === 'json') {
119
+ const parsed = JSON.parse(trimmed);
120
+ const list = Array.isArray(parsed) ? parsed : parsed.references ?? [parsed];
121
+ return list.map(normalizeCslItem).filter((i) => i !== undefined);
122
+ }
123
+ // CSL-YAML: a `references:` list, or the list itself.
124
+ const yaml = /^references\s*:/m.test(trimmed) ? trimmed : `references:\n${body.replace(/^/gm, ' ')}`;
125
+ const data = matter(`---\n${yaml}\n---\n`).data;
126
+ const list = Array.isArray(data.references) ? data.references : [];
127
+ return list.map(normalizeCslItem).filter((i) => i !== undefined);
128
+ }
129
+ catch (e) {
130
+ issues.push({ message: `unreadable ${format} references: ${e.message.split('\n')[0]}`, ...at });
131
+ return [];
132
+ }
133
+ }
134
+ /** The references of a document: its front matter's `references` and
135
+ * `nocite`, and every `:::references` block, in order. A key written twice
136
+ * keeps its first entry. */
137
+ export function documentReferences(metadata, blocks) {
138
+ const issues = [];
139
+ const items = [];
140
+ const seen = new Set();
141
+ const add = (list) => {
142
+ for (const item of list) {
143
+ if (seen.has(item.id))
144
+ continue;
145
+ seen.add(item.id);
146
+ items.push(item);
147
+ }
148
+ };
149
+ const fm = metadata?.references;
150
+ if (Array.isArray(fm))
151
+ add(fm.map(normalizeCslItem).filter((i) => i !== undefined));
152
+ for (const b of blocks) {
153
+ if (b.type === 'directive' && b.directiveName === 'references')
154
+ add(referencesOfBlock(b, issues));
155
+ }
156
+ return { items, nocite: nociteKeys(metadata?.nocite), issues };
157
+ }
158
+ //# sourceMappingURL=data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data.js","sourceRoot":"","sources":["../../src/citations/data.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,MAAM,MAAM,aAAa,CAAC;AAGjC,OAAO,EAAE,WAAW,EAAoB,MAAM,UAAU,CAAC;AAiBzD,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,gBAAgB,CAAC,CAAC;AACzG,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,UAAU,EAAE,UAAU,EAAE,aA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AAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAgB,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC;IAClG,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACvB,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,IAAI,CAAC,CAAC,aAAa,KAAK,YAAY;YAAE,GAAG,CAAC,iBAAiB,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACpG,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;AACjE,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The small HTML a citation processor writes (citeproc-js's `html` output)
3
+ * as inline spans: `<i>`, `<b>`, `<sup>`, `<sub>`, the `font-style` /
4
+ * `font-weight` / `font-variant` spans CSL flip-flops use, `<a href>`
5
+ * links, and character entities. Any other tag is dropped, its text kept.
6
+ */
7
+ import type { InlineSpan } from '../parse';
8
+ /** Character entities of `text` decoded. */
9
+ export declare function decodeEntities(text: string): string;
10
+ /** The spans of a formatted citation or bibliography entry. `base` is
11
+ * the emphasis of the text around it (a citation in an italic sentence). */
12
+ export declare function htmlToSpans(html: string, base?: {
13
+ bold: boolean;
14
+ italic: boolean;
15
+ }): InlineSpan[];
16
+ //# sourceMappingURL=html.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/citations/html.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAY3C,4CAA4C;AAC5C,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQnD;AAED;6EAC6E;AAC7E,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAmC,GAAG,UAAU,EAAE,CA+DjI"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * The small HTML a citation processor writes (citeproc-js's `html` output)
3
+ * as inline spans: `<i>`, `<b>`, `<sup>`, `<sub>`, the `font-style` /
4
+ * `font-weight` / `font-variant` spans CSL flip-flops use, `<a href>`
5
+ * links, and character entities. Any other tag is dropped, its text kept.
6
+ */
7
+ const NAMED = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: ' ' };
8
+ /** Character entities of `text` decoded. */
9
+ export function decodeEntities(text) {
10
+ return text.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (whole, ref) => {
11
+ if (ref[0] === '#') {
12
+ const code = ref[1] === 'x' || ref[1] === 'X' ? parseInt(ref.slice(2), 16) : parseInt(ref.slice(1), 10);
13
+ return Number.isFinite(code) ? String.fromCodePoint(code) : whole;
14
+ }
15
+ return NAMED[ref.toLowerCase()] ?? whole;
16
+ });
17
+ }
18
+ /** The spans of a formatted citation or bibliography entry. `base` is
19
+ * the emphasis of the text around it (a citation in an italic sentence). */
20
+ export function htmlToSpans(html, base = { bold: false, italic: false }) {
21
+ const out = [];
22
+ const stack = [{ italic: base.italic, bold: base.bold, smallCaps: false }];
23
+ const top = () => stack[stack.length - 1];
24
+ const tagStack = [];
25
+ const push = (text) => {
26
+ if (text.length === 0)
27
+ return;
28
+ const s = top();
29
+ const last = out[out.length - 1];
30
+ const linkOf = (span) => span.links?.[0]?.href;
31
+ if (last && last.italic === s.italic && last.bold === s.bold && (last.smallCaps ?? false) === s.smallCaps && last.script === s.script && linkOf(last) === s.href) {
32
+ last.text += text;
33
+ if (s.href)
34
+ last.links = [{ start: 0, end: last.text.length, href: s.href }];
35
+ return;
36
+ }
37
+ out.push({
38
+ text,
39
+ bold: s.bold,
40
+ italic: s.italic,
41
+ ...(s.smallCaps ? { smallCaps: true } : {}),
42
+ ...(s.script ? { script: s.script } : {}),
43
+ ...(s.href ? { links: [{ start: 0, end: text.length, href: s.href }] } : {}),
44
+ });
45
+ };
46
+ const TAG = /<(\/?)([a-z]+)([^>]*)>/gi;
47
+ let last = 0;
48
+ for (let m = TAG.exec(html); m; m = TAG.exec(html)) {
49
+ push(decodeEntities(html.slice(last, m.index)));
50
+ last = m.index + m[0].length;
51
+ const closing = m[1] === '/';
52
+ const name = m[2].toLowerCase();
53
+ const attrs = m[3] ?? '';
54
+ if (name === 'br')
55
+ continue;
56
+ if (closing) {
57
+ const at = tagStack.lastIndexOf(name);
58
+ if (at >= 0) {
59
+ stack.length = at + 1;
60
+ tagStack.length = at;
61
+ }
62
+ continue;
63
+ }
64
+ const s = { ...top() };
65
+ if (name === 'i' || name === 'em')
66
+ s.italic = true;
67
+ else if (name === 'b' || name === 'strong')
68
+ s.bold = true;
69
+ else if (name === 'sup')
70
+ s.script = 'sup';
71
+ else if (name === 'sub')
72
+ s.script = 'sub';
73
+ else if (name === 'a') {
74
+ const href = /href="([^"]*)"/i.exec(attrs)?.[1];
75
+ if (href)
76
+ s.href = decodeEntities(href);
77
+ }
78
+ else if (name === 'span') {
79
+ const style = /style="([^"]*)"/i.exec(attrs)?.[1] ?? '';
80
+ if (/font-style:\s*italic/i.test(style))
81
+ s.italic = true;
82
+ if (/font-style:\s*normal/i.test(style))
83
+ s.italic = false;
84
+ if (/font-weight:\s*bold/i.test(style))
85
+ s.bold = true;
86
+ if (/font-weight:\s*normal/i.test(style))
87
+ s.bold = false;
88
+ if (/font-variant:\s*small-caps/i.test(style))
89
+ s.smallCaps = true;
90
+ if (/font-variant:\s*normal/i.test(style))
91
+ s.smallCaps = false;
92
+ }
93
+ stack.push(s);
94
+ tagStack.push(name);
95
+ }
96
+ push(decodeEntities(html.slice(last)));
97
+ return out;
98
+ }
99
+ //# sourceMappingURL=html.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.js","sourceRoot":"","sources":["../../src/citations/html.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA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,GAAG,KAAK,CAAC;YACzD,IAAI,6BAA6B,CAAC,IAAI,CAAC,KAAK,CAAC;gBAAE,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC;YAClE,IAAI,yBAAyB,CAAC,IAAI,CAAC,KAAK,CAAC;gBAAE,CAAC,CAAC,SAAS,GAAG,KAAK,CAAC;QACjE,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACd,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IACD,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACvC,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,30 @@
1
+ import type { CitationEngine } from './types';
2
+ /**
3
+ * Register the citation engine the builds format citations with (the
4
+ * `postext-citeproc` package registers itself: `import 'postext-citeproc/register'`).
5
+ * Without one, citations print as written and the build warns
6
+ * (`citationsUnavailable`).
7
+ */
8
+ export declare function registerCitationEngine(next: CitationEngine | undefined): void;
9
+ /** The registered citation engine, if any. */
10
+ export declare function citationEngine(): CitationEngine | undefined;
11
+ /**
12
+ * How to load the citation engine when a document first needs it — a
13
+ * dynamic import, so a host pays for it only on documents that cite:
14
+ *
15
+ * ```ts
16
+ * setCitationEngineLoader(() => import('postext-citeproc/register'));
17
+ * ```
18
+ *
19
+ * The layout worker calls it before building a document that cites works
20
+ * (see {@link ensureCitationEngine}).
21
+ */
22
+ export declare function setCitationEngineLoader(next: (() => Promise<unknown>) | undefined): void;
23
+ /** Load the citation engine with the registered loader, once; true when an
24
+ * engine is registered afterwards. */
25
+ export declare function ensureCitationEngine(): Promise<boolean>;
26
+ /** Whether a document's markdown may cite works or define references: an
27
+ * `@`, a `:::references` block or a `references:` front matter field. A
28
+ * cheap test, before parsing, of whether the engine is worth loading. */
29
+ export declare function mayNeedCitations(markdown: string): boolean;
30
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/citations/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAI9C;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,cAAc,GAAG,SAAS,GAAG,IAAI,CAE7E;AAED,8CAA8C;AAC9C,wBAAgB,cAAc,IAAI,cAAc,GAAG,SAAS,CAE3D;AAKD;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,CAGxF;AAED;uCACuC;AACvC,wBAAgB,oBAAoB,IAAI,OAAO,CAAC,OAAO,CAAC,CAQvD;AAED;;0EAE0E;AAC1E,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAE1D"}
@@ -0,0 +1,51 @@
1
+ let engine;
2
+ /**
3
+ * Register the citation engine the builds format citations with (the
4
+ * `postext-citeproc` package registers itself: `import 'postext-citeproc/register'`).
5
+ * Without one, citations print as written and the build warns
6
+ * (`citationsUnavailable`).
7
+ */
8
+ export function registerCitationEngine(next) {
9
+ engine = next;
10
+ }
11
+ /** The registered citation engine, if any. */
12
+ export function citationEngine() {
13
+ return engine;
14
+ }
15
+ let loader;
16
+ let loading;
17
+ /**
18
+ * How to load the citation engine when a document first needs it — a
19
+ * dynamic import, so a host pays for it only on documents that cite:
20
+ *
21
+ * ```ts
22
+ * setCitationEngineLoader(() => import('postext-citeproc/register'));
23
+ * ```
24
+ *
25
+ * The layout worker calls it before building a document that cites works
26
+ * (see {@link ensureCitationEngine}).
27
+ */
28
+ export function setCitationEngineLoader(next) {
29
+ loader = next;
30
+ loading = undefined;
31
+ }
32
+ /** Load the citation engine with the registered loader, once; true when an
33
+ * engine is registered afterwards. */
34
+ export function ensureCitationEngine() {
35
+ if (engine)
36
+ return Promise.resolve(true);
37
+ if (!loader)
38
+ return Promise.resolve(false);
39
+ loading ??= loader().then(() => engine !== undefined, () => {
40
+ loading = undefined;
41
+ return false;
42
+ });
43
+ return loading;
44
+ }
45
+ /** Whether a document's markdown may cite works or define references: an
46
+ * `@`, a `:::references` block or a `references:` front matter field. A
47
+ * cheap test, before parsing, of whether the engine is worth loading. */
48
+ export function mayNeedCitations(markdown) {
49
+ return markdown.includes('@') || markdown.includes(':::references') || /^references\s*:/m.test(markdown);
50
+ }
51
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/citations/registry.ts"],"names":[],"mappings":"AAEA,IAAI,MAAkC,CAAC;AAEvC;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAgC;IACrE,MAAM,GAAG,IAAI,CAAC;AAChB,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,cAAc;IAC5B,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,IAAI,MAA4C,CAAC;AACjD,IAAI,OAAqC,CAAC;AAE1C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAA0C;IAChF,MAAM,GAAG,IAAI,CAAC;IACd,OAAO,GAAG,SAAS,CAAC;AACtB,CAAC;AAED;uCACuC;AACvC,MAAM,UAAU,oBAAoB;IAClC,IAAI,MAAM;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,IAAI,CAAC,MAAM;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC3C,OAAO,KAAK,MAAM,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,KAAK,SAAS,EAAE,GAAG,EAAE;QACzD,OAAO,GAAG,SAAS,CAAC;QACpB,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;0EAE0E;AAC1E,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,OAAO,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC3G,CAAC"}