@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.
Files changed (52) hide show
  1. package/README.md +8 -2
  2. package/dist/ContentsBlock.d.ts +82 -0
  3. package/dist/ContentsBlock.js +162 -0
  4. package/dist/DataTable.js +31 -4
  5. package/dist/InPageAnchor.d.ts +20 -0
  6. package/dist/InPageAnchor.js +35 -0
  7. package/dist/Markdown.d.ts +7 -1
  8. package/dist/Markdown.js +48 -31
  9. package/dist/NoteBody.js +107 -28
  10. package/dist/PropertiesBlock.d.ts +54 -3
  11. package/dist/PropertiesBlock.js +91 -5
  12. package/dist/Transclusion.js +4 -1
  13. package/dist/appendices.d.ts +30 -0
  14. package/dist/appendices.js +11 -4
  15. package/dist/contents.d.ts +92 -0
  16. package/dist/contents.js +224 -0
  17. package/dist/diagnose.d.ts +3 -1
  18. package/dist/diagnose.js +25 -0
  19. package/dist/edit/ContentsDialog.d.ts +39 -0
  20. package/dist/edit/ContentsDialog.js +126 -0
  21. package/dist/edit/NoteEditor.js +56 -4
  22. package/dist/edit/PropertiesDialog.d.ts +42 -0
  23. package/dist/edit/PropertiesDialog.js +103 -0
  24. package/dist/edit/StyleDialog.js +5 -3
  25. package/dist/edit/blocks.d.ts +29 -0
  26. package/dist/edit/blocks.js +100 -3
  27. package/dist/edit/contents.d.ts +30 -0
  28. package/dist/edit/contents.js +76 -0
  29. package/dist/edit/live.js +72 -2
  30. package/dist/edit/properties.d.ts +26 -0
  31. package/dist/edit/properties.js +60 -0
  32. package/dist/host.d.ts +24 -0
  33. package/dist/host.js +6 -0
  34. package/dist/index.d.ts +3 -0
  35. package/dist/index.js +3 -0
  36. package/dist/kept-files.d.ts +11 -0
  37. package/dist/kept-files.js +49 -0
  38. package/dist/note-style.d.ts +9 -1
  39. package/dist/note-style.js +4 -2
  40. package/dist/outline.d.ts +227 -0
  41. package/dist/outline.js +366 -0
  42. package/dist/properties-block.d.ts +62 -0
  43. package/dist/properties-block.js +175 -0
  44. package/dist/slots.js +11 -2
  45. package/dist/strings.d.ts +60 -0
  46. package/dist/strings.js +43 -1
  47. package/dist/table-block.d.ts +13 -1
  48. package/dist/table-block.js +2 -1
  49. package/dist/theme.d.ts +19 -0
  50. package/package.json +4 -2
  51. package/structure.css +54 -0
  52. package/theme-default.css +56 -0
