@memorysmithapp/markdown-renderer 0.11.1 → 0.12.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.
@@ -70,6 +70,9 @@ export function readTable(source, from, to) {
70
70
  at = end + 1;
71
71
  }
72
72
  const align = (rows[1]?.cells ?? []).map((cell) => {
73
+ // The justified column, `;---;`, the specification's own delimiter (§4.1).
74
+ if (/^;-+;$/.test(cell.text))
75
+ return 'justify';
73
76
  const left = cell.text.startsWith(':');
74
77
  const right = cell.text.endsWith(':');
75
78
  return left && right ? 'center' : right ? 'right' : left ? 'left' : null;
@@ -93,7 +96,7 @@ function rowText(table, cells) {
93
96
  }
94
97
  /** The delimiter cell of an alignment. */
95
98
  export function delimiterOf(alignment) {
96
- return alignment === 'center' ? ':---:' : alignment === 'right' ? '---:' : alignment === 'left' ? ':---' : '---';
99
+ return alignment === 'center' ? ':---:' : alignment === 'right' ? '---:' : alignment === 'left' ? ':---' : alignment === 'justify' ? ';---;' : '---';
97
100
  }
98
101
  /**
99
102
  * Replaces the content of one cell of the header (row 0) or of the body (row 2 on). A row with
package/dist/host.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import { type NoteStrings, type NoteStringsInput } from './strings.js';
3
- import type { TablePage, TableRequest } from './table-block.js';
3
+ import type { TablePage, TableRequest, TableRowView } from './table-block.js';
4
+ import { type NoteStyle } from './note-style.js';
4
5
  import { type Scheme, type Theme } from './theme.js';
5
6
  import { type DrawnNote } from './embed-target.js';
6
7
  /**
@@ -70,6 +71,14 @@ export interface NoteHost {
70
71
  * answers a request from rows held in memory.
71
72
  */
72
73
  readonly queryTable?: (request: TableRequest) => Promise<TablePage | null>;
74
+ /**
75
+ * Shows a row of a `table` block whole (#163). On the screen a cell holds one line and a longer
76
+ * value ends in an ellipsis; a click on a row, or Enter on it, hands the host the row with its
77
+ * columns and each value as the table draws it, for the host's own dialog. Without it, the block
78
+ * opens a native `<dialog>` with each column's name and value. A printed block opens nothing: it
79
+ * carries every value whole.
80
+ */
81
+ readonly openTableRow?: (view: TableRowView) => void;
73
82
  /**
74
83
  * Whether the note is being drawn for paper or a PDF (#139). Each `table` block then asks
75
84
  * `queryTable` for every row its filter returns, in its declared order, and is drawn with no
@@ -78,6 +87,24 @@ export interface NoteHost {
78
87
  * `[aria-busy="true"]` is left under the note, then print. Defaults to `false`.
79
88
  */
80
89
  readonly printing?: boolean;
90
+ /**
91
+ * With `printing`, prints each table of the note as an appendix at its end (#165): a Markdown
92
+ * table and a `table` block alike, in the order they appear, numbered in one sequence, each under
93
+ * `strings.tableAppendix` in a `section.table-appendix` the host may lay on a page of its own
94
+ * (`page:`), and a reference in `strings.tableAppendixReference` in its place, linked to the
95
+ * appendix's id, so the host's pagination can number its page (`target-counter()`). The note's own
96
+ * tables only: an embedded note draws its tables in place. Nothing changes on the screen.
97
+ */
98
+ readonly tablesAsAppendices?: boolean;
99
+ /**
100
+ * How the note is set, as its notebook's style says (#164, memorysmithapp/memorysmithapp#493): the
101
+ * face, `sans` or `serif`, and the alignment of headings, of text — paragraphs and list items —
102
+ * and of tables — the cells of a column whose delimiter declares none, and a `table` block's text
103
+ * columns — each `left`, `center`, `right` or `justify`. Justified text hyphenates in the language
104
+ * of `strings.locale`. A key left out, or a value none of those, is what the renderer draws with no
105
+ * style; a `:::{style}` block of the note wins over it in its passage.
106
+ */
107
+ readonly noteStyle?: NoteStyle;
81
108
  /**
82
109
  * Whether the reader may tick the task boxes of this note. Defaults to `false`: every box shows
83
110
  * its state and none answers a click.
@@ -281,7 +308,10 @@ export interface ResolvedHost {
281
308
  */
282
309
  readonly drawn: DrawnNote | null;
283
310
  readonly queryTable: ((request: TableRequest) => Promise<TablePage | null>) | null;
311
+ readonly openTableRow: ((view: TableRowView) => void) | null;
284
312
  readonly printing: boolean;
313
+ readonly tablesAsAppendices: boolean;
314
+ readonly noteStyle: NoteStyle;
285
315
  readonly keeps: (name: string) => boolean;
286
316
  readonly suggest: ((query: string) => readonly string[] | PromiseLike<readonly string[]>) | null;
287
317
  readonly attach: ((file: File, attributes: AttachAttributes, progress: (report: AttachProgress) => void) => string | PromiseLike<string>) | null;
package/dist/host.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { createContext, useContext, useMemo } from 'react';
3
3
  import { withDefaults } from './strings.js';
4
+ import { cleanStyle } from './note-style.js';
4
5
  import { DEFAULT_THEME, schemeOf } from './theme.js';
5
6
  import { drawing, drawnNote } from './embed-target.js';
6
7
  /** Whether a rejection is a refusal the host worded for the author, and not an error. */
@@ -25,7 +26,10 @@ export const HOST_KEYS = Object.keys({
25
26
  loadNoteAt: 1,
26
27
  noteAddress: 1,
27
28
  queryTable: 1,
29
+ openTableRow: 1,
28
30
  printing: 1,
31
+ tablesAsAppendices: 1,
32
+ noteStyle: 1,
29
33
  writable: 1,
30
34
  onToggleTask: 1,
31
35
  keeps: 1,
@@ -62,7 +66,10 @@ export function resolveHost(host) {
62
66
  loadNoteAt: host.loadNoteAt ?? null,
63
67
  drawn: null,
64
68
  queryTable: host.queryTable ?? null,
69
+ openTableRow: host.openTableRow ?? null,
65
70
  printing: host.printing ?? false,
71
+ tablesAsAppendices: host.tablesAsAppendices ?? false,
72
+ noteStyle: cleanStyle(host.noteStyle),
66
73
  keeps: host.keeps ?? never,
67
74
  suggest: host.suggest ?? null,
68
75
  attach: host.attach ?? null,
package/dist/index.d.ts CHANGED
@@ -11,4 +11,6 @@ export { codeRegions, fenceRegions, headingKey, remoteImageHosts, resolveWikilin
11
11
  export { ordinalAt, taskBoxes, taskCheckedAt, toggleTaskAt } from './tasklist.js';
12
12
  export { readProperties, type NoteProperties, type PropertyEntry, type PropertyShape } from './properties.js';
13
13
  export { DELEGATED_TO_THE_BASE_PARSER, unclassified } from './delegated.js';
14
- export { runTableQuery, type TableColumn, type TableColumnKind, type TablePage, type TableRequest, type TableRow, type TableSchema, type TableSortKey, type TableValue, } from './table-block.js';
14
+ export type { TableAppendix } from './appendices.js';
15
+ export type { NoteStyle, StyleAlignment, StyleFont } from './note-style.js';
16
+ export { runTableQuery, type TableColumn, type TableColumnKind, type TablePage, type TableRequest, type TableRow, type TableRowView, type TableSchema, type TableSortKey, type TableValue, } from './table-block.js';
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The justified column of a table, `;---;` in its delimiter row (`SPEC.md` §4.1, #164).
3
+ *
4
+ * GFM has no justified column, and the parser's table tokenizer, `remark-gfm`'s, reads a delimiter
5
+ * row of colons and dashes only: to it a row holding `;---;` is text, and so is the table. So the
6
+ * text is prepared before it is parsed: in a delimiter row whose every cell is GFM's or `;---;`,
7
+ * each `;` of a justified cell becomes a `:`, which the tokenizer reads as a centred column, and
8
+ * the cell is remembered by its line and column. Then `remarkJustifiedColumns` turns those columns
9
+ * from centred to justified on the table it finds there. A `;` replaced by a `:` keeps every offset
10
+ * of the text, so what the parser reports — the place of a task box among it — is the text's own.
11
+ *
12
+ * A row holding a `;` on one side of a cell only, or beside a colon, is left alone, and stays text,
13
+ * as §4.1 says. Rows inside code are never touched: they are examples.
14
+ */
15
+ export interface Justified {
16
+ /** The text the parser reads: every justified cell written as a centred one. */
17
+ readonly text: string;
18
+ /** The justified columns, by the line of their delimiter row, from 1, each from 0. */
19
+ readonly columns: ReadonlyMap<number, readonly number[]>;
20
+ }
21
+ export declare function justifyColumns(text: string): Justified;
22
+ /** Turns the columns `justifyColumns` remembered from centred to justified, on the table whose delimiter row holds them. */
23
+ export declare function remarkJustifiedColumns(options: {
24
+ readonly columns: ReadonlyMap<number, readonly number[]>;
25
+ }): (tree: unknown) => void;
@@ -0,0 +1,96 @@
1
+ /**
2
+ * The justified column of a table, `;---;` in its delimiter row (`SPEC.md` §4.1, #164).
3
+ *
4
+ * GFM has no justified column, and the parser's table tokenizer, `remark-gfm`'s, reads a delimiter
5
+ * row of colons and dashes only: to it a row holding `;---;` is text, and so is the table. So the
6
+ * text is prepared before it is parsed: in a delimiter row whose every cell is GFM's or `;---;`,
7
+ * each `;` of a justified cell becomes a `:`, which the tokenizer reads as a centred column, and
8
+ * the cell is remembered by its line and column. Then `remarkJustifiedColumns` turns those columns
9
+ * from centred to justified on the table it finds there. A `;` replaced by a `:` keeps every offset
10
+ * of the text, so what the parser reports — the place of a task box among it — is the text's own.
11
+ *
12
+ * A row holding a `;` on one side of a cell only, or beside a colon, is left alone, and stays text,
13
+ * as §4.1 says. Rows inside code are never touched: they are examples.
14
+ */
15
+ import { codeRegions, insideCode } from './source.js';
16
+ /** A cell of a delimiter row: GFM's, or the justified column's. */
17
+ const CELL = /^[ \t]*(?::?-+:?|;-+;)[ \t]*$/;
18
+ const JUSTIFIED = /^([ \t]*);(-+);([ \t]*)$/;
19
+ /** What may stand before a table's rows: the markers of the quote or callout that holds it, and the indent of a list item. */
20
+ const CONTAINER = /^[ \t>]*/;
21
+ /** The cells of a row, without its outer pipes, each with where it starts in the row. */
22
+ function cellsOf(row) {
23
+ const cells = [];
24
+ let start = 0;
25
+ let end = row.length;
26
+ if (row.trimStart().startsWith('|'))
27
+ start = row.indexOf('|') + 1;
28
+ if (row.trimEnd().endsWith('|') && row.trimEnd().length > start)
29
+ end = row.lastIndexOf('|');
30
+ let at = start;
31
+ for (let index = start; index <= end; index++) {
32
+ if (index === end || row[index] === '|') {
33
+ cells.push({ text: row.slice(at, index), at });
34
+ at = index + 1;
35
+ }
36
+ }
37
+ return cells;
38
+ }
39
+ export function justifyColumns(text) {
40
+ if (!text.includes(';'))
41
+ return { text, columns: new Map() };
42
+ const code = codeRegions(text);
43
+ const lines = text.split('\n');
44
+ const columns = new Map();
45
+ let offset = 0;
46
+ const out = [];
47
+ lines.forEach((line, index) => {
48
+ const at = offset;
49
+ offset += line.length + 1;
50
+ const previous = lines[index - 1];
51
+ if (index === 0 || !line.includes(';') || !line.includes('-') || previous === undefined || !previous.includes('|') || insideCode(code, at)) {
52
+ out.push(line);
53
+ return;
54
+ }
55
+ const prefix = CONTAINER.exec(line)?.[0] ?? '';
56
+ const row = line.slice(prefix.length);
57
+ const cells = cellsOf(row);
58
+ if (cells.length === 0 || !cells.every((cell) => CELL.test(cell.text)) || (cells.length === 1 && !row.includes('|'))) {
59
+ out.push(line);
60
+ return;
61
+ }
62
+ const justified = cells.flatMap((cell, column) => (JUSTIFIED.test(cell.text) ? [column] : []));
63
+ if (justified.length === 0) {
64
+ out.push(line);
65
+ return;
66
+ }
67
+ let rewritten = row;
68
+ for (const column of justified) {
69
+ const cell = cells[column];
70
+ const replaced = cell.text.replace(JUSTIFIED, '$1:$2:$3');
71
+ rewritten = rewritten.slice(0, cell.at) + replaced + rewritten.slice(cell.at + cell.text.length);
72
+ }
73
+ columns.set(index + 1, justified);
74
+ out.push(prefix + rewritten);
75
+ });
76
+ return { text: out.join('\n'), columns };
77
+ }
78
+ /** Turns the columns `justifyColumns` remembered from centred to justified, on the table whose delimiter row holds them. */
79
+ export function remarkJustifiedColumns(options) {
80
+ return (tree) => {
81
+ if (options.columns.size === 0)
82
+ return;
83
+ const walk = (node) => {
84
+ if (node.type === 'table' && node.position && node.align) {
85
+ for (const column of options.columns.get(node.position.start.line + 1) ?? []) {
86
+ if (column < node.align.length)
87
+ node.align[column] = 'justify';
88
+ }
89
+ return;
90
+ }
91
+ for (const child of node.children ?? [])
92
+ walk(child);
93
+ };
94
+ walk(tree);
95
+ };
96
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * How a note is set: its face, and the alignment of its headings, its text and its tables (#164,
3
+ * memorysmithapp/memorysmithapp#493).
4
+ *
5
+ * The notebook keeps a style, and the host hands it to the renderer as `noteStyle`; a passage of a
6
+ * note may differ from it in a `:::{style}` block (`SPEC.md` §7.16). Either way the choice is
7
+ * written as custom properties on the element it governs — the root of the note, or the block — so
8
+ * an inner choice wins over an outer one by inheritance, and the stylesheet reads them with today's
9
+ * drawing as their fallback: a note with no style is drawn exactly as before.
10
+ *
11
+ * Justified text hyphenates, in the language the host gives (`strings.locale`), which is what the
12
+ * element that justifies is marked with: a browser hyphenates only a language it is told.
13
+ */
14
+ export type StyleFont = 'sans' | 'serif';
15
+ export type StyleAlignment = 'left' | 'center' | 'right' | 'justify';
16
+ /** A style: each key left out is what the renderer draws with none. */
17
+ export interface NoteStyle {
18
+ /** The face of the text and the headings. */
19
+ readonly font?: StyleFont;
20
+ /** The alignment of headings. */
21
+ readonly headings?: StyleAlignment;
22
+ /** The alignment of paragraphs and list items. */
23
+ readonly text?: StyleAlignment;
24
+ /** The alignment of a table's cells whose column declares none, and of a `table` block's text columns. */
25
+ readonly tables?: StyleAlignment;
26
+ }
27
+ export declare const STYLE_FONTS: readonly StyleFont[];
28
+ export declare const STYLE_ALIGNMENTS: readonly StyleAlignment[];
29
+ export declare const STYLE_KEYS: readonly ["font", "headings", "text", "tables"];
30
+ export type StyleKey = (typeof STYLE_KEYS)[number];
31
+ /** Whether `value` is one `key` takes. */
32
+ export declare function takes(key: StyleKey, value: string): boolean;
33
+ /** A style with only the keys and values it may hold: a host's mistake is ignored, never drawn. */
34
+ export declare function cleanStyle(style: NoteStyle | null | undefined): NoteStyle;
35
+ /** The custom properties that set a style on the element it governs; empty for no style. */
36
+ export declare function styleProperties(style: NoteStyle): Record<string, string>;
37
+ /** Whether a style justifies anything, so the element it governs carries the language to hyphenate in. */
38
+ export declare const justifies: (style: NoteStyle) => boolean;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * How a note is set: its face, and the alignment of its headings, its text and its tables (#164,
3
+ * memorysmithapp/memorysmithapp#493).
4
+ *
5
+ * The notebook keeps a style, and the host hands it to the renderer as `noteStyle`; a passage of a
6
+ * note may differ from it in a `:::{style}` block (`SPEC.md` §7.16). Either way the choice is
7
+ * written as custom properties on the element it governs — the root of the note, or the block — so
8
+ * an inner choice wins over an outer one by inheritance, and the stylesheet reads them with today's
9
+ * drawing as their fallback: a note with no style is drawn exactly as before.
10
+ *
11
+ * Justified text hyphenates, in the language the host gives (`strings.locale`), which is what the
12
+ * element that justifies is marked with: a browser hyphenates only a language it is told.
13
+ */
14
+ export const STYLE_FONTS = ['sans', 'serif'];
15
+ export const STYLE_ALIGNMENTS = ['left', 'center', 'right', 'justify'];
16
+ export const STYLE_KEYS = ['font', 'headings', 'text', 'tables'];
17
+ /** Whether `value` is one `key` takes. */
18
+ export function takes(key, value) {
19
+ return key === 'font' ? STYLE_FONTS.includes(value) : STYLE_ALIGNMENTS.includes(value);
20
+ }
21
+ /** A style with only the keys and values it may hold: a host's mistake is ignored, never drawn. */
22
+ export function cleanStyle(style) {
23
+ if (!style)
24
+ return {};
25
+ const clean = {};
26
+ for (const key of STYLE_KEYS) {
27
+ const value = style[key];
28
+ if (typeof value === 'string' && takes(key, value))
29
+ clean[key] = value;
30
+ }
31
+ return clean;
32
+ }
33
+ /** The custom properties that set a style on the element it governs; empty for no style. */
34
+ export function styleProperties(style) {
35
+ const properties = {};
36
+ if (style.font) {
37
+ properties['--ms-face'] = style.font === 'serif' ? 'var(--ms-font-serif)' : 'var(--ms-font-sans)';
38
+ properties['--ms-face-heading'] = style.font === 'serif' ? 'var(--ms-font-serif)' : 'var(--ms-font-heading)';
39
+ }
40
+ if (style.headings)
41
+ properties['--ms-align-headings'] = style.headings;
42
+ if (style.text) {
43
+ properties['--ms-align-text'] = style.text;
44
+ properties['--ms-hyphens-text'] = style.text === 'justify' ? 'auto' : 'manual';
45
+ }
46
+ if (style.tables) {
47
+ properties['--ms-align-tables'] = style.tables;
48
+ properties['--ms-hyphens-tables'] = style.tables === 'justify' ? 'auto' : 'manual';
49
+ }
50
+ return properties;
51
+ }
52
+ /** Whether a style justifies anything, so the element it governs carries the language to hyphenate in. */
53
+ export const justifies = (style) => STYLE_KEYS.some((key) => key !== 'font' && style[key] === 'justify');
package/dist/source.js CHANGED
@@ -221,9 +221,10 @@ export function insideCode(regions, at) {
221
221
  * and it runs to the first blank line. The outer pipes are optional, which is
222
222
  * why the delimiter row is what identifies the block. A shape this misses
223
223
  * costs nothing new — it is the behaviour of before — so the pattern is
224
- * deliberately the conservative one.
224
+ * deliberately the conservative one. A cell of the delimiter row is GFM's,
225
+ * colons and dashes, or the justified column's `;---;` (§4.1).
225
226
  */
226
- const DELIMITER_ROW = /^ {0,3}\|?[ \t]*:?-{1,}:?[ \t]*(\|[ \t]*:?-{1,}:?[ \t]*)*\|?[ \t]*$/;
227
+ const DELIMITER_ROW = /^ {0,3}\|?[ \t]*(?::?-{1,}:?|;-{1,};)[ \t]*(\|[ \t]*(?::?-{1,}:?|;-{1,};)[ \t]*)*\|?[ \t]*$/;
227
228
  export function tableRegions(body) {
228
229
  const regions = [];
229
230
  const code = codeRegions(body);
package/dist/strings.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { TableAppendix } from './appendices.js';
1
2
  import type { TableNoticeCode } from './table-block.js';
2
3
  /**
3
4
  * The words the reading surface shows of its own, around what a note says.
@@ -28,11 +29,12 @@ export interface NoteStrings {
28
29
  readonly parameter: string;
29
30
  /** The title of a wikilink whose target writes a parameter, which leads nowhere until then. */
30
31
  readonly parameterLink: string;
31
- /** How many rows the filter of a `table` block returns (§7.15). */
32
- readonly tableRows: (count: number) => string;
33
- /** Which page of a `table` block is drawn, of how many. */
34
- readonly tablePage: (page: number, pages: number) => string;
35
- /** The buttons that move a `table` block to the page before and after. */
32
+ /**
33
+ * Which rows of a `table` block are drawn, of how many the filter returns (§7.15, #163): `first`
34
+ * and `last` count from 1, and are 0 when the filter returns no row.
35
+ */
36
+ readonly tableShowing: (first: number, last: number, total: number) => string;
37
+ /** The buttons that move a `table` block to the page before and after, drawn after and before an arrow, which stands alone on a narrow block. */
36
38
  readonly tablePrevious: string;
37
39
  readonly tableNext: string;
38
40
  /** The label of the row that closes a table with its total. */
@@ -50,6 +52,14 @@ export interface NoteStrings {
50
52
  readonly count: number;
51
53
  readonly readAt: string;
52
54
  }) => string;
55
+ /**
56
+ * The title of a table printed as an appendix at the end of the note (#165): its number among the
57
+ * appendices, and the table a `table` block names, or for a Markdown table, which has none, its
58
+ * number among the note's Markdown tables.
59
+ */
60
+ readonly tableAppendix: (appendix: TableAppendix) => string;
61
+ /** What stands in a printed note in place of a table printed as an appendix, linked to it (#165). */
62
+ readonly tableAppendixReference: (appendix: TableAppendix) => string;
53
63
  /** The title of an embed naming a file the notebook does not keep. */
54
64
  readonly attachmentMissing: string;
55
65
  /** A card's ways to a file: open it where a browser shows it, and save it (#77). */
@@ -128,6 +138,25 @@ export interface EditorWords {
128
138
  readonly math: string;
129
139
  readonly diagram: string;
130
140
  readonly rule: string;
141
+ /**
142
+ * A `:::{style}` block (`SPEC.md` §7.16, #166): the control and the title of its form, the form's
143
+ * four keys, what each value reads as, the choice that writes no key, and its two verbs — one that
144
+ * wraps the passage in a new block, one that changes the block the cursor is in.
145
+ */
146
+ readonly style: string;
147
+ readonly styleFont: string;
148
+ readonly styleHeadings: string;
149
+ readonly styleText: string;
150
+ readonly styleTables: string;
151
+ readonly styleNotebook: string;
152
+ readonly styleSans: string;
153
+ readonly styleSerif: string;
154
+ readonly styleLeft: string;
155
+ readonly styleCenter: string;
156
+ readonly styleRight: string;
157
+ readonly styleJustify: string;
158
+ readonly styleInsert: string;
159
+ readonly styleApply: string;
131
160
  readonly footnote: string;
132
161
  readonly comment: string;
133
162
  /** The toolbar's button that attaches a file, and what it says while the host keeps it or failed (#75). */
@@ -217,6 +246,8 @@ export interface EditorWords {
217
246
  readonly alignLeft: string;
218
247
  readonly alignCenter: string;
219
248
  readonly alignRight: string;
249
+ /** Justifies the column of the cell the author is in, `;---;` (`SPEC.md` §4.1, #166). */
250
+ readonly alignJustify: string;
220
251
  /** The buttons beside the switch that show the note's Markdown and copy it, and the dialog (#63, #76). */
221
252
  readonly showMarkdown: string;
222
253
  readonly copyMarkdown: string;
package/dist/strings.js CHANGED
@@ -41,10 +41,9 @@ export const ENGLISH = {
41
41
  refusedLink: 'This address is not one the reading surface follows, so the text stays and the link does not.',
42
42
  parameter: 'Parameter: filled in when a notebook is created from this model.',
43
43
  parameterLink: 'A link to a parameter: it leads to a note once a notebook is created from this model.',
44
- tableRows: (count) => (count === 1 ? '1 row' : `${count.toLocaleString('en-US')} rows`),
45
- tablePage: (page, pages) => `Page ${page} of ${pages}`,
46
- tablePrevious: 'Previous page',
47
- tableNext: 'Next page',
44
+ tableShowing: (first, last, total) => total === 0 ? 'No rows' : `${first.toLocaleString('en-US')}–${last.toLocaleString('en-US')} of ${total.toLocaleString('en-US')}`,
45
+ tablePrevious: 'Previous',
46
+ tableNext: 'Next',
48
47
  tableTotal: 'Total',
49
48
  tableEmpty: 'No row answers this filter.',
50
49
  tableSortBy: (column) => `Sort by ${column}, for you alone: the note keeps its order`,
@@ -65,6 +64,8 @@ export const ENGLISH = {
65
64
  }
66
65
  },
67
66
  tablePrinted: ({ table, filter, count, readAt }) => `Table ${table}${filter === null ? '' : `, filtered by ${filter}`}: ${count === 1 ? '1 row' : `${count.toLocaleString('en-US')} rows`}, read on ${readAt}.`,
67
+ tableAppendix: ({ number, table, markdownTable }) => `Appendix ${number} — ${table ?? `Table ${markdownTable}`}`,
68
+ tableAppendixReference: ({ number, table, markdownTable }) => `See appendix ${number}, ${table ?? `table ${markdownTable}`}.`,
68
69
  attachmentMissing: 'This notebook keeps no file under that name.',
69
70
  attachmentOpen: 'Open',
70
71
  attachmentDownload: 'Download',
@@ -133,6 +134,20 @@ export const ENGLISH = {
133
134
  math: 'Formula',
134
135
  diagram: 'Diagram',
135
136
  rule: 'Divider',
137
+ style: 'Style',
138
+ styleFont: 'Font',
139
+ styleHeadings: 'Headings',
140
+ styleText: 'Text',
141
+ styleTables: 'Tables',
142
+ styleNotebook: "The notebook's",
143
+ styleSans: 'Sans serif',
144
+ styleSerif: 'Serif',
145
+ styleLeft: 'Left',
146
+ styleCenter: 'Centered',
147
+ styleRight: 'Right',
148
+ styleJustify: 'Justified',
149
+ styleInsert: 'Set apart',
150
+ styleApply: 'Apply',
136
151
  footnote: 'Footnote',
137
152
  comment: 'Comment',
138
153
  attach: 'Attach a file',
@@ -204,6 +219,7 @@ export const ENGLISH = {
204
219
  alignLeft: 'Align left',
205
220
  alignCenter: 'Center',
206
221
  alignRight: 'Align right',
222
+ alignJustify: 'Justify',
207
223
  showMarkdown: 'Show Markdown',
208
224
  copyMarkdown: 'Copy Markdown',
209
225
  sourceTitle: 'The note in Markdown',
@@ -0,0 +1,78 @@
1
+ /**
2
+ * The `:::{style}` block (`SPEC.md` §7.16, #164): a passage of a note set apart from the notebook's
3
+ * style, a colon fence holding its options in a `---` block, as MyST writes a directive.
4
+ *
5
+ * ```markdown
6
+ * :::{style}
7
+ * ---
8
+ * text: justify
9
+ * headings: center
10
+ * ---
11
+ * # Ata da assembleia
12
+ * :::
13
+ * ```
14
+ *
15
+ * No parser of this package reads a colon fence, so the block is found here, on the text, as the
16
+ * code regions and the comments are: a fence inside code is an example and is never read. Each
17
+ * fence line and each line of the options is then written as spaces of its own length, which keeps
18
+ * every offset and every line of the text, and leaves the content parsed exactly as it would be on
19
+ * its own — a line of options is no setext heading (§3.4), and the content's headings are the
20
+ * note's (§3.3). What a block sets is drawn by wrapping the content it holds, by its lines.
21
+ *
22
+ * A block opens at the margin, up to three spaces in, never inside a quote or a list. A bare colon
23
+ * fence closes the innermost open block whose fence it is at least as long as; one that closes
24
+ * nothing is text. A block never closed runs to the end of the note. A key or a value the style
25
+ * cannot take, and a block never closed, are its notices (§7.13); none is an error.
26
+ */
27
+ import { type NoteStyle } from './note-style.js';
28
+ export type StyleNoticeCode = 'style-key-unknown' | 'style-value-invalid' | 'style-unclosed';
29
+ export interface StyleProblem {
30
+ readonly code: StyleNoticeCode;
31
+ /** The line it is about, from 1, and its offset in the text. */
32
+ readonly line: number;
33
+ readonly at: number;
34
+ readonly end: number;
35
+ }
36
+ export interface StyleBlock {
37
+ /** The line of the opening fence, from 1. */
38
+ readonly open: number;
39
+ /** The line of the closing fence, or `null` for a block that runs to the end of the text. */
40
+ readonly close: number | null;
41
+ /** The first and last lines of what the block holds, which may be none (`from > to`). */
42
+ readonly from: number;
43
+ readonly to: number;
44
+ /** What the block sets: the keys and values its options may hold. */
45
+ readonly style: NoteStyle;
46
+ /** How deep it sits among the blocks, from 0. */
47
+ readonly depth: number;
48
+ }
49
+ export interface StyleBlocks {
50
+ /** The text with every fence and option line written as spaces. */
51
+ readonly text: string;
52
+ readonly blocks: readonly StyleBlock[];
53
+ readonly problems: readonly StyleProblem[];
54
+ }
55
+ /** Every style block of a text, and the text with their fences and options blanked. */
56
+ export declare function findStyleBlocks(text: string): StyleBlocks;
57
+ /** A block as one run of a note draws it: its lines in the run's own count, from 1. */
58
+ export interface StyleRange {
59
+ readonly from: number;
60
+ readonly to: number;
61
+ readonly style: NoteStyle;
62
+ readonly depth: number;
63
+ }
64
+ /** The blocks that reach the lines `first` to `last` of the text, in those lines' own count. */
65
+ export declare function rangesFor(blocks: readonly StyleBlock[], first: number, last: number): StyleRange[];
66
+ /** What a line of the text is set as, every block that holds it merged, the innermost winning. */
67
+ export declare function styleAt(blocks: readonly StyleBlock[], line: number): NoteStyle;
68
+ /** The attributes of the element that draws a block: its class, its style's custom properties, what it sets, and the language when it justifies. */
69
+ export declare function blockAttributes(style: NoteStyle, locale: string): Record<string, unknown>;
70
+ /**
71
+ * Wraps what each block holds, by its lines, in the element that draws it: a `div.style-block`
72
+ * carrying its style as custom properties, which its content inherits and an inner block's own
73
+ * override. The last plugin of a run, so every other one reads the tree as the parser left it.
74
+ */
75
+ export declare function remarkStyleBlocks(options: {
76
+ readonly ranges: readonly StyleRange[];
77
+ readonly locale: string;
78
+ }): (tree: unknown) => void;