@memorysmithapp/markdown-renderer 0.12.1 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/dist/ContentsBlock.d.ts +82 -0
- package/dist/ContentsBlock.js +162 -0
- package/dist/DataTable.js +31 -4
- package/dist/InPageAnchor.d.ts +20 -0
- package/dist/InPageAnchor.js +35 -0
- package/dist/Markdown.d.ts +7 -1
- package/dist/Markdown.js +48 -31
- package/dist/NoteBody.js +107 -28
- package/dist/PropertiesBlock.d.ts +54 -3
- package/dist/PropertiesBlock.js +91 -5
- package/dist/Transclusion.js +4 -1
- package/dist/appendices.d.ts +30 -0
- package/dist/appendices.js +11 -4
- package/dist/contents.d.ts +92 -0
- package/dist/contents.js +224 -0
- package/dist/diagnose.d.ts +3 -1
- package/dist/diagnose.js +25 -0
- package/dist/edit/ContentsDialog.d.ts +39 -0
- package/dist/edit/ContentsDialog.js +126 -0
- package/dist/edit/NoteEditor.js +56 -4
- package/dist/edit/PropertiesDialog.d.ts +42 -0
- package/dist/edit/PropertiesDialog.js +103 -0
- package/dist/edit/StyleDialog.js +5 -3
- package/dist/edit/blocks.d.ts +29 -0
- package/dist/edit/blocks.js +100 -3
- package/dist/edit/contents.d.ts +30 -0
- package/dist/edit/contents.js +76 -0
- package/dist/edit/live.js +72 -2
- package/dist/edit/properties.d.ts +26 -0
- package/dist/edit/properties.js +60 -0
- package/dist/host.d.ts +24 -0
- package/dist/host.js +6 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/kept-files.d.ts +11 -0
- package/dist/kept-files.js +49 -0
- package/dist/note-style.d.ts +9 -1
- package/dist/note-style.js +4 -2
- package/dist/outline.d.ts +227 -0
- package/dist/outline.js +366 -0
- package/dist/properties-block.d.ts +62 -0
- package/dist/properties-block.js +175 -0
- package/dist/slots.js +11 -2
- package/dist/strings.d.ts +60 -0
- package/dist/strings.js +43 -1
- package/dist/table-block.d.ts +13 -1
- package/dist/table-block.js +2 -1
- package/dist/theme.d.ts +19 -0
- package/package.json +4 -2
- package/structure.css +54 -0
- package/theme-default.css +56 -0
package/dist/host.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { type ReactNode } from 'react';
|
|
|
2
2
|
import { type NoteStrings, type NoteStringsInput } from './strings.js';
|
|
3
3
|
import type { TablePage, TableRequest, TableRowView } from './table-block.js';
|
|
4
4
|
import { type NoteStyle } from './note-style.js';
|
|
5
|
+
import { type ContentsSettings } from './contents.js';
|
|
6
|
+
import { type PropertiesSettings } from './properties-block.js';
|
|
5
7
|
import { type Scheme, type Theme } from './theme.js';
|
|
6
8
|
import { type DrawnNote } from './embed-target.js';
|
|
7
9
|
/**
|
|
@@ -105,6 +107,24 @@ export interface NoteHost {
|
|
|
105
107
|
* style; a `:::{style}` block of the note wins over it in its passage.
|
|
106
108
|
*/
|
|
107
109
|
readonly noteStyle?: NoteStyle;
|
|
110
|
+
/**
|
|
111
|
+
* The contents of a note that declares none, as the notebook says (`SPEC.md` §7.17, #173): the
|
|
112
|
+
* structure a `contents` block takes — the lists, their options, `screen` and `print`, `none` —
|
|
113
|
+
* plus `place`, `start` or `end`, at the root or in a medium. A note with no block draws it where
|
|
114
|
+
* `place` says, at the start when it says nothing, in each medium the settings name; a note with
|
|
115
|
+
* a block draws only its own blocks, and these settings are the defaults of what the block leaves
|
|
116
|
+
* unset, `place` excepted. Read as YAML or JSON gives it; a key or value it cannot take is left out.
|
|
117
|
+
*/
|
|
118
|
+
readonly contents?: ContentsSettings;
|
|
119
|
+
/**
|
|
120
|
+
* How the properties of a note are drawn as the notebook says (`SPEC.md` §7.18, #172): the
|
|
121
|
+
* structure a `properties` block takes — `keys`, `title`, `fold`, `screen` and `print`, `none` —
|
|
122
|
+
* plus `place`, `start` or `end`. A note with no block draws its properties as these say, at the
|
|
123
|
+
* start unless `place` says otherwise; a note with a block draws only its own blocks, and these
|
|
124
|
+
* are the defaults of what the block leaves unset, `place` excepted. Without it, a note with no
|
|
125
|
+
* block draws every property at the top, as before.
|
|
126
|
+
*/
|
|
127
|
+
readonly properties?: PropertiesSettings;
|
|
108
128
|
/**
|
|
109
129
|
* Whether the reader may tick the task boxes of this note. Defaults to `false`: every box shows
|
|
110
130
|
* its state and none answers a click.
|
|
@@ -312,6 +332,10 @@ export interface ResolvedHost {
|
|
|
312
332
|
readonly printing: boolean;
|
|
313
333
|
readonly tablesAsAppendices: boolean;
|
|
314
334
|
readonly noteStyle: NoteStyle;
|
|
335
|
+
/** The contents of a note that declares none, cleaned (#173). */
|
|
336
|
+
readonly contents: ContentsSettings | null;
|
|
337
|
+
/** How a note's properties are drawn, cleaned (#172). */
|
|
338
|
+
readonly properties: PropertiesSettings | null;
|
|
315
339
|
readonly keeps: (name: string) => boolean;
|
|
316
340
|
readonly suggest: ((query: string) => readonly string[] | PromiseLike<readonly string[]>) | null;
|
|
317
341
|
readonly attach: ((file: File, attributes: AttachAttributes, progress: (report: AttachProgress) => void) => string | PromiseLike<string>) | null;
|
package/dist/host.js
CHANGED
|
@@ -2,6 +2,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { createContext, useContext, useMemo } from 'react';
|
|
3
3
|
import { withDefaults } from './strings.js';
|
|
4
4
|
import { cleanStyle } from './note-style.js';
|
|
5
|
+
import { cleanContents } from './contents.js';
|
|
6
|
+
import { cleanProperties } from './properties-block.js';
|
|
5
7
|
import { DEFAULT_THEME, schemeOf } from './theme.js';
|
|
6
8
|
import { drawing, drawnNote } from './embed-target.js';
|
|
7
9
|
/** Whether a rejection is a refusal the host worded for the author, and not an error. */
|
|
@@ -30,6 +32,8 @@ export const HOST_KEYS = Object.keys({
|
|
|
30
32
|
printing: 1,
|
|
31
33
|
tablesAsAppendices: 1,
|
|
32
34
|
noteStyle: 1,
|
|
35
|
+
contents: 1,
|
|
36
|
+
properties: 1,
|
|
33
37
|
writable: 1,
|
|
34
38
|
onToggleTask: 1,
|
|
35
39
|
keeps: 1,
|
|
@@ -70,6 +74,8 @@ export function resolveHost(host) {
|
|
|
70
74
|
printing: host.printing ?? false,
|
|
71
75
|
tablesAsAppendices: host.tablesAsAppendices ?? false,
|
|
72
76
|
noteStyle: cleanStyle(host.noteStyle),
|
|
77
|
+
contents: cleanContents(host.contents),
|
|
78
|
+
properties: cleanProperties(host.properties),
|
|
73
79
|
keeps: host.keeps ?? never,
|
|
74
80
|
suggest: host.suggest ?? null,
|
|
75
81
|
attach: host.attach ?? null,
|
package/dist/index.d.ts
CHANGED
|
@@ -13,4 +13,7 @@ export { readProperties, type NoteProperties, type PropertyEntry, type PropertyS
|
|
|
13
13
|
export { DELEGATED_TO_THE_BASE_PARSER, unclassified } from './delegated.js';
|
|
14
14
|
export type { TableAppendix } from './appendices.js';
|
|
15
15
|
export type { NoteStyle, StyleAlignment, StyleFont } from './note-style.js';
|
|
16
|
+
export { readContents, type ContentsLayer, type ContentsList, type ContentsListOptions, type ContentsMedium, type ContentsNoticeCode, type ContentsPlace, type ContentsProblem, type ContentsSettings, } from './contents.js';
|
|
17
|
+
export { slugOf } from './outline.js';
|
|
18
|
+
export { readPropertiesBlock, type PropertiesLayer, type PropertiesNoticeCode, type PropertiesProblem, type PropertiesSettings, } from './properties-block.js';
|
|
16
19
|
export { runTableQuery, type TableColumn, type TableColumnKind, type TablePage, type TableRequest, type TableRow, type TableRowView, type TableSchema, type TableSortKey, type TableValue, } from './table-block.js';
|
package/dist/index.js
CHANGED
|
@@ -9,4 +9,7 @@ export { codeRegions, fenceRegions, headingKey, remoteImageHosts, resolveWikilin
|
|
|
9
9
|
export { ordinalAt, taskBoxes, taskCheckedAt, toggleTaskAt } from './tasklist.js';
|
|
10
10
|
export { readProperties } from './properties.js';
|
|
11
11
|
export { DELEGATED_TO_THE_BASE_PARSER, unclassified } from './delegated.js';
|
|
12
|
+
export { readContents, } from './contents.js';
|
|
13
|
+
export { slugOf } from './outline.js';
|
|
14
|
+
export { readPropertiesBlock, } from './properties-block.js';
|
|
12
15
|
export { runTableQuery, } from './table-block.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the host says of several kept files at once (#175): `fileOf` for each name, an answer given
|
|
3
|
+
* at once kept at once and a promise kept once it settles, so a contents can tell an image from
|
|
4
|
+
* another file — which only a file's media type says (§5.8) — and name it by its description.
|
|
5
|
+
*/
|
|
6
|
+
import type { KeptFile, ResolvedHost } from './host.js';
|
|
7
|
+
/**
|
|
8
|
+
* Each name's file: the file, `null` for none or a host that cannot say, and `undefined` while the
|
|
9
|
+
* host's answer is on its way.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useKeptFiles(host: ResolvedHost, names: readonly string[]): ReadonlyMap<string, KeptFile | null | undefined>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the host says of several kept files at once (#175): `fileOf` for each name, an answer given
|
|
3
|
+
* at once kept at once and a promise kept once it settles, so a contents can tell an image from
|
|
4
|
+
* another file — which only a file's media type says (§5.8) — and name it by its description.
|
|
5
|
+
*/
|
|
6
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
7
|
+
function isThenable(value) {
|
|
8
|
+
return typeof value === 'object' && value !== null && typeof value.then === 'function';
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Each name's file: the file, `null` for none or a host that cannot say, and `undefined` while the
|
|
12
|
+
* host's answer is on its way.
|
|
13
|
+
*/
|
|
14
|
+
export function useKeptFiles(host, names) {
|
|
15
|
+
const key = names.join('\u0000');
|
|
16
|
+
const answers = useMemo(() => new Map(names.map((name) => [name, host.fileOf ? host.fileOf(name) : null])), [host.fileOf, key]);
|
|
17
|
+
const [settled, setSettled] = useState({ answers: null, files: new Map() });
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
let live = true;
|
|
20
|
+
const files = new Map();
|
|
21
|
+
const pending = [...answers].filter(([, answer]) => isThenable(answer));
|
|
22
|
+
if (pending.length === 0)
|
|
23
|
+
return;
|
|
24
|
+
for (const [name, answer] of pending) {
|
|
25
|
+
answer.then((file) => {
|
|
26
|
+
files.set(name, file);
|
|
27
|
+
if (live)
|
|
28
|
+
setSettled({ answers, files: new Map(files) });
|
|
29
|
+
}, () => {
|
|
30
|
+
files.set(name, null);
|
|
31
|
+
if (live)
|
|
32
|
+
setSettled({ answers, files: new Map(files) });
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return () => {
|
|
36
|
+
live = false;
|
|
37
|
+
};
|
|
38
|
+
}, [answers]);
|
|
39
|
+
return useMemo(() => {
|
|
40
|
+
const out = new Map();
|
|
41
|
+
for (const [name, answer] of answers) {
|
|
42
|
+
if (!isThenable(answer))
|
|
43
|
+
out.set(name, answer ?? null);
|
|
44
|
+
else
|
|
45
|
+
out.set(name, settled.answers === answers && settled.files.has(name) ? settled.files.get(name) : undefined);
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}, [answers, settled]);
|
|
49
|
+
}
|
package/dist/note-style.d.ts
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
*/
|
|
14
14
|
export type StyleFont = 'sans' | 'serif';
|
|
15
15
|
export type StyleAlignment = 'left' | 'center' | 'right' | 'justify';
|
|
16
|
+
/** How the headings are numbered (#174): not at all, or `1`, `1.1`, `1.2`. */
|
|
17
|
+
export type StyleNumbering = 'none' | 'decimal';
|
|
16
18
|
/** A style: each key left out is what the renderer draws with none. */
|
|
17
19
|
export interface NoteStyle {
|
|
18
20
|
/** The face of the text and the headings. */
|
|
@@ -23,10 +25,16 @@ export interface NoteStyle {
|
|
|
23
25
|
readonly text?: StyleAlignment;
|
|
24
26
|
/** The alignment of a table's cells whose column declares none, and of a `table` block's text columns. */
|
|
25
27
|
readonly tables?: StyleAlignment;
|
|
28
|
+
/**
|
|
29
|
+
* How the note's headings are numbered (#174): `decimal` numbers the outline 1, 1.1, 1.2, from its
|
|
30
|
+
* highest level; `none` numbers nothing, and a heading in a passage of `none` advances no counter.
|
|
31
|
+
*/
|
|
32
|
+
readonly numbering?: StyleNumbering;
|
|
26
33
|
}
|
|
27
34
|
export declare const STYLE_FONTS: readonly StyleFont[];
|
|
28
35
|
export declare const STYLE_ALIGNMENTS: readonly StyleAlignment[];
|
|
29
|
-
export declare const
|
|
36
|
+
export declare const STYLE_NUMBERINGS: readonly StyleNumbering[];
|
|
37
|
+
export declare const STYLE_KEYS: readonly ["font", "headings", "text", "tables", "numbering"];
|
|
30
38
|
export type StyleKey = (typeof STYLE_KEYS)[number];
|
|
31
39
|
/** Whether `value` is one `key` takes. */
|
|
32
40
|
export declare function takes(key: StyleKey, value: string): boolean;
|
package/dist/note-style.js
CHANGED
|
@@ -13,10 +13,12 @@
|
|
|
13
13
|
*/
|
|
14
14
|
export const STYLE_FONTS = ['sans', 'serif'];
|
|
15
15
|
export const STYLE_ALIGNMENTS = ['left', 'center', 'right', 'justify'];
|
|
16
|
-
export const
|
|
16
|
+
export const STYLE_NUMBERINGS = ['none', 'decimal'];
|
|
17
|
+
export const STYLE_KEYS = ['font', 'headings', 'text', 'tables', 'numbering'];
|
|
17
18
|
/** Whether `value` is one `key` takes. */
|
|
18
19
|
export function takes(key, value) {
|
|
19
|
-
|
|
20
|
+
const values = key === 'font' ? STYLE_FONTS : key === 'numbering' ? STYLE_NUMBERINGS : STYLE_ALIGNMENTS;
|
|
21
|
+
return values.includes(value);
|
|
20
22
|
}
|
|
21
23
|
/** A style with only the keys and values it may hold: a host's mistake is ignored, never drawn. */
|
|
22
24
|
export function cleanStyle(style) {
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The outline of a note and the ids of its headings (`SPEC.md` §3.3, §7.17, #173), apart from
|
|
3
|
+
* React: what a `contents` block lists, and what a link to `#section` lands on.
|
|
4
|
+
*
|
|
5
|
+
* Every heading is given the GitHub slug of its text, unique in the note, a repeat taking `-1`,
|
|
6
|
+
* `-2`: the note's own headings carry it as their id, prefixed so it never meets an id of the
|
|
7
|
+
* host's page, and every heading carries it as `data-heading`, which is what a link written inside
|
|
8
|
+
* an embed finds there, where no id is given. The outline is the headings at the top level of the
|
|
9
|
+
* note, outside quotes, callouts, lists and code: the ones `heading-first-level` examines.
|
|
10
|
+
*
|
|
11
|
+
* The note is drawn in runs an embed cuts, each parsed on its own; the slugs are counted across
|
|
12
|
+
* them here, once, over the same text and the same plugins the runs are drawn with, and each run
|
|
13
|
+
* is handed its own, in the order it meets its headings.
|
|
14
|
+
*/
|
|
15
|
+
import type { StyleNumbering } from './note-style.js';
|
|
16
|
+
/** A node of the tree as much as is read here. */
|
|
17
|
+
export interface OutlineNode {
|
|
18
|
+
type: string;
|
|
19
|
+
readonly depth?: number;
|
|
20
|
+
readonly value?: string;
|
|
21
|
+
readonly position?: {
|
|
22
|
+
readonly start?: {
|
|
23
|
+
readonly line?: number;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
readonly lang?: string | null;
|
|
27
|
+
readonly meta?: string | null;
|
|
28
|
+
readonly url?: string;
|
|
29
|
+
readonly alt?: string | null;
|
|
30
|
+
readonly title?: string | null;
|
|
31
|
+
children?: OutlineNode[];
|
|
32
|
+
data?: {
|
|
33
|
+
hProperties?: Record<string, unknown>;
|
|
34
|
+
} & Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
/** One heading of the outline: where a contents entry leads, and what it says. */
|
|
37
|
+
export interface OutlineHeading {
|
|
38
|
+
/** The id the heading carries on the page. */
|
|
39
|
+
readonly id: string;
|
|
40
|
+
readonly slug: string;
|
|
41
|
+
readonly level: number;
|
|
42
|
+
/** The heading's inlines, as drawn: links are their text, footnote references are gone. */
|
|
43
|
+
readonly content: readonly OutlineNode[];
|
|
44
|
+
/** Its number, as the style numbers it (#174), or `null`. */
|
|
45
|
+
readonly number: string | null;
|
|
46
|
+
/** The run it is in, and its line there, from 1. */
|
|
47
|
+
readonly run: number;
|
|
48
|
+
readonly line: number;
|
|
49
|
+
}
|
|
50
|
+
/** What a note's runs carry: each run's slugs and contents blocks, and the note's outline. */
|
|
51
|
+
export interface NoteOutline {
|
|
52
|
+
readonly runs: readonly OutlineRun[];
|
|
53
|
+
readonly headings: readonly OutlineHeading[];
|
|
54
|
+
/** The source of each `contents` block of the note, in order. */
|
|
55
|
+
readonly blocks: readonly string[];
|
|
56
|
+
/** The source of each `properties` block of the note, in order (#172). */
|
|
57
|
+
readonly propertiesBlocks: readonly string[];
|
|
58
|
+
/** Every block of either kind, in the order they are written, by kind and ordinal. */
|
|
59
|
+
readonly sequence: readonly {
|
|
60
|
+
readonly kind: 'contents' | 'properties';
|
|
61
|
+
readonly ordinal: number;
|
|
62
|
+
}[];
|
|
63
|
+
/** Each image alone in its paragraph, in order: what may be a figure once its file is known (#175). */
|
|
64
|
+
readonly figureCandidates: readonly FigureCandidate[];
|
|
65
|
+
/** Each table of the note, in order (#175). */
|
|
66
|
+
readonly tables: readonly TableItem[];
|
|
67
|
+
/** Each reference to a kept file, in order (#175). */
|
|
68
|
+
readonly kept: readonly KeptReference[];
|
|
69
|
+
}
|
|
70
|
+
export interface OutlineRun {
|
|
71
|
+
/** The slug of every heading of the run, in the order a walk of its tree meets them. */
|
|
72
|
+
readonly slugs: readonly string[];
|
|
73
|
+
/** The number of each of those headings, `null` for one the style does not number (#174). */
|
|
74
|
+
readonly numbers?: readonly (string | null)[];
|
|
75
|
+
/** The ordinal of its first `contents` block among the note's. */
|
|
76
|
+
readonly firstBlock: number;
|
|
77
|
+
/** The ordinal of its first `properties` block among the note's (#172). */
|
|
78
|
+
readonly firstProperties?: number;
|
|
79
|
+
/** What each image alone in its paragraph is (#175): a figure's number, or `null`. */
|
|
80
|
+
readonly figures?: readonly (number | null)[];
|
|
81
|
+
/** The number of each table of the run, in the order of the walk (#175). */
|
|
82
|
+
readonly tables?: readonly number[];
|
|
83
|
+
/** The id of each reference to a kept file, on the first one of its name only (#175). */
|
|
84
|
+
readonly attachments?: readonly (string | null)[];
|
|
85
|
+
/** Whether a `table` block is a table, as the plan counted the tables. */
|
|
86
|
+
readonly tableBlocks?: boolean;
|
|
87
|
+
}
|
|
88
|
+
/** An image alone in its paragraph (#175): remote, or a file the notebook keeps. */
|
|
89
|
+
export interface FigureCandidate {
|
|
90
|
+
readonly run: number;
|
|
91
|
+
readonly kept: boolean;
|
|
92
|
+
/** The kept file's name, or the last segment of a remote image's address. */
|
|
93
|
+
readonly name: string;
|
|
94
|
+
/** The title written after its destination, ``, or `null`. */
|
|
95
|
+
readonly title: string | null;
|
|
96
|
+
/** Whether it is written as an image, ``, or as an embed, `![[…]]`. */
|
|
97
|
+
readonly form: 'image' | 'embed';
|
|
98
|
+
}
|
|
99
|
+
/** A table of the note (#175): a Markdown table and its `Table:` caption, or a `table` block. */
|
|
100
|
+
export interface TableItem {
|
|
101
|
+
readonly run: number;
|
|
102
|
+
readonly kind: 'markdown' | 'block';
|
|
103
|
+
/** A Markdown table's caption inlines, keyword left out, or `null`. */
|
|
104
|
+
readonly caption: readonly OutlineNode[] | null;
|
|
105
|
+
/** A block's `title`, else the table it names, or `null`. */
|
|
106
|
+
readonly title: string | null;
|
|
107
|
+
}
|
|
108
|
+
/** A reference to a file the notebook keeps (#175): an embed or an image whose destination names no host. */
|
|
109
|
+
export interface KeptReference {
|
|
110
|
+
readonly run: number;
|
|
111
|
+
readonly name: string;
|
|
112
|
+
readonly title: string | null;
|
|
113
|
+
}
|
|
114
|
+
/** The kept file an attachment link names, as `resolveWikilinks` writes it: `attachment:name|size`. */
|
|
115
|
+
export declare function attachmentName(url: string): string | null;
|
|
116
|
+
/** The kept file or remote image a node references, or `null`. */
|
|
117
|
+
export declare function referenceOf(node: OutlineNode): {
|
|
118
|
+
kept: boolean;
|
|
119
|
+
name: string;
|
|
120
|
+
title: string | null;
|
|
121
|
+
form: 'image' | 'embed';
|
|
122
|
+
} | null;
|
|
123
|
+
/** The one image or file a paragraph holds and nothing else, which makes it a figure's candidate (#175). */
|
|
124
|
+
export declare function aloneIn(paragraph: OutlineNode): OutlineNode | null;
|
|
125
|
+
/** Whether a node is a table the note draws: a Markdown table, or a `table` block where tables are reached. */
|
|
126
|
+
export declare function isTableNode(node: OutlineNode, blocks: boolean): boolean;
|
|
127
|
+
/** The paragraph right after a table that captions it (`Table: …`), or `null`. */
|
|
128
|
+
export declare function captionAfter(node: OutlineNode, parent: OutlineNode | null): OutlineNode | null;
|
|
129
|
+
/** A caption's inlines without its keyword. */
|
|
130
|
+
export declare function captionContent(paragraph: OutlineNode): OutlineNode[];
|
|
131
|
+
/** The id a heading of the note carries on the page. */
|
|
132
|
+
export declare function headingId(slug: string): string;
|
|
133
|
+
/**
|
|
134
|
+
* GitHub's slug of a heading's text: lower case, letters with their marks, digits, `-` and `_`
|
|
135
|
+
* kept, every space a `-`, anything else dropped.
|
|
136
|
+
*/
|
|
137
|
+
export declare function slugOf(text: string): string;
|
|
138
|
+
/** Hands out slugs, a repeat taking `-1`, `-2`, as GitHub's slugger does. */
|
|
139
|
+
export declare class Slugger {
|
|
140
|
+
private readonly seen;
|
|
141
|
+
slug(text: string): string;
|
|
142
|
+
}
|
|
143
|
+
/** The text of a node, as a heading's slug reads it. */
|
|
144
|
+
export declare function textOf(node: OutlineNode): string;
|
|
145
|
+
/** Visits every node of a tree, parents before their children, as remark does. */
|
|
146
|
+
export declare function walkTree(node: OutlineNode, visit: (node: OutlineNode, parent: OutlineNode | null) => void, parent?: OutlineNode | null): void;
|
|
147
|
+
/** A run's tree, as the page parses and transforms it. */
|
|
148
|
+
export declare function parseRun(text: string): OutlineNode;
|
|
149
|
+
/**
|
|
150
|
+
* The numbers of the headings of an outline (#174): `decimal` ones counted 1, 1.1, 1.2 from the
|
|
151
|
+
* highest level they reach; one the style leaves at `none` takes no number and advances no counter.
|
|
152
|
+
*/
|
|
153
|
+
export declare function numberHeadings(headings: readonly {
|
|
154
|
+
readonly level: number;
|
|
155
|
+
readonly numbering: StyleNumbering;
|
|
156
|
+
}[]): (string | null)[];
|
|
157
|
+
/**
|
|
158
|
+
* The outline of a note drawn in these runs, the text of each as it is drawn. `numberingAt` says
|
|
159
|
+
* how the heading at a line of a run is numbered, as the style that reaches it says (#174).
|
|
160
|
+
*/
|
|
161
|
+
export declare function planOutline(runs: readonly string[], numberingAt?: (run: number, line: number) => StyleNumbering,
|
|
162
|
+
/** Whether a `table` block is drawn as a table, which it is where the host reaches tables. */
|
|
163
|
+
tableBlocks?: boolean): NoteOutline;
|
|
164
|
+
/** What a kept file is, as far as a figure is concerned: an image, something else, or not known yet. */
|
|
165
|
+
export type FileKind = 'image' | 'other' | 'pending';
|
|
166
|
+
export interface FigureItem {
|
|
167
|
+
readonly id: string;
|
|
168
|
+
readonly number: number;
|
|
169
|
+
readonly kept: boolean;
|
|
170
|
+
readonly name: string;
|
|
171
|
+
readonly title: string | null;
|
|
172
|
+
}
|
|
173
|
+
export interface TableEntry {
|
|
174
|
+
readonly id: string;
|
|
175
|
+
readonly number: number;
|
|
176
|
+
readonly kind: 'markdown' | 'block';
|
|
177
|
+
readonly caption: readonly OutlineNode[] | null;
|
|
178
|
+
readonly title: string | null;
|
|
179
|
+
}
|
|
180
|
+
export interface AttachmentItem {
|
|
181
|
+
readonly id: string;
|
|
182
|
+
readonly name: string;
|
|
183
|
+
readonly title: string | null;
|
|
184
|
+
}
|
|
185
|
+
/** A note's figures, tables and attachments, numbered, and what each run marks of them (#175). */
|
|
186
|
+
export interface NoteItems {
|
|
187
|
+
readonly figures: readonly FigureItem[];
|
|
188
|
+
readonly tables: readonly TableEntry[];
|
|
189
|
+
readonly attachments: readonly AttachmentItem[];
|
|
190
|
+
readonly runs: readonly {
|
|
191
|
+
readonly figures: readonly (number | null)[];
|
|
192
|
+
readonly tables: readonly number[];
|
|
193
|
+
readonly attachments: readonly (string | null)[];
|
|
194
|
+
}[];
|
|
195
|
+
/** Whether a candidate's file is not known yet, so the figures may still change. */
|
|
196
|
+
readonly pending: boolean;
|
|
197
|
+
}
|
|
198
|
+
export declare const figureId: (number: number) => string;
|
|
199
|
+
export declare const tableId: (number: number) => string;
|
|
200
|
+
export declare const attachmentId: (number: number) => string;
|
|
201
|
+
/**
|
|
202
|
+
* Numbers a note's figures, tables and attachments (#175). An image alone in its paragraph is a
|
|
203
|
+
* figure when it is remote, or when the file it names is an image, which only its media type says
|
|
204
|
+
* (§5.8); an attachment is listed once, at the first reference to its name.
|
|
205
|
+
*/
|
|
206
|
+
export declare function planItems(outline: NoteOutline, kindOf: (name: string, form: 'image' | 'embed') => FileKind, keeps?: (name: string) => boolean): NoteItems;
|
|
207
|
+
/**
|
|
208
|
+
* The remark plugin that gives the headings of a run their ids and numbers its `contents` blocks.
|
|
209
|
+
* Handed the run's slugs, it gives each heading its id and its slug; with none it counts its own,
|
|
210
|
+
* for a note drawn in one run, and with `ids: false` — inside an embed — gives the slug alone.
|
|
211
|
+
*/
|
|
212
|
+
export declare function remarkOutline(options?: {
|
|
213
|
+
slugs?: readonly string[] | null;
|
|
214
|
+
numbers?: readonly (string | null)[] | null;
|
|
215
|
+
ids?: boolean;
|
|
216
|
+
firstBlock?: number;
|
|
217
|
+
/** The ordinal of the run's first `properties` block (#172). */
|
|
218
|
+
firstProperties?: number;
|
|
219
|
+
/** Each image alone in its paragraph: its figure's number, or `null` (#175). */
|
|
220
|
+
figures?: readonly (number | null)[] | null;
|
|
221
|
+
/** Each table's number (#175). */
|
|
222
|
+
tables?: readonly number[] | null;
|
|
223
|
+
/** Each kept file's reference: the id of its first, or `null` (#175). */
|
|
224
|
+
attachments?: readonly (string | null)[] | null;
|
|
225
|
+
/** Whether a `table` block is a table, as the plan counted them. */
|
|
226
|
+
tableBlocks?: boolean;
|
|
227
|
+
}): (tree: OutlineNode) => void;
|