package/dist/strings.d.ts CHANGED
@@ -60,6 +60,15 @@ export interface NoteStrings {
60
60
  readonly tableAppendix: (appendix: TableAppendix) => string;
61
61
  /** What stands in a printed note in place of a table printed as an appendix, linked to it (#165). */
62
62
  readonly tableAppendixReference: (appendix: TableAppendix) => string;
63
+ /** The title of a contents' list of headings when its block writes none (§7.17, #173). */
64
+ readonly contentsHeadings: string;
65
+ /** The titles of a contents' lists of figures, tables and attachments when its block writes none (#175). */
66
+ readonly contentsFigures: string;
67
+ readonly contentsTables: string;
68
+ readonly contentsAttachments: string;
69
+ /** What a figure and a table are called with their number, in a contents and under them (#175). */
70
+ readonly figureNumber: (number: number) => string;
71
+ readonly tableNumber: (number: number) => string;
63
72
  /** The title of an embed naming a file the notebook does not keep. */
64
73
  readonly attachmentMissing: string;
65
74
  /** A card's ways to a file: open it where a browser shows it, and save it (#77). */
@@ -157,6 +166,55 @@ export interface EditorWords {
157
166
  readonly styleJustify: string;
158
167
  readonly styleInsert: string;
159
168
  readonly styleApply: string;
169
+ /** The numbering of headings (#174): the field, and its two values. */
170
+ readonly styleNumbering: string;
171
+ readonly styleNumberingNone: string;
172
+ readonly styleNumberingDecimal: string;
173
+ /**
174
+ * A `contents` block (`SPEC.md` §7.17, #173): the control and the title of its form, its fields
175
+ * — the title, the levels, where it is drawn, and what the screen and print draw — the choices of
176
+ * each, and the button that writes it, inserting a block or changing the one the cursor is in.
177
+ */
178
+ readonly contents: string;
179
+ readonly contentsTitle: string;
180
+ readonly contentsDepth: string;
181
+ readonly contentsPlace: string;
182
+ readonly contentsScreen: string;
183
+ readonly contentsPrint: string;
184
+ /** A choice that writes nothing: what the notebook's settings say, else the default. */
185
+ readonly contentsNotebook: string;
186
+ readonly contentsHere: string;
187
+ readonly contentsStart: string;
188
+ readonly contentsEnd: string;
189
+ readonly contentsSame: string;
190
+ readonly contentsNone: string;
191
+ readonly contentsOwn: string;
192
+ readonly contentsInsert: string;
193
+ readonly contentsApply: string;
194
+ /**
195
+ * What a block says in edit mode where it draws nothing on the screen: where it is drawn on the
196
+ * screen and in print, `here`, `start` or `end`, or `null` where it draws nothing.
197
+ */
198
+ /**
199
+ * A `properties` block (`SPEC.md` §7.18, #172): the control and the title of its form, the keys
200
+ * to choose and order, the fold and its two values, the button that moves a key up, and what a
201
+ * block says in edit mode where it draws nothing on the screen.
202
+ */
203
+ readonly propertiesBlock: string;
204
+ readonly propertiesKeys: string;
205
+ readonly propertiesAllKeys: string;
206
+ readonly propertiesFold: string;
207
+ readonly propertiesOpen: string;
208
+ readonly propertiesClosed: string;
209
+ readonly propertiesMoveUp: (key: string) => string;
210
+ readonly propertiesElsewhere: (where: {
211
+ readonly screen: 'here' | 'start' | 'end' | null;
212
+ readonly print: 'here' | 'start' | 'end' | null;
213
+ }) => string;
214
+ readonly contentsElsewhere: (where: {
215
+ readonly screen: 'here' | 'start' | 'end' | null;
216
+ readonly print: 'here' | 'start' | 'end' | null;
217
+ }) => string;
160
218
  readonly footnote: string;
161
219
  readonly comment: string;
162
220
  /** The toolbar's button that attaches a file, and what it says while the host keeps it or failed (#75). */
@@ -248,6 +306,8 @@ export interface EditorWords {
248
306
  readonly alignRight: string;
249
307
  /** Justifies the column of the cell the author is in, `;---;` (`SPEC.md` §4.1, #166). */
250
308
  readonly alignJustify: string;
309
+ /** The field under a table in edit mode that writes its `Table:` caption (#175). */
310
+ readonly tableCaption: string;
251
311
  /** The buttons beside the switch that show the note's Markdown and copy it, and the dialog (#63, #76). */
252
312
  readonly showMarkdown: string;
253
313
  readonly copyMarkdown: string;
package/dist/strings.js CHANGED
@@ -64,8 +64,14 @@ export const ENGLISH = {
64
64
  }
65
65
  },
66
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}`}`,
67
+ tableAppendix: ({ number, table, markdownTable, title }) => `Appendix ${number} — ${title ?? table ?? `Table ${markdownTable}`}`,
68
68
  tableAppendixReference: ({ number, table, markdownTable }) => `See appendix ${number}, ${table ?? `table ${markdownTable}`}.`,
69
+ contentsHeadings: 'Contents',
70
+ contentsFigures: 'Figures',
71
+ contentsTables: 'Tables',
72
+ contentsAttachments: 'Attachments',
73
+ figureNumber: (number) => `Figure ${number}`,
74
+ tableNumber: (number) => `Table ${number}`,
69
75
  attachmentMissing: 'This notebook keeps no file under that name.',
70
76
  attachmentOpen: 'Open',
71
77
  attachmentDownload: 'Download',
@@ -148,6 +154,41 @@ export const ENGLISH = {
148
154
  styleJustify: 'Justified',
149
155
  styleInsert: 'Set apart',
150
156
  styleApply: 'Apply',
157
+ styleNumbering: 'Numbering',
158
+ styleNumberingNone: 'None',
159
+ styleNumberingDecimal: '1, 1.1, 1.2',
160
+ contents: 'Contents',
161
+ contentsTitle: 'Title',
162
+ contentsDepth: 'Levels',
163
+ contentsPlace: 'Where',
164
+ contentsScreen: 'On the screen',
165
+ contentsPrint: 'In print',
166
+ contentsNotebook: "The notebook's",
167
+ contentsHere: 'Where it is written',
168
+ contentsStart: 'At the start',
169
+ contentsEnd: 'At the end',
170
+ contentsSame: 'As above',
171
+ contentsNone: 'Not drawn',
172
+ contentsOwn: 'Its own',
173
+ contentsInsert: 'Insert',
174
+ contentsApply: 'Apply',
175
+ propertiesBlock: 'Properties',
176
+ propertiesKeys: 'Keys',
177
+ propertiesAllKeys: 'Every key, the reserved ones first',
178
+ propertiesFold: 'Folded',
179
+ propertiesOpen: 'Open',
180
+ propertiesClosed: 'Closed',
181
+ propertiesMoveUp: (key) => `Move ${key} up`,
182
+ propertiesElsewhere: ({ screen, print }) => {
183
+ const at = (where) => (where === 'here' ? 'here' : where === 'start' ? 'at the start' : 'at the end');
184
+ const parts = [screen && `${at(screen)} on the screen`, print && `${at(print)} in print`].filter(Boolean);
185
+ return parts.length === 0 ? 'Properties: not drawn' : `Properties: ${parts.join(', ')}`;
186
+ },
187
+ contentsElsewhere: ({ screen, print }) => {
188
+ const at = (where) => (where === 'here' ? 'here' : where === 'start' ? 'at the start' : 'at the end');
189
+ const parts = [screen && `${at(screen)} on the screen`, print && `${at(print)} in print`].filter(Boolean);
190
+ return parts.length === 0 ? 'Contents: not drawn' : `Contents: ${parts.join(', ')}`;
191
+ },
151
192
  footnote: 'Footnote',
152
193
  comment: 'Comment',
153
194
  attach: 'Attach a file',
@@ -220,6 +261,7 @@ export const ENGLISH = {
220
261
  alignCenter: 'Center',
221
262
  alignRight: 'Align right',
222
263
  alignJustify: 'Justify',
264
+ tableCaption: 'Caption',
223
265
  showMarkdown: 'Show Markdown',
224
266
  copyMarkdown: 'Copy Markdown',
225
267
  sourceTitle: 'The note in Markdown',
@@ -47,13 +47,15 @@ export interface TableBlock {
47
47
  readonly sort: readonly TableSortKey[] | null;
48
48
  readonly page: number;
49
49
  readonly total: string | null;
50
+ /** The title it writes, which names it in a contents and on its appendix (#175), or `null`. */
51
+ readonly title: string | null;
50
52
  /** The mistakes that do not need the table, at most one a line. */
51
53
  readonly problems: readonly TableProblem[];
52
54
  /** The line of each key that was read, for the mistakes found against the table. */
53
55
  readonly lines: Readonly<Partial<Record<TableKey, number>>>;
54
56
  }
55
57
  /** The six keys, in English in every notebook (§7.15). */
56
- export declare const TABLE_KEYS: readonly ["table", "columns", "where", "sort", "page", "total"];
58
+ export declare const TABLE_KEYS: readonly ["table", "columns", "where", "sort", "page", "total", "title"];
57
59
  export type TableKey = (typeof TABLE_KEYS)[number];
58
60
  /** Rows to a page when the block says nothing, and the most it may ask for. */
59
61
  export declare const DEFAULT_PAGE = 25;
@@ -163,6 +165,16 @@ export interface TablePage {
163
165
  readonly total: string | null;
164
166
  /** When the rows were read, in ISO 8601. */
165
167
  readonly readAt: string;
168
+ /**
169
+ * Where each row leads, in the order of `rows` (#171): an address the note's links are drawn to,
170
+ * or `null` for a row that leads nowhere. Left out, no row leads anywhere, as before.
171
+ */
172
+ readonly links?: readonly (string | null)[];
173
+ /**
174
+ * The column whose cell carries the link (#171), when it is among the columns drawn; else the
175
+ * first column drawn.
176
+ */
177
+ readonly linkColumn?: string | null;
166
178
  }
167
179
  /**
168
180
  * Answers a request from a table held in memory, as `SPEC.md` §6.9 and §7.15 say a query is
@@ -12,7 +12,7 @@
12
12
  * a number as well as a date.
13
13
  */
14
14
  /** The six keys, in English in every notebook (§7.15). */
15
- export const TABLE_KEYS = ['table', 'columns', 'where', 'sort', 'page', 'total'];
15
+ export const TABLE_KEYS = ['table', 'columns', 'where', 'sort', 'page', 'total', 'title'];
16
16
  /** Rows to a page when the block says nothing, and the most it may ask for. */
17
17
  export const DEFAULT_PAGE = 25;
18
18
  export const MAX_PAGE = 100;
@@ -136,6 +136,7 @@ export function readTableBlock(value) {
136
136
  columns,
137
137
  where,
138
138
  whereText: values.where ?? null,
139
+ title: values.title ?? null,
139
140
  sort,
140
141
  page,
141
142
  total,
package/dist/theme.d.ts CHANGED
@@ -177,6 +177,15 @@ export interface InlineCodeSlotProps {
177
177
  export interface HeadingSlotProps {
178
178
  readonly level: 1 | 2 | 3 | 4 | 5 | 6;
179
179
  readonly children: ReactNode;
180
+ /**
181
+ * The id a contents entry and a link to `#section` land on (#173), to put on the element the
182
+ * slot draws: the heading's slug, prefixed. Absent inside an embed, whose headings carry none.
183
+ */
184
+ readonly id?: string;
185
+ /** The heading's slug, which a link written as `#slug` names; put it on the element as `data-heading`. */
186
+ readonly slug?: string;
187
+ /** Its number, `1.2`, where the style numbers the headings (#174), to draw before its text. */
188
+ readonly number?: string;
180
189
  }
181
190
  /** A quotation that is not a callout. */
182
191
  export interface BlockquoteSlotProps {
@@ -253,6 +262,16 @@ export interface PropertiesSlotProps {
253
262
  * links: a slot decides how a value looks, never where its links go.
254
263
  */
255
264
  readonly value: (text: string) => ReactNode;
265
+ /**
266
+ * What this call draws (#172): `whole`, the name and the entries at the top, as before; `name`,
267
+ * the name alone, where a `properties` block draws the entries elsewhere; `entries`, the entries
268
+ * alone, where a block or the notebook's settings put them, `name` then `null`. Absent is `whole`.
269
+ */
270
+ readonly part?: 'whole' | 'name' | 'entries';
271
+ /** The title a `properties` block or the notebook's settings give the entries (#172). */
272
+ readonly title?: string;
273
+ /** Whether they start folded, as a block or the notebook's settings say (#172). */
274
+ readonly fold?: 'open' | 'closed';
256
275
  }
257
276
  /**
258
277
  * The switch between reading and editing a note, at its top right (#51). It is drawn only when the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memorysmithapp/markdown-renderer",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "A React component that draws a MemorySmith note exactly as MemorySmith's reading page does.",
5
5
  "keywords": [
6
6
  "markdown",
@@ -69,6 +69,7 @@
69
69
  "@codemirror/state": "6.7.6",
70
70
  "@codemirror/view": "6.43.13",
71
71
  "hast-util-to-jsx-runtime": "2.3.6",
72
+ "mdast-util-to-hast": "13.2.1",
72
73
  "mermaid": "11.17.0",
73
74
  "micromark-util-decode-string": "2.0.1",
74
75
  "react-markdown": "9.1.0",
@@ -80,8 +81,9 @@
80
81
  "unified": "11.0.5"
81
82
  },
82
83
  "devDependencies": {
83
- "@memorysmithapp/markdown-spec": "0.12.0",
84
+ "@memorysmithapp/markdown-spec": "0.13.0",
84
85
  "@types/hast": "3.0.5",
86
+ "@types/mdast": "4.0.4",
85
87
  "@types/react": "19.2.18",
86
88
  "@types/react-dom": "19.2.4",
87
89
  "katex": "0.18.5",
package/structure.css CHANGED
@@ -291,6 +291,34 @@
291
291
  height: auto;
292
292
  max-height: calc(100vh - 4rem);
293
293
  }
294
+ /* The form of a contents block (#173): what the screen and print draw, each
295
+ in a group of its own, its fields shown when it has its own. */
296
+ .markdown .edit-contents-medium {
297
+ display: flex;
298
+ flex-direction: column;
299
+ margin: 0;
300
+ padding: 0;
301
+ border: 0;
302
+ }
303
+ /* A choice a form makes with a box (#172, #175): the box beside its word, and
304
+ the keys of a properties block one to a line, each with its button up. */
305
+ .markdown .edit-attach-form label.edit-contents-check {
306
+ flex-direction: row;
307
+ align-items: center;
308
+ gap: 0.5rem;
309
+ }
310
+ .markdown .edit-properties-keys {
311
+ display: flex;
312
+ flex-direction: column;
313
+ margin: 0;
314
+ padding: 0;
315
+ border: 0;
316
+ }
317
+ .markdown .edit-properties-key {
318
+ display: flex;
319
+ align-items: center;
320
+ justify-content: space-between;
321
+ }
294
322
  .markdown .edit-attach-ways {
295
323
  display: flex;
296
324
  flex: none;
@@ -603,6 +631,32 @@
603
631
  white-space: pre-wrap;
604
632
  overflow-wrap: anywhere;
605
633
  }
634
+ /* A note's contents (#173): a list of the note's headings, nested by level.
635
+ A contents, or the line under a figure or a table (#175), drawn for one
636
+ medium is marked with it and shown only there, so a print the browser makes
637
+ on its own is the print the settings declared. */
638
+ @media print {
639
+ .markdown [data-media='screen'] {
640
+ display: none;
641
+ }
642
+ }
643
+ @media not print {
644
+ .markdown [data-media='print'] {
645
+ display: none;
646
+ }
647
+ }
648
+ /* The line under a figure stands on a line of its own, below the picture. */
649
+ .markdown .figure-caption {
650
+ display: block;
651
+ }
652
+ .markdown .contents-entries {
653
+ margin: 0;
654
+ padding-inline-start: 0;
655
+ list-style: none;
656
+ }
657
+ .markdown .contents-entries .contents-entries {
658
+ padding-inline-start: 1.25em;
659
+ }
606
660
  /* A table printed as an appendix opens a page of its own (#165); a host lays
607
661
  `.table-appendix` on a named page of its own to choose its orientation. */
608
662
  @media print {
package/theme-default.css CHANGED
@@ -531,6 +531,48 @@
531
531
  margin-block: 0 var(--ms-p-spacing);
532
532
  font-size: var(--ms-h3-size);
533
533
  }
534
+ /* A heading's number, as the style numbers the outline (#174), and the same
535
+ number before an entry of the contents: the heading's own colour, a little
536
+ softer, so the number reads as the heading's and not as its text. */
537
+ .markdown .heading-number,
538
+ .markdown .contents-number {
539
+ font-variant-numeric: tabular-nums;
540
+ opacity: 0.75;
541
+ }
542
+ /* The line under a figure or a table (#175): its number and what names it,
543
+ small and soft, as a caption is. */
544
+ .markdown .figure-caption,
545
+ .markdown .table-caption {
546
+ margin-block: 0.35rem var(--ms-p-spacing);
547
+ font-size: 0.9em;
548
+ color: var(--ms-text-soft);
549
+ }
550
+ .markdown .caption-number {
551
+ font-weight: 600;
552
+ }
553
+ /* A note's contents (#173): each list under its title, its entries the
554
+ note's links in the colour of the text, so the list reads as a list. */
555
+ .markdown .contents {
556
+ margin-block: var(--ms-p-spacing);
557
+ }
558
+ .markdown .contents-list + .contents-list {
559
+ margin-block-start: var(--ms-p-spacing);
560
+ }
561
+ .markdown .contents-title {
562
+ margin-block: 0 0.35rem;
563
+ font-weight: var(--ms-heading-weight);
564
+ color: var(--ms-heading-color);
565
+ }
566
+ .markdown .contents-item {
567
+ margin-block: 0.15rem;
568
+ }
569
+ .markdown .contents-entry {
570
+ color: inherit;
571
+ text-decoration: none;
572
+ }
573
+ .markdown .contents-entry:hover {
574
+ text-decoration: underline;
575
+ }
534
576
  /* A block that cannot be answered says why, in place of its table. */
535
577
  .markdown .data-table-problems {
536
578
  margin-block: var(--ms-p-spacing);
@@ -2007,6 +2049,20 @@
2007
2049
  .markdown .markdown-editor .cm-ms-block {
2008
2050
  font-family: var(--ms-face, var(--ms-font-sans));
2009
2051
  }
2052
+ /* A contents block in edit mode that draws nothing here: where it is drawn,
2053
+ small and soft, as a style block's opening says what it sets (#173). */
2054
+ .markdown .contents-elsewhere {
2055
+ margin-block: var(--ms-p-spacing);
2056
+ font-family: var(--ms-font-display);
2057
+ font-size: 0.8rem;
2058
+ color: var(--ms-text-soft);
2059
+ cursor: pointer;
2060
+ }
2061
+ .markdown .edit-contents-medium {
2062
+ gap: 0.5rem;
2063
+ padding-block-start: 0.5rem;
2064
+ border-top: 1px solid var(--ms-border);
2065
+ }
2010
2066
  /* A style block's opening while the author is elsewhere: what it sets, small
2011
2067
  and soft, over a rule that its closing fence draws again at its end. */
2012
2068
  .markdown .edit-style-summary {