@memorysmithapp/markdown-renderer 0.12.0 → 0.13.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 +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/NoteBody.js
CHANGED
|
@@ -9,7 +9,8 @@ import { Markdown } from './Markdown.js';
|
|
|
9
9
|
import { readingPlugins } from './reading.js';
|
|
10
10
|
import { bodyStart, hideComments, remoteImageHosts, resolveWikilinks } from './source.js';
|
|
11
11
|
import { readProperties } from './properties.js';
|
|
12
|
-
import {
|
|
12
|
+
import { PropertiesAt, PropertiesContext, PropertiesTop } from './PropertiesBlock.js';
|
|
13
|
+
import { readPropertiesBlock, resolvePropertiesBlock, resolvePropertiesHost } from './properties-block.js';
|
|
13
14
|
import { useTaskSaves } from './task-saves.js';
|
|
14
15
|
import { taskBoxes } from './tasklist.js';
|
|
15
16
|
import { justifies } from './note-style.js';
|
|
@@ -20,6 +21,10 @@ import { appendixId, planAppendices } from './appendices.js';
|
|
|
20
21
|
import { findStyleBlocks, rangesFor, styleAt, blockAttributes } from './style-block.js';
|
|
21
22
|
import { embedsFile } from './embed-target.js';
|
|
22
23
|
import { wikilinkAddress } from './wikilink-address.js';
|
|
24
|
+
import { planItems, planOutline } from './outline.js';
|
|
25
|
+
import { useKeptFiles } from './kept-files.js';
|
|
26
|
+
import { readContents, resolveBlock, resolveHost as resolveHostContents } from './contents.js';
|
|
27
|
+
import { ContentsAt, ContentsContext, listedIn } from './ContentsBlock.js';
|
|
23
28
|
/** The editor, loaded the first time a note is edited, so a host that only draws never loads it. */
|
|
24
29
|
const NoteEditor = lazy(() => import('./edit/NoteEditor.js').then((module) => ({ default: module.NoteEditor })));
|
|
25
30
|
/** The switch between reading and editing, drawn by the theme's slot or as the default theme draws it. */
|
|
@@ -166,7 +171,6 @@ function NoteView({ markdown, writable = false, onToggleTask, corner, switched =
|
|
|
166
171
|
const appendices = useMemo(() => (appendixRuns ? planAppendices(runs, blocks) : null),
|
|
167
172
|
// The runs and whether a `table` block is a table are the whole input.
|
|
168
173
|
[appendixRuns, blocks, runs.join('\u0000')]);
|
|
169
|
-
let run = 0;
|
|
170
174
|
// The line of the body each segment starts on: a run keeps every line of its text, and an embed
|
|
171
175
|
// stands within one. Where that does not add up, no block is drawn rather than a wrong one.
|
|
172
176
|
const startLines = [];
|
|
@@ -177,32 +181,107 @@ function NoteView({ markdown, writable = false, onToggleTask, corner, switched =
|
|
|
177
181
|
line += segment.text.split('\n').length - 1;
|
|
178
182
|
}
|
|
179
183
|
const lined = styled.blocks.length > 0 && line === styled.text.split('\n').length;
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
184
|
+
// The outline of the note and its `contents` blocks (§7.17, #173): the slugs of its headings
|
|
185
|
+
// counted across the runs, over the text each is drawn with, and what each block draws in each
|
|
186
|
+
// medium over the host's settings; with no block, what the host's draw where they say.
|
|
187
|
+
const drawnRuns = runs.map((text, index) => footnotes?.runs[index]?.text ?? text);
|
|
188
|
+
// How the heading at a line of a run is numbered (#174): the style block that reaches its line,
|
|
189
|
+
// else the notebook's style.
|
|
190
|
+
const runStarts = segments.flatMap((segment, index) => ('rendered' in segment ? [startLines[index]] : []));
|
|
191
|
+
const numbering = resolved.noteStyle.numbering ?? 'none';
|
|
192
|
+
const numberingAt = (run, line) => (lined && runStarts[run] !== undefined ? styleAt(styled.blocks, runStarts[run] + line - 1).numbering : undefined) ?? numbering;
|
|
193
|
+
const tableBlocks = resolved.queryTable !== null;
|
|
194
|
+
const outline = useMemo(() => planOutline(drawnRuns, numberingAt, tableBlocks), [drawnRuns.join('\u0000'), numbering, JSON.stringify(styled.blocks), tableBlocks]);
|
|
195
|
+
// The note's figures, tables and attachments (#175): a kept file is a figure when its media type
|
|
196
|
+
// is an image's, which only the host says, so what it says of each file is asked first.
|
|
197
|
+
const keptNames = useMemo(() => [...new Set(outline.kept.map((reference) => reference.name))].filter((name) => resolved.keeps(name)), [outline, resolved.keeps]);
|
|
198
|
+
const files = useKeptFiles(resolved, keptNames);
|
|
199
|
+
const items = useMemo(() => {
|
|
200
|
+
const kindOf = (name, form) => {
|
|
201
|
+
if (!resolved.fileOf)
|
|
202
|
+
return form === 'image' ? 'image' : 'other';
|
|
203
|
+
const file = files.get(name);
|
|
204
|
+
if (file === undefined)
|
|
205
|
+
return 'pending';
|
|
206
|
+
return file?.mimeType.startsWith('image/') ? 'image' : 'other';
|
|
207
|
+
};
|
|
208
|
+
return planItems(outline, kindOf, resolved.keeps);
|
|
209
|
+
}, [outline, files, resolved.fileOf, resolved.keeps]);
|
|
210
|
+
const contentsScope = useMemo(() => {
|
|
211
|
+
const blocks = outline.blocks.map((source) => {
|
|
212
|
+
const { settings } = readContents(source);
|
|
213
|
+
return { screen: resolveBlock(settings, resolved.contents, 'screen'), print: resolveBlock(settings, resolved.contents, 'print') };
|
|
214
|
+
});
|
|
215
|
+
const host = blocks.length === 0 ? [{ screen: resolveHostContents(resolved.contents, 'screen'), print: resolveHostContents(resolved.contents, 'print') }] : [];
|
|
216
|
+
const placed = [...blocks, ...host];
|
|
217
|
+
return {
|
|
218
|
+
scope: {
|
|
219
|
+
kind: 'note',
|
|
220
|
+
headings: outline.headings,
|
|
221
|
+
items,
|
|
222
|
+
files,
|
|
223
|
+
blocks,
|
|
224
|
+
listed: listedIn(placed),
|
|
225
|
+
printing: resolved.printing,
|
|
226
|
+
appendices: Boolean(appendices),
|
|
227
|
+
},
|
|
228
|
+
placed,
|
|
229
|
+
};
|
|
230
|
+
}, [outline, items, files, resolved.contents, resolved.printing, appendices]);
|
|
231
|
+
// What each `properties` block draws in each medium, over the host's settings, and with none, what
|
|
232
|
+
// the host's draw: the entries at the top, as always, unless they say otherwise (#172).
|
|
233
|
+
const propertiesScope = useMemo(() => {
|
|
234
|
+
const blocks = outline.propertiesBlocks.map((source) => {
|
|
235
|
+
const { settings } = readPropertiesBlock(source);
|
|
236
|
+
return { screen: resolvePropertiesBlock(settings, resolved.properties, 'screen'), print: resolvePropertiesBlock(settings, resolved.properties, 'print') };
|
|
237
|
+
});
|
|
238
|
+
const host = blocks.length === 0 ? [{ screen: resolvePropertiesHost(resolved.properties, 'screen'), print: resolvePropertiesHost(resolved.properties, 'print') }] : [];
|
|
239
|
+
return { scope: { kind: 'note', properties, blocks, printing: resolved.printing }, placed: [...blocks, ...host] };
|
|
240
|
+
}, [outline, properties, resolved.properties, resolved.printing]);
|
|
241
|
+
// A run marks the figures, tables and attachments a list leads to, and only those: a note with no
|
|
242
|
+
// such list draws its images, tables and files exactly as before (#175).
|
|
243
|
+
const marked = contentsScope.scope.kind === 'note' ? contentsScope.scope.listed : null;
|
|
244
|
+
const any = (kind) => Boolean(marked && (marked[kind].screen || marked[kind].print));
|
|
245
|
+
const markedOf = (index) => {
|
|
246
|
+
const plan = items.runs[index];
|
|
247
|
+
return {
|
|
248
|
+
...(plan && any('figures') ? { figures: plan.figures } : {}),
|
|
249
|
+
...(plan && any('tables') ? { tables: plan.tables } : {}),
|
|
250
|
+
...(plan && any('attachments') ? { attachments: plan.attachments } : {}),
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
const placed = (place) => contentsScope.placed.map((plans, index) => _jsx(ContentsAt, { plans: plans, place: place }, `${place}-${index}`));
|
|
254
|
+
let run = 0;
|
|
255
|
+
return (_jsx(HostProvider, { value: resolved, children: _jsx(ContentsContext.Provider, { value: contentsScope.scope, children: _jsx(PropertiesContext.Provider, { value: propertiesScope.scope, children: _jsxs("div", { className: `markdown markdown-theme-${resolved.theme.name}${corner ? ' has-note-corner' : ''}${switched ? ' has-mode-switch' : ''}${corner && buttons === 'responsive' ? ' has-responsive-buttons' : ''}`, "data-theme": resolved.scheme, style: rootStyle(resolved.theme, resolved.scheme, resolved.noteStyle),
|
|
256
|
+
// Justified text hyphenates in the reader's language, which the browser has to be told (#164).
|
|
257
|
+
lang: justifies(resolved.noteStyle) ? resolved.strings.locale : undefined, children: [corner, _jsx(PropertiesTop, { properties: properties, plans: propertiesScope.placed, printing: resolved.printing }), placed('start'), segments.map((segment, index) => {
|
|
258
|
+
if (!('rendered' in segment)) {
|
|
259
|
+
const embed = _jsx(Transclusion, { target: segment.target, anchor: segment.anchor, source: segment.source }, index);
|
|
260
|
+
// An embed a style block holds is drawn in that block's style.
|
|
261
|
+
const style = lined ? styleAt(styled.blocks, startLines[index]) : {};
|
|
262
|
+
if (Object.keys(style).length === 0)
|
|
263
|
+
return embed;
|
|
264
|
+
const { className, style: css, ...attributes } = blockAttributes(style, resolved.strings.locale);
|
|
265
|
+
// The attributes as the page writes them: `dataText` is `data-text`.
|
|
266
|
+
const written = Object.fromEntries(Object.entries(attributes).map(([name, value]) => [name.replace(/^data([A-Z])/, (_, first) => `data-${first.toLowerCase()}`), value]));
|
|
267
|
+
return (_jsx("div", { className: className.join(' '), style: cssObject(css), ...written, children: embed }, index));
|
|
268
|
+
}
|
|
269
|
+
const base = seen;
|
|
270
|
+
seen += taskBoxes(segment.rendered).length;
|
|
271
|
+
// The run's place among the runs, counted here: `footnotes?.runs[run++]` counted nothing
|
|
272
|
+
// when the note had no footnotes, and every run then took the first one's place.
|
|
273
|
+
const current = run++;
|
|
274
|
+
const first = appendices?.first[current];
|
|
275
|
+
const runOutline = outline.runs[current];
|
|
276
|
+
const planned = footnotes?.runs[current];
|
|
277
|
+
return (_jsx(Markdown, {
|
|
278
|
+
// The text the ordinal is counted over, stated rather than left to
|
|
279
|
+
// a default: it is the one the parser reports offsets into, and
|
|
280
|
+
// `mappable` above is what makes it safe to write back through.
|
|
281
|
+
// A planned run is the same text with definitions appended after
|
|
282
|
+
// it, so every box keeps the offset it had.
|
|
283
|
+
source: planned?.text ?? segment.rendered, onToggleTask: onToggleTask && ((ordinal, checked) => saves.toggle(base + ordinal, checked)), taskSave: (ordinal) => saves.stateOf(base + ordinal), writable: writable && mappable, ...(planned ? { footnotes: { refs: planned.refs } } : {}), ...(appendices && first !== undefined ? { appendices: { first, appendices: appendices.appendices } } : {}), styles: lined ? rangesFor(styled.blocks, startLines[index], startLines[index] + segment.text.split('\n').length - 1) : NO_STYLES, ...(runOutline ? { outline: { ...runOutline, ...markedOf(current), tableBlocks } } : {}), children: planned?.text ?? segment.rendered }, index));
|
|
284
|
+
}), footnotes && (_jsx(Markdown, { footnotes: "section", outline: { slugs: [], firstBlock: outline.blocks.length }, children: footnotes.section })), placed('end'), propertiesScope.placed.map((plans, index) => (_jsx(PropertiesAt, { plans: plans, place: "end" }, `properties-end-${index}`))), appendices && appendices.appendices.length > 0 && (_jsx("div", { className: "table-appendices", children: appendices.appendices.map((appendix) => (_jsxs("section", { id: appendixId(appendix.number), className: "table-appendix", "data-table-kind": appendix.table === null ? 'markdown' : 'block', children: [_jsx("h2", { className: "table-appendix-title", children: resolved.strings.tableAppendix(appendix) }), _jsx(Markdown, { children: appendix.source })] }, appendix.number))) })), hosts.length > 0 && _jsx("p", { className: "remote-notice", children: resolved.strings.remoteImages(hosts) }), writable && onToggleTask && (_jsx("p", { className: "visually-hidden", role: "status", "aria-live": "polite", children: saves.announcement && resolved.strings[saves.announcement] }))] }) }) }) }));
|
|
206
285
|
}
|
|
207
286
|
/** A run with no style block: given, so it does not look for one in text whose fences are gone. */
|
|
208
287
|
const NO_STYLES = [];
|
|
@@ -11,13 +11,64 @@
|
|
|
11
11
|
* chips, a boolean the reader's *Yes* or *No*, a date in the reader's locale,
|
|
12
12
|
* and what was typed stays in the title of each.
|
|
13
13
|
*/
|
|
14
|
-
import type
|
|
15
|
-
import { type NoteProperties } from './properties.js';
|
|
14
|
+
import { type ReactNode } from 'react';
|
|
15
|
+
import { type NoteProperties, type PropertyEntry } from './properties.js';
|
|
16
|
+
import type { PropertiesPlan } from './properties-block.js';
|
|
17
|
+
import type { ContentsMedium } from './contents.js';
|
|
16
18
|
/**
|
|
17
19
|
* Text as it was typed, with each parameter it writes drawn as one (§7.14): a value of the
|
|
18
20
|
* frontmatter, or the name of a note, in a model.
|
|
19
21
|
*/
|
|
20
22
|
export declare function useParameters(): (text: string) => ReactNode;
|
|
21
|
-
|
|
23
|
+
/** The entries a plan draws: the keys it names, in its order, else every entry, the reserved first. */
|
|
24
|
+
export declare function chosenEntries(entries: readonly PropertyEntry[], keys: readonly string[] | null): PropertyEntry[];
|
|
25
|
+
/**
|
|
26
|
+
* The note's properties as the default theme draws them, or through the theme's `properties` slot:
|
|
27
|
+
* the name as the title, where `withName` says, and the chosen entries in a block that folds (#172).
|
|
28
|
+
*/
|
|
29
|
+
export declare function Properties({ properties, plan, withName, medium, }: {
|
|
22
30
|
properties: NoteProperties;
|
|
31
|
+
/** Which keys, under which title, folded or open; `null` draws every key, as before. */
|
|
32
|
+
plan?: PropertiesPlan | null;
|
|
33
|
+
/** Whether the name is drawn too: only at the top. */
|
|
34
|
+
withName?: boolean;
|
|
35
|
+
/** The one medium this drawing is for, marked so the stylesheet shows it only there. */
|
|
36
|
+
medium?: ContentsMedium | null;
|
|
23
37
|
}): string | number | bigint | boolean | import("react").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined;
|
|
38
|
+
/** What each `properties` block of a note draws, by medium, or the host's for a note with none. */
|
|
39
|
+
export interface PropertiesPlans {
|
|
40
|
+
readonly screen: PropertiesPlan | null;
|
|
41
|
+
readonly print: PropertiesPlan | null;
|
|
42
|
+
}
|
|
43
|
+
/** The note whose properties are drawn (#172): its properties and what each block draws. */
|
|
44
|
+
export type PropertiesScope = {
|
|
45
|
+
readonly kind: 'note';
|
|
46
|
+
readonly properties: NoteProperties;
|
|
47
|
+
readonly blocks: readonly PropertiesPlans[];
|
|
48
|
+
readonly printing: boolean;
|
|
49
|
+
} | {
|
|
50
|
+
readonly kind: 'embedded';
|
|
51
|
+
};
|
|
52
|
+
export declare const PropertiesContext: import("react").Context<PropertiesScope | null>;
|
|
53
|
+
/**
|
|
54
|
+
* The top of a note (#172): its name, always, and the entries the plans place at the start, in
|
|
55
|
+
* one drawing with the name where a single one serves both media, as a note was always drawn.
|
|
56
|
+
*/
|
|
57
|
+
export declare function PropertiesTop({ properties, plans, printing }: {
|
|
58
|
+
properties: NoteProperties;
|
|
59
|
+
plans: readonly PropertiesPlans[];
|
|
60
|
+
printing: boolean;
|
|
61
|
+
}): import("react").JSX.Element;
|
|
62
|
+
/** The entries the plans place at the end of the note, or where a block is written (`null`). */
|
|
63
|
+
export declare function PropertiesAt({ plans, place }: {
|
|
64
|
+
plans: PropertiesPlans;
|
|
65
|
+
place: 'end' | null;
|
|
66
|
+
}): import("react").JSX.Element | null;
|
|
67
|
+
/**
|
|
68
|
+
* A `properties` block where it is written (`SPEC.md` §7.18, #172): the entries it draws here in
|
|
69
|
+
* each medium, nothing inside an embed, and its code block where no note is known.
|
|
70
|
+
*/
|
|
71
|
+
export declare function PropertiesBlockAt({ ordinal, fallback }: {
|
|
72
|
+
ordinal: number | null;
|
|
73
|
+
fallback: ReactNode;
|
|
74
|
+
}): import("react").JSX.Element | null;
|
package/dist/PropertiesBlock.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The frontmatter of a note, drawn above its body — or not — as the theme decides.
|
|
4
|
+
*
|
|
5
|
+
* The renderer reads it (`readProperties`) and hands it to the theme's
|
|
6
|
+
* `properties` slot. With none, the default theme draws what MemorySmith's note
|
|
7
|
+
* page draws above the body (*observed* at `4b67c7e`): the name as the note's
|
|
8
|
+
* title, always — *Unnamed note* when it has none — and the properties in a
|
|
9
|
+
* block that folds, under a rule and never in a card. The reserved keys come
|
|
10
|
+
* first, in the order of the specification, then the notebook's own in the
|
|
11
|
+
* order written; each key wears the icon of the shape of its value; a list is
|
|
12
|
+
* chips, a boolean the reader's *Yes* or *No*, a date in the reader's locale,
|
|
13
|
+
* and what was typed stays in the title of each.
|
|
14
|
+
*/
|
|
15
|
+
import { createContext, useContext } from 'react';
|
|
2
16
|
import { useHost } from './host.js';
|
|
3
17
|
import { MarkdownAnchor } from './Markdown.js';
|
|
4
18
|
import { hasParameterReference, splitParameters } from './parameters.js';
|
|
@@ -112,13 +126,85 @@ function ordered(entries) {
|
|
|
112
126
|
.sort((left, right) => rank(left.entry.key) - rank(right.entry.key) || left.index - right.index)
|
|
113
127
|
.map(({ entry }) => entry);
|
|
114
128
|
}
|
|
115
|
-
|
|
129
|
+
/** The entries a plan draws: the keys it names, in its order, else every entry, the reserved first. */
|
|
130
|
+
export function chosenEntries(entries, keys) {
|
|
131
|
+
if (keys === null)
|
|
132
|
+
return ordered(entries);
|
|
133
|
+
// A key the note does not have is drawn as nothing and raises nothing (#172).
|
|
134
|
+
return keys.flatMap((key) => entries.filter((entry) => entry.key === key && entry.shape !== 'empty'));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The note's properties as the default theme draws them, or through the theme's `properties` slot:
|
|
138
|
+
* the name as the title, where `withName` says, and the chosen entries in a block that folds (#172).
|
|
139
|
+
*/
|
|
140
|
+
export function Properties({ properties, plan = null, withName = true, medium = null, }) {
|
|
116
141
|
const { strings } = useHost();
|
|
117
142
|
const slot = useSlot('properties');
|
|
118
143
|
const value = useValue();
|
|
119
144
|
const drawn = useParameters();
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
145
|
+
const shown = plan === null ? ordered(properties.entries) : chosenEntries(properties.entries, plan.keys);
|
|
146
|
+
if (slot) {
|
|
147
|
+
// A theme that draws nothing still wins: a host that shows the properties elsewhere is never made to draw them twice.
|
|
148
|
+
const slotted = drawSlot(slot, {
|
|
149
|
+
name: withName ? properties.name : null,
|
|
150
|
+
entries: plan === null || plan.keys === null ? properties.entries : shown,
|
|
151
|
+
value,
|
|
152
|
+
part: withName ? (plan === null || shown.length > 0 ? 'whole' : 'name') : 'entries',
|
|
153
|
+
...(plan?.title ? { title: plan.title } : {}),
|
|
154
|
+
...(plan?.fold ? { fold: plan.fold } : {}),
|
|
155
|
+
});
|
|
156
|
+
return medium ? _jsx("div", { "data-media": medium, children: slotted }) : slotted;
|
|
157
|
+
}
|
|
158
|
+
const entries = shown.length > 0 && (_jsxs("details", { className: "properties-box", open: plan?.fold !== 'closed', "data-media": medium ?? undefined, children: [_jsx("summary", { children: plan?.title ?? strings.properties }), _jsx("div", { className: "metadata-container", children: shown.map((entry, index) => (_jsxs("div", { className: "metadata-property", "data-property-type": iconType(entry), children: [_jsx("span", { className: "metadata-property-key", children: entry.key }), _jsx("span", { className: "metadata-property-value", children: _jsx(PropertyValue, { entry: entry, value: value }) })] }, index))) })] }));
|
|
159
|
+
return (_jsxs(_Fragment, { children: [withName && (_jsx("h1", { className: properties.name === null ? 'note-title note-unnamed' : 'note-title', children: properties.name === null ? strings.unnamedNote : drawn(properties.name) })), entries] }));
|
|
160
|
+
}
|
|
161
|
+
export const PropertiesContext = createContext(null);
|
|
162
|
+
const samePlan = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
163
|
+
/** The draws of plans that resolve to `place`: one for both media where they agree, else one for each. */
|
|
164
|
+
function drawsAt(plans, place, printing) {
|
|
165
|
+
const at = (plan) => (plan && plan.place === place ? plan : null);
|
|
166
|
+
if (printing) {
|
|
167
|
+
const print = at(plans.print);
|
|
168
|
+
return print ? [{ plan: print, medium: null }] : [];
|
|
169
|
+
}
|
|
170
|
+
const screen = at(plans.screen);
|
|
171
|
+
const print = at(plans.print);
|
|
172
|
+
if (screen && print && samePlan(screen, print))
|
|
173
|
+
return [{ plan: screen, medium: null }];
|
|
174
|
+
return [...(screen ? [{ plan: screen, medium: 'screen' }] : []), ...(print ? [{ plan: print, medium: 'print' }] : [])];
|
|
175
|
+
}
|
|
176
|
+
/** The plan that draws the name and nothing else, where the entries are drawn elsewhere. */
|
|
177
|
+
const NAME_ONLY = { keys: [], title: null, fold: null, place: 'start' };
|
|
178
|
+
/**
|
|
179
|
+
* The top of a note (#172): its name, always, and the entries the plans place at the start, in
|
|
180
|
+
* one drawing with the name where a single one serves both media, as a note was always drawn.
|
|
181
|
+
*/
|
|
182
|
+
export function PropertiesTop({ properties, plans, printing }) {
|
|
183
|
+
const draws = plans.flatMap((each) => drawsAt(each, 'start', printing));
|
|
184
|
+
const first = draws[0];
|
|
185
|
+
if (draws.length === 1 && first && first.medium === null)
|
|
186
|
+
return _jsx(Properties, { properties: properties, plan: first.plan });
|
|
187
|
+
return (_jsxs(_Fragment, { children: [_jsx(Properties, { properties: properties, plan: NAME_ONLY }), draws.map((draw, index) => (_jsx(Properties, { properties: properties, plan: draw.plan, withName: false, medium: draw.medium }, index)))] }));
|
|
188
|
+
}
|
|
189
|
+
/** The entries the plans place at the end of the note, or where a block is written (`null`). */
|
|
190
|
+
export function PropertiesAt({ plans, place }) {
|
|
191
|
+
const scope = useContext(PropertiesContext);
|
|
192
|
+
if (scope === null || scope.kind !== 'note')
|
|
193
|
+
return null;
|
|
194
|
+
return (_jsx(_Fragment, { children: drawsAt(plans, place, scope.printing).map((draw, index) => (_jsx(Properties, { properties: scope.properties, plan: draw.plan, withName: false, medium: draw.medium }, index))) }));
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* A `properties` block where it is written (`SPEC.md` §7.18, #172): the entries it draws here in
|
|
198
|
+
* each medium, nothing inside an embed, and its code block where no note is known.
|
|
199
|
+
*/
|
|
200
|
+
export function PropertiesBlockAt({ ordinal, fallback }) {
|
|
201
|
+
const scope = useContext(PropertiesContext);
|
|
202
|
+
if (scope === null)
|
|
203
|
+
return _jsx(_Fragment, { children: fallback });
|
|
204
|
+
if (scope.kind === 'embedded')
|
|
205
|
+
return null;
|
|
206
|
+
const plans = ordinal === null ? undefined : scope.blocks[ordinal];
|
|
207
|
+
if (!plans)
|
|
208
|
+
return _jsx(_Fragment, { children: fallback });
|
|
209
|
+
return _jsx(PropertiesAt, { plans: plans, place: null });
|
|
124
210
|
}
|
package/dist/Transclusion.js
CHANGED
|
@@ -7,6 +7,8 @@ import { bodyStart, hideComments, resolveWikilinks } from './source.js';
|
|
|
7
7
|
import { blockOf, demoteEmbeds, isBlockAnchor, sectionOf } from './embeds.js';
|
|
8
8
|
import { wikilinkAddress } from './wikilink-address.js';
|
|
9
9
|
import { drawing, drawnNote, embedsFile, embedTarget } from './embed-target.js';
|
|
10
|
+
import { ContentsContext, EMBEDDED } from './ContentsBlock.js';
|
|
11
|
+
import { PropertiesContext } from './PropertiesBlock.js';
|
|
10
12
|
/** The shape of what is coming, in the position it will occupy, while the host answers. */
|
|
11
13
|
function TransclusionSkeleton({ loading }) {
|
|
12
14
|
return (_jsxs("div", { className: "skeleton-region", "aria-busy": "true", "aria-live": "polite", children: [_jsx("span", { className: "visually-hidden", children: loading }), _jsxs("figure", { className: "embed embed-skeleton", children: [_jsx("div", { className: "embed-body", children: _jsxs("span", { className: "skeleton-text", children: [_jsx("span", { className: "skeleton", style: { width: '96%', height: '1rem' } }), _jsx("span", { className: "skeleton", style: { width: '58%', height: '1rem' } })] }) }), _jsx("figcaption", { className: "embed-source", children: _jsx("span", { className: "skeleton", style: { width: '8rem', height: '0.8rem' } }) })] })] }));
|
|
@@ -100,7 +102,8 @@ export function Transclusion({ target, anchor, source }) {
|
|
|
100
102
|
* content into a wikilink, and that embed is drawn as A LINK to its
|
|
101
103
|
* target. Raw text is not a link.
|
|
102
104
|
*/
|
|
103
|
-
|
|
105
|
+
// An embed draws another note's content; the apparatus of navigation is the open note's (#173).
|
|
106
|
+
_jsx(ContentsContext.Provider, { value: EMBEDDED, children: _jsx(PropertiesContext.Provider, { value: { kind: 'embedded' }, children: _jsx(Markdown, { children: resolveWikilinks(demoteEmbeds(cut, embedsFile(inner)), (each) => wikilinkAddress(host, each), embedsFile(inner)) }) }) }));
|
|
104
107
|
if (slot) {
|
|
105
108
|
return drawSlot(slot, {
|
|
106
109
|
state: cut === null ? 'section-missing' : 'ready',
|
package/dist/appendices.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export interface TableAppendix {
|
|
|
22
22
|
readonly table: string | null;
|
|
23
23
|
/** Its place among the note's Markdown tables, from 1, or `null` for a `table` block. */
|
|
24
24
|
readonly markdownTable: number | null;
|
|
25
|
+
/** What names it (#175): a Markdown table's `Table:` caption, as text, or a block's `title`; `null` for none. */
|
|
26
|
+
readonly title?: string | null;
|
|
25
27
|
}
|
|
26
28
|
/** An appendix and the Markdown that draws its table. */
|
|
27
29
|
export interface PlannedAppendix extends TableAppendix {
|
|
@@ -32,6 +34,33 @@ export interface AppendixPlan {
|
|
|
32
34
|
readonly first: readonly number[];
|
|
33
35
|
readonly appendices: readonly PlannedAppendix[];
|
|
34
36
|
}
|
|
37
|
+
interface Node {
|
|
38
|
+
type: string;
|
|
39
|
+
lang?: string | null;
|
|
40
|
+
meta?: string | null;
|
|
41
|
+
value?: string;
|
|
42
|
+
url?: string;
|
|
43
|
+
children?: Node[];
|
|
44
|
+
position?: {
|
|
45
|
+
start: {
|
|
46
|
+
offset?: number;
|
|
47
|
+
column: number;
|
|
48
|
+
};
|
|
49
|
+
end: {
|
|
50
|
+
offset?: number;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
data?: {
|
|
54
|
+
hName?: string;
|
|
55
|
+
hProperties?: Record<string, unknown>;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Each table of a tree, in the order they are read, never one inside another's place. */
|
|
59
|
+
export declare function tablesOf(tree: Node, blocks: boolean): {
|
|
60
|
+
node: Node;
|
|
61
|
+
parent: Node;
|
|
62
|
+
index: number;
|
|
63
|
+
}[];
|
|
35
64
|
/**
|
|
36
65
|
* The appendices of a note drawn in `runs`: each table found in each run, numbered across them.
|
|
37
66
|
* `blocks` is whether a `table` block is drawn as a table, which it is where the host reaches tables.
|
|
@@ -49,3 +78,4 @@ export declare function remarkTableReferences(options: {
|
|
|
49
78
|
readonly appendices: readonly TableAppendix[];
|
|
50
79
|
readonly words: (appendix: TableAppendix) => string;
|
|
51
80
|
}): (tree: unknown) => void;
|
|
81
|
+
export {};
|
package/dist/appendices.js
CHANGED
|
@@ -19,12 +19,13 @@ import remarkParse from 'remark-parse';
|
|
|
19
19
|
import { unified } from 'unified';
|
|
20
20
|
import { justifyColumns } from './justified.js';
|
|
21
21
|
import { isTableBlock, readTableBlock } from './table-block.js';
|
|
22
|
+
import { captionAfter, captionContent, textOf } from './outline.js';
|
|
22
23
|
/** Whether a node is a table the note draws: a Markdown table, or a `table` block where tables are reached. */
|
|
23
24
|
function isAppendixTable(node, blocks) {
|
|
24
25
|
return node.type === 'table' || (blocks && node.type === 'code' && isTableBlock(node.lang, node.meta));
|
|
25
26
|
}
|
|
26
27
|
/** Each table of a tree, in the order they are read, never one inside another's place. */
|
|
27
|
-
function tablesOf(tree, blocks) {
|
|
28
|
+
export function tablesOf(tree, blocks) {
|
|
28
29
|
const found = [];
|
|
29
30
|
const walk = (parent) => {
|
|
30
31
|
(parent.children ?? []).forEach((node, index) => {
|
|
@@ -49,14 +50,17 @@ export function planAppendices(runs, blocks) {
|
|
|
49
50
|
for (const text of runs) {
|
|
50
51
|
first.push(appendices.length + 1);
|
|
51
52
|
// Read as the run reads it, a justified column among them (§4.1).
|
|
52
|
-
for (const { node } of tablesOf(parser.parse(justifyColumns(text).text), blocks)) {
|
|
53
|
+
for (const { node, parent } of tablesOf(parser.parse(justifyColumns(text).text), blocks)) {
|
|
53
54
|
const number = appendices.length + 1;
|
|
54
55
|
if (node.type === 'code') {
|
|
55
|
-
|
|
56
|
+
const block = readTableBlock(node.value ?? '');
|
|
57
|
+
appendices.push({ number, table: block.table, markdownTable: null, title: block.title, source: fenced(node.value ?? '') });
|
|
56
58
|
}
|
|
57
59
|
else {
|
|
58
60
|
markdownTables += 1;
|
|
59
|
-
|
|
61
|
+
const caption = captionAfter(node, parent);
|
|
62
|
+
const title = caption ? captionContent(caption).map(textOf).join('').trim() || null : null;
|
|
63
|
+
appendices.push({ number, table: null, markdownTable: markdownTables, title, source: sliceOf(text, node) });
|
|
60
64
|
}
|
|
61
65
|
}
|
|
62
66
|
}
|
|
@@ -92,6 +96,9 @@ export function remarkTableReferences(options) {
|
|
|
92
96
|
const appendix = options.appendices[options.first - 1 + offset];
|
|
93
97
|
if (!appendix || !parent.children)
|
|
94
98
|
return;
|
|
99
|
+
// Its caption goes with it: it names the appendix (#175).
|
|
100
|
+
if (parent.children[index + 1]?.data?.hName === 'ms-caption')
|
|
101
|
+
parent.children.splice(index + 1, 1);
|
|
95
102
|
parent.children[index] = {
|
|
96
103
|
type: 'paragraph',
|
|
97
104
|
data: { hName: 'p', hProperties: { className: ['table-reference'] } },
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `contents` block (`SPEC.md` §7.17, #173): a table of contents the note declares, read and
|
|
3
|
+
* resolved, with no React and no DOM, so `diagnose` reads it on a server as the page does.
|
|
4
|
+
*
|
|
5
|
+
* A block holds settings in YAML's shape — a key alone on its line opens a group, the `key: value`
|
|
6
|
+
* lines indented below it belong to it — so the host's settings, `NoteHost.contents`, are the same
|
|
7
|
+
* structure a YAML parser gives, and one resolution reads both: the note's medium group, its root,
|
|
8
|
+
* the host's medium group, its root, the default. `place` is the one value not inherited: a note's
|
|
9
|
+
* block with none is drawn where it is written.
|
|
10
|
+
*/
|
|
11
|
+
/** The lists a contents block draws, each a group of its settings. */
|
|
12
|
+
export declare const CONTENTS_LISTS: readonly ["headings", "figures", "tables", "attachments"];
|
|
13
|
+
export type ContentsList = (typeof CONTENTS_LISTS)[number];
|
|
14
|
+
/** The media a contents block tells apart. */
|
|
15
|
+
export declare const CONTENTS_MEDIA: readonly ["screen", "print"];
|
|
16
|
+
export type ContentsMedium = (typeof CONTENTS_MEDIA)[number];
|
|
17
|
+
/** Where a contents is drawn when it is not where its block is written. */
|
|
18
|
+
export type ContentsPlace = 'start' | 'end';
|
|
19
|
+
/** The options of one list. */
|
|
20
|
+
export interface ContentsListOptions {
|
|
21
|
+
/** The title above the list; absent, the host's word for the kind. */
|
|
22
|
+
readonly title?: string;
|
|
23
|
+
/** How many heading levels are listed, from 1 to 6. Only `headings` takes it. */
|
|
24
|
+
readonly depth?: number;
|
|
25
|
+
}
|
|
26
|
+
/** The settings of one medium, or of the root: the lists, in their order, and where. */
|
|
27
|
+
export type ContentsLayer = {
|
|
28
|
+
readonly [kind in ContentsList]?: ContentsListOptions | null;
|
|
29
|
+
} & {
|
|
30
|
+
readonly place?: ContentsPlace;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The settings of a contents, as a block writes them and as a host gives them: the lists at the
|
|
34
|
+
* root apply to every medium, and `screen` and `print` override them for theirs, or draw nothing
|
|
35
|
+
* there with `none`.
|
|
36
|
+
*/
|
|
37
|
+
export type ContentsSettings = ContentsLayer & {
|
|
38
|
+
readonly screen?: ContentsLayer | 'none';
|
|
39
|
+
readonly print?: ContentsLayer | 'none';
|
|
40
|
+
};
|
|
41
|
+
/** The codes a `contents` block raises (§7.13). */
|
|
42
|
+
export type ContentsNoticeCode = 'contents-key-unknown' | 'contents-value-invalid';
|
|
43
|
+
/** One mistake of a block: its code and the line of the block it is on, 1 being the line after the fence. */
|
|
44
|
+
export interface ContentsProblem {
|
|
45
|
+
readonly code: ContentsNoticeCode;
|
|
46
|
+
readonly line: number;
|
|
47
|
+
}
|
|
48
|
+
/** The default depth of the headings list. */
|
|
49
|
+
export declare const CONTENTS_DEPTH = 3;
|
|
50
|
+
/** Whether a fenced block is a `contents` block: its info string is `contents` and nothing else. */
|
|
51
|
+
export declare function isContentsBlock(lang: string | null | undefined, meta: string | null | undefined): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Reads the lines of a `contents` block into its settings, and what is wrong with them. A mistake
|
|
54
|
+
* sets nothing and the rest is read: a block always draws, with its defaults where it said nothing
|
|
55
|
+
* that could be read.
|
|
56
|
+
*/
|
|
57
|
+
export declare function readContents(source: string): {
|
|
58
|
+
settings: ContentsSettings;
|
|
59
|
+
problems: ContentsProblem[];
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Settings with only what they can mean: a host's, read from YAML or JSON, or a block's. An empty
|
|
63
|
+
* group (`headings:`) is a list with its defaults, and anything else is left out.
|
|
64
|
+
*/
|
|
65
|
+
export declare function cleanContents(given: unknown): ContentsSettings | null;
|
|
66
|
+
/** One list a contents draws, with its options resolved. */
|
|
67
|
+
export interface ContentsListPlan {
|
|
68
|
+
readonly kind: ContentsList;
|
|
69
|
+
/** The title written, or `null` for the host's word. */
|
|
70
|
+
readonly title: string | null;
|
|
71
|
+
readonly depth: number;
|
|
72
|
+
}
|
|
73
|
+
/** What a contents draws in one medium, and where: `null` is where its block is written. */
|
|
74
|
+
export interface ContentsPlan {
|
|
75
|
+
readonly lists: readonly ContentsListPlan[];
|
|
76
|
+
readonly place: ContentsPlace | null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* What a note's block draws in a medium, over the host's settings: `null` when the block says
|
|
80
|
+
* `none` there. The lists are the first of the note's medium, the note's root, the host's medium
|
|
81
|
+
* and the host's root that names any, else the headings; each option the nearest that sets it.
|
|
82
|
+
* `place` is the block's own, never the host's.
|
|
83
|
+
*/
|
|
84
|
+
export declare function resolveBlock(block: ContentsSettings, host: ContentsSettings | null, medium: ContentsMedium): ContentsPlan | null;
|
|
85
|
+
/**
|
|
86
|
+
* What the host's settings draw in a medium for a note that holds no block: `null` unless the
|
|
87
|
+
* host's medium group is there, or its root names a list. It is drawn where its `place` says, at
|
|
88
|
+
* the start when it says nothing.
|
|
89
|
+
*/
|
|
90
|
+
export declare function resolveHost(host: ContentsSettings | null, medium: ContentsMedium): ContentsPlan | null;
|
|
91
|
+
/** Whether two plans draw the same lists, so one drawing serves both media. */
|
|
92
|
+
export declare function samePlan(a: ContentsPlan | null, b: ContentsPlan | null): boolean;
|