svelte-rtf-editor 1.13.0 → 1.16.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 CHANGED
@@ -13,7 +13,11 @@ RTF viewer and rich-text editor components for **Svelte 5**.
13
13
  - **`InkEditor`** — Full rich-text editor that reads and writes RTF, built on `contenteditable`
14
14
  - Formatting toolbar: bold, italic, underline, strikethrough, font colour
15
15
  - Block-level controls: headings (H1–H3), paragraph, blockquote, code block
16
- - Images: upload, paste or drag-and-drop, with a description below each picture, drag-to-resize and left/centre/right placement — embedded in the RTF, not linked
16
+ - Bullet and numbered lists, and lists within lists, made the same in every browser. See [Lists](#lists)
17
+ - Undo and Redo of everything the editor changes, a picture or a table put in as much as typing. See [Undo and Redo](#undo-and-redo)
18
+ - Line spacing, and the space before and after a paragraph, in points; and the gap between a list's bullets or numbers and its text. See [Line and paragraph spacing](#line-and-paragraph-spacing)
19
+ - Tables: insert one with or without borders; the borders are in the RTF. See [Tables](#tables)
20
+ - Images: upload, paste or drag-and-drop, with a description below each picture, drag-to-resize, left/centre/right placement, move up and down, and two or more side by side, each with its own description — embedded in the RTF, not linked
17
21
  - Import an RTF file from disk; export as RTF, HTML, or Markdown
18
22
  - Optional auto-save to `localStorage` (off unless asked for)
19
23
  - HTML from outside (the `content` prop, `setHTML`, a restored draft, a paste, a drop) is made safe before it is shown. See [HTML from outside](#html-from-outside)
@@ -140,6 +144,7 @@ Pass an HTML string as `content`. If the content is already RTF, convert it firs
140
144
  | `fontSize` | `number` | `12` | Body text size in points, on screen and in the RTF |
141
145
  | `fontSizes` | `number[]` | `[8, 9, 10, 11, 12, 14, 16, 18, 20, 24, 28, 36]` | The sizes, in points, the toolbar's size list offers for selected text. The body size is always among them; `[]` takes the list off the toolbar. See [Size of selected text](#size-of-selected-text) |
142
146
  | `fonts` | `string[]` | `[]` | The fonts the toolbar's font list offers for selected text, beside the document's own. `[]` means no font list, and one font for the whole document. See [Fonts for selected text](#fonts-for-selected-text) |
147
+ | `fontMenu` | `boolean` | `false` | A right-click on the text opens a menu of `fonts` in place of the browser's menu. Shift + right-click still opens the browser's. See [The font menu](#the-font-menu) |
143
148
  | `keepAttributes` | `string[]` | `[]` | `data-` attributes of your own that stay on HTML you set or the user pastes. See [HTML from outside](#html-from-outside) |
144
149
  | `keepClasses` | `string[]` | `[]` | Class names of your own that stay the same way |
145
150
 
@@ -167,6 +172,12 @@ editor.importRtf() // → void — open the file picker to import .rtf
167
172
  editor.setFontSize(14) // → void — size, in points, of the selected text, or of what is typed next
168
173
  editor.setFont('Calibri') // → void — font of the selected text, or of what is typed next: one of `fonts`, or '' for the document font
169
174
  editor.clearFormatting() // → void — take bold, italic, underline, strike, color, size and font off the selected text
175
+ editor.setLineSpacing(1.5) // → void — line spacing of the selected paragraphs, in lines; null for the document's own
176
+ editor.setParagraphSpacing({ before: 6, after: 12 }) // → void — space before and after them, in points; either may be left out, 0 or null is none
177
+ editor.setListMarkerGap(27) // → void — gap between the markers and the text of the selected lists, in points (6 to 144); null for the quarter inch
178
+ editor.insertTable(3, 2, { borders: true, header: false }) // → void — a table of empty cells after the paragraph the caret is in
179
+ editor.undo() // → boolean — take back the last step; false if there was none
180
+ editor.redo() // → boolean — make a step that was taken back again; false if there was none
170
181
  ```
171
182
 
172
183
  #### Auto-save
@@ -352,6 +363,24 @@ The list is the limit. A font that is not on it is not offered, is taken off HTM
352
363
  - Code stays in Courier New whatever font is around it. A monospace font you offer is written as that font, and read back as code, which is what a reader makes of text in a monospace font.
353
364
  - [Clear formatting](#clear-formatting) takes a font off with the rest.
354
365
 
366
+ #### The font menu
367
+
368
+ The font list is in the toolbar. Set `fontMenu` and a right-click on the text opens the same fonts as a menu as well, where the pointer is:
369
+
370
+ ```svelte
371
+ <InkEditor fonts={['Georgia', 'Calibri, Carlito, sans-serif', 'Arial']} fontMenu />
372
+ ```
373
+
374
+ The menu shows the document font first, then yours, each in its own font, with the font of the selected text checked. Choosing one sets the font of the selection, exactly as the toolbar's list does, and Undo takes it off again. On a Mac a right-click selects the word it is on, so a right-click on a word and a choice from the menu are enough to set that word.
375
+
376
+ The menu is off by default because it takes the place of the browser's own menu, and with it the spelling suggestions, Copy and Paste. The browser's menu is still there when you need it:
377
+
378
+ - Shift + right-click opens the browser's menu. The foot of the font menu says so.
379
+ - A right-click on a link or a picture opens the browser's menu, which has what a link or a picture needs (Open link, Copy image).
380
+ - Without `fonts`, or with `readonly`, `fontMenu` changes nothing.
381
+
382
+ From the keyboard, the menu key or Shift+F10 opens the menu at the caret, where the browser sends the page the menu's event (Chromium does; check the others in your own setup). In the menu, the arrow keys, Home and End move, Enter or Space chooses, and Escape or Tab closes it and gives the text the keyboard back. A click anywhere else, a scroll, or the window losing the keyboard closes it too.
383
+
355
384
  ### Clear formatting
356
385
 
357
386
  The toolbar's Clear formatting button, next to the text color, takes the formatting off the selected text. `editor.clearFormatting()` does the same from your own toolbar. With nothing selected it changes nothing in the document.
@@ -367,12 +396,40 @@ The toolbar's Clear formatting button, next to the text color, takes the formatt
367
396
 
368
397
  - Only the selected words change: clearing two words of a bold sentence leaves the rest bold.
369
398
  - The result is the same HTML in Chromium, Firefox and Safari (the browser tests run in all three engines, on every push). The browsers' own command is not: one takes a paragraph's alignment with its color, another leaves the color on the paragraph, a third takes out the element your mark is on.
370
- - Undo puts the formatting back and Redo takes it off again, from the keyboard and from the toolbar, also after more has been typed and undone. In Safari one Undo may take back the step before it as well.
371
- - On a very long selection it takes time, and four times as long for twice the length. The time is the browser's own command, which the editor uses so that the browser's Undo knows of the change: measured on paragraphs with four formatted runs each, 250 of them (about eight pages) clear in a quarter of a second in Chromium, 1,000 in three seconds, 2,000 in twelve; Safari's engine takes about two thirds of that and Firefox a tenth. A report of ordinary length is not affected.
399
+ - Undo puts the formatting back and Redo takes it off again, from the keyboard and from the toolbar, also after more has been typed and undone.
400
+ - On a very long selection it takes time, and four times as long for twice the length. The time is the browser's own command: measured on paragraphs with four formatted runs each, 250 of them (about eight pages) clear in a quarter of a second in Chromium, 1,000 in three seconds, 2,000 in twelve; Safari's engine takes about two thirds of that and Firefox a tenth. A report of ordinary length is not affected.
372
401
  - A mark stays whole in all three browsers, whatever part of it is selected. In Firefox the words inside it keep the bold or italic they have there: its command cannot clear them without cutting the mark in two.
373
402
 
374
403
  ---
375
404
 
405
+ ## Lists
406
+
407
+ The toolbar's **Bullet list** and **Numbered list** buttons are the editor's own, not the browser's list commands, so a list is made the same in Chrome, Edge, Safari and Firefox, and its HTML is the same.
408
+
409
+ - **Making a list.** Every line the selection touches becomes an item: a paragraph, a heading, or a line of words in no paragraph. Lines next to each other are one list, and a line made an item next to a list of the same kind is an item of that list, whichever is made first; the numbers run on. The caret stays in the words where it was.
410
+ - **Taking it off.** The button of the kind the items already are makes them paragraphs again, one paragraph for each item. One item taken off in the middle leaves a list before it and a list after it.
411
+ - **The other kind.** With the caret in a list, the other button changes the whole list, bullets to numbers or back. With items selected, it changes those items.
412
+ - **A list within a list.** `Tab` at the start of an item, or Increase indent anywhere in it, puts the item under the item before it; `Shift+Tab` or Decrease indent takes it out again. Several items selected go together. The first item of a list has none before it to go under: there Increase indent moves the whole list, as it moves a paragraph, and `Tab` types a tab.
413
+ - **Leaving a list.** `Enter` in an item with nothing in it, and `Backspace` at the start of an item, take the item one list out; from a list that is in no other, it becomes a paragraph.
414
+ - The buttons are lit while the caret is in a list of their kind. In a list within a list, the kind is the inner list's.
415
+ - Not made an item: a picture with its caption, a table as a whole (a line inside a cell is), a code block.
416
+ - A lettered list or one in Roman numerals (`<ol type="A">`) is kept as it is and takes new items; the buttons make bullets and plain numbers only.
417
+
418
+ How a list is written to RTF and read back is under [What is written, and what is read back](#what-is-written-and-what-is-read-back).
419
+
420
+ ## Undo and Redo
421
+
422
+ The editor keeps its own history. `Ctrl+Z` / `Cmd+Z`, `Ctrl+Shift+Z` / `Cmd+Shift+Z`, `Ctrl+Y`, the toolbar's buttons, the browser's Edit menu, and `editor.undo()` / `editor.redo()` all go through it.
423
+
424
+ A browser's history knows only its own commands and what was typed. It knew nothing of a picture or a table put in, a picture moved, placed beside another or resized, an indent, a spacing, or a list: its Undo went past those to the typing before them, and after some of them it could undo nothing at all. The editor's history takes back whatever changed the document, in the order it was done.
425
+
426
+ - **A step** is one press of a button, one paste, one drop, a new paragraph, or a run of typing. Typing is one step until the writer pauses for a second, moves the caret, or changes from typing to deleting.
427
+ - **The caret** is put back where it was before the step.
428
+ - **Redo** makes a step again that Undo took back, until something else is changed.
429
+ - **A new document starts a new history.** After `setHTML()`, `clear()`, or an RTF file imported, Undo does not lead back into the document that was there before.
430
+ - What Undo puts back is checked as everything that reaches the editor is (see [HTML from outside](#html-from-outside)).
431
+ - 200 steps are kept. A step holds the document's HTML with each embedded picture kept once, not once per step, so a report with megabytes of pictures does not hold them 200 times.
432
+
376
433
  ## Paragraph formatting
377
434
 
378
435
  A `<p>` or `<div>` keeps its own indents, spacing and tab stops in the RTF, so a layout made of ordinary paragraphs, such as a bold label, a tab, and text in a column with later lines hanging under it, reaches the receiving system:
@@ -383,16 +440,40 @@ A `<p>` or `<div>` keeps its own indents, spacing and tab stops in the RTF, so a
383
440
  | `margin-right: 0.5in` | `\ri720` |
384
441
  | `text-indent: -1.75in` | `\fi-2520` |
385
442
  | `margin-top: 5pt` / `margin-bottom: 5pt` | `\sb100` / `\sa100` |
443
+ | `line-height: 1.5` (or `150%`) | `\sl360\slmult1` |
444
+ | `line-height: 14pt` | `\sl-280\slmult0` (exactly 14 pt) |
386
445
  | `break-after: avoid` or `page-break-after: avoid` | `\keepn` |
387
446
  | `data-rtf-tab-stops="1.75in"` (comma-separated) | `\tx2520` |
388
447
 
389
448
  - Lengths in `in`, `pt`, `cm`, `mm` or `px` (15 twips per px), rounded to whole twips. Only `text-indent` may be negative. A value the writer cannot read, or zero, writes nothing.
390
449
  - CSS has no absolute tab stop, hence the `data-` attribute. On screen, `white-space: pre-wrap; tab-size: 1.75in` with that hanging indent puts the browser's first stop at the same place, and `pre-wrap` makes the writer send the tab as `\tab`.
391
450
  - `margin-left` adds to the indent of the blocks around the paragraph (an indent pasted from a browser, or a `<div>` with a margin that holds paragraphs), and is written as one `\li`.
392
- - Inside a table cell the cell declares its own paragraph: only alignment and the left indent are written there, not the right or first-line indent, spacing, tab stops or keep-with-next.
451
+ - Inside a table cell the cell declares its own paragraph: alignment, the left indent and spacing are written there, not the right or first-line indent, tab stops or keep-with-next.
393
452
  - `rtfToHtml` reads the three indents back, in points: `\li720\ri720\fi-720` becomes `margin-left:36pt;margin-right:36pt;text-indent:-36pt`, and `RtfViewer` shows them. As in RTF, they hold from one paragraph to the next until `\pard`. Indents inside a table cell are not read.
394
453
  - A heading outside a table cell also writes its right and first-line indents, so a heading read from RTF with a hanging number goes back as it came. A picture is read with a left margin only, where its line starts.
395
- - `rtfToHtml` does not yet read spacing, keep-with-next or tab stops back.
454
+ - `rtfToHtml` reads spacing back too: `\sb120\sa240\sl360\slmult1` becomes `margin-top:6pt;margin-bottom:12pt;line-height:1.5`, on a paragraph, a heading, a list item (as the `<li>`'s style) or a picture, and holds until `\pard` as the indents do. Line spacing "at least" (a positive `\sl` without `\slmult1`) is not something CSS can say, and is left out. In a table cell where a paragraph is spaced, as Word writes a cell's paragraphs, each of the cell's paragraphs is read as a `<p>` with its spacing; a cell with none spaced is read as lines, as before.
455
+ - `rtfToHtml` does not yet read keep-with-next or tab stops back.
456
+
457
+ ### Line and paragraph spacing
458
+
459
+ The **Spacing** list in the toolbar sets, for the paragraphs the selection touches:
460
+
461
+ - **Line spacing**: 1, 1.15, 1.5 or 2 lines, or Default (the document's own).
462
+ - **Space before paragraph** and **Space after paragraph**: 0, 6 or 12 pt.
463
+
464
+ The list marks what the paragraph at the caret has, and shows a value it does not offer (`7.5 pt` from a pasted document) so that it can be seen and changed. A heading takes spacing as a paragraph does, and so does a list item: the item the caret is in, as one paragraph, its style on the `<li>`. In the RTF its space before is on its first paragraph, its space after on its last, and its line spacing on each. In a table cell the paragraph the caret is in is spaced; a line typed straight into the cell is made a paragraph first. With a picture selected, the space before and after is the picture's, which is how the distance between two pictures, one under the other, is set. Each change is one step for Undo.
465
+
466
+ `setLineSpacing(lines)` and `setParagraphSpacing({ before, after })` do the same from code, with any value: up to 10 lines, and up to 144 pt. Copy format carries a paragraph's spacing with its alignment and indents.
467
+
468
+ #### The gap after a list's bullets or numbers
469
+
470
+ With the caret in a list, the Spacing list also offers **Bullet or number gap**: how far each item's text starts from its bullet or number, 9, 18, 27 or 36 pt, or Default. It is Word's *text indent* of a list: the marker stays where it is, and the text moves. `setListMarkerGap(points)` sets any gap from 6 to 144 pt, and `null` takes it off. It is set on the lists the selection touches, the innermost for an item of a list within a list, and is one step for Undo.
471
+
472
+ - **In the HTML** the gap is the list's own `padding-left` (`<ol style="padding-left: 27pt;">`), which is that distance in CSS too. A list without one has the quarter inch (18 pt) every list always had, and is shown and written as before.
473
+ - **On the screen** the editor draws the bullets and numbers of a list with a gap itself, at the list's edge, where Word has them; a browser draws its own markers against the text, by how wide they are. The numbers are worked out as the RTF writer works them out, from the list's `start` and `type` and an item's own `value`. They are written on each item as `data-ink-marker`, for the screen only: `getHTML()`, `onchange`, `onsave`, the draft and the HTML export do not have them.
474
+ - **In the RTF** each item hangs by the gap: 27 pt is `\li900\fi-540`, the marker still a quarter inch in. `rtfToHtml` reads a list hung by any gap from 6 to 144 pt as a list with that gap, Word's own lists hung by 0.2 in among them, and lists whose markers stand at one place are at one level whatever their gaps.
475
+
476
+ In the editor and in `RtfViewer` a picture has no space of its own around it, as it has none in the RTF: what is set is what shows. (Through 1.13 a picture was drawn with 20 px above and below it that no reader of the RTF showed.)
396
477
 
397
478
  ---
398
479
 
@@ -417,9 +498,10 @@ A `<p>` or `<div>` keeps its own indents, spacing and tab stops in the RTF, so a
417
498
  | `<table>` | one `\trowd … \row` per row; see [Tables](#tables) | `<table>` |
418
499
  | `<br>` | `\line` | `<br>` |
419
500
 
420
- - **Lists.** Only the shape above is read back as a list: a bullet or `N.`, a tab, and a paragraph that hangs by 360 twips and has no right indent or alignment of its own. Word's lists have that shape and are read as lists, including the bullet it writes in a `{\listtext}` group. Anything else stays the paragraph it is, marker and all, because it could not be written back the same: a line typed as `- Invasive adenocarcinoma.`, a list hung by another distance, one marked `a)` or `1)`, a centered one. A list in a table cell is read as lines of text.
501
+ - **The HTML of a list made in the editor** is a `<ul>` or `<ol>` beside the paragraphs around it, and a list within a list is inside the item it is under (`<ul><li>skin<ul><li>left arm</li></ul></li></ul>`): the shape `rtfToHtml` returns, so what is kept reads back as the same document. See [Lists](#lists). A block a browser leaves inside a paragraph (Firefox leaves pasted paragraphs inside the paragraph they were pasted in), which no HTML can say, is put beside the paragraph as soon as it is there, and `getHTML()`, `onchange`, `onsave`, the draft kept by `autosave` and the HTML export never hand one out.
502
+ - **Lists.** Only the shape above is read back as a list: a bullet or `N.`, a tab, and a paragraph that hangs by 360 twips and has no right indent or alignment of its own. Word's lists have that shape and are read as lists, including the bullet it writes in a `{\listtext}` group. A paragraph hung by another distance, from 6 to 144 pt, is a list with that gap after its markers (see [the gap after a list's bullets or numbers](#the-gap-after-a-lists-bullets-or-numbers)). Anything else stays the paragraph it is, marker and all, because it could not be written back the same: a line typed as `- Invasive adenocarcinoma.`, one marked `a)` or `1)`, a centered one. A list in a table cell is read as lines of text.
421
503
  - **Lettered lists.** A list numbered in letters or Roman numerals (`type="A"`, `a`, `I`, `i`, or the same as `list-style-type`, on the list or on each item as Google Docs writes it) is written with the markers the screen shows, from the list's `start` and an item's own `value`: specimen parts lettered A, B, C are A, B, C in the RTF, and "see part B" finds its item. Through 1.12.0 they were written 1, 2, 3. Such a list is read back as a list of its kind. Letters that are numerals too are told apart by what comes next: `C.` before `D.` is the third letter, before `CI.` it is a hundred. A letter and a tab typed on a line of another shape (`A.`, a tab, the specimen, as other systems write a report) stay what was typed.
422
- - **Colors and backgrounds.** A text color is written (`\cf`). A background is not, neither a highlight nor the shading of a table cell, and shading in an RTF is not shown: every word ends up on white. So a color that can be read on its background and not on white is left out, and the words are in the reader's own color: the white header of a table with a dark header row, a sentence copied from a page with a dark theme. Through 1.12.0 such words were written white, and could not be seen in the report. A color that can be read on white is written whatever is behind it, and a light color with no background behind it is written as the screen shows it. The editor still shows a pasted table with its shading; the RTF has the same words without it.
504
+ - **Colors and backgrounds.** A text color is written (`\cf`). A background is not, neither a highlight nor the shading of a table cell, and shading in an RTF is not shown: every word ends up on white. So a color that can be read on its background and not on white is left out, and the words are in the reader's own color: the white header of a table with a dark header row, a sentence copied from a page with a dark theme. Through 1.12.0 such words were written white, and could not be seen in the report. A color that can be read on white is written whatever is behind it, and a light color with no background behind it is written as the screen shows it. The editor still shows a pasted table with its shading; the RTF has the same words without it. A picture or a gradient as a background is not kept at all (nothing is loaded for a document), so light words that stood on one are put in the page's own color when the document is made safe, in the editor as in the RTF, unless there is a background color behind them still.
423
505
  - **List items.** A paragraph inside an item (`<li><p>…</p></li>`, as Word and Google Docs paste a list) is the item's text; a second paragraph in the item is a line under it. A list written straight inside a list (`<ul><ul>`) is one level deeper. An item with no list around it is written as a bulleted line. The list a browser's own list command makes, which the toolbar's list buttons run, is left inside the paragraph it was made from (`<p><ul>…</ul></p>`); it is written as the list alone.
424
506
  - **Headings.** A paragraph is read as a heading when all of its text is at a heading's size and all of it is bold, as every heading `htmlToRtf` writes is. Size alone does not make a heading: a report set in 14 pt throughout is 14 pt paragraphs, with the words that were bold still the only bold ones. (Through 1.9.0, at a 12 pt body size, large text was read as a heading whether bold or not, and was saved bold.) A large word in an ordinary paragraph is a large word. A heading set larger than its level keeps that size.
425
507
  - **Links.** A link is read back only for an address `isSafeLinkUrl` accepts, the same test the writer applies: an absolute web, mail or phone address. A field with a `javascript:`, `data:` or `file:` address, a relative or network path, or a link to a bookmark is read as its text alone. A web link opens in a tab of its own, so a click in `RtfViewer` does not replace your application. A document with a link carries the link color as the first entry of its color table (`\red0\green0\blue255`); a document without one is written as before.
@@ -437,7 +519,9 @@ RTF has no table element: each row says where its cells end (`\cellx`), so colum
437
519
  - **`<caption>`** is written as a centered paragraph before the table, where a browser shows it, and is read back as that paragraph.
438
520
  - **A column no cell starts in is not a column.** `colspan="100"` on a cell meant to cross the whole table adds none.
439
521
  - **A row short of cells** is filled with empty ones, so its edges are the table's.
440
- - **`<th>`** gets a bottom border, on that cell only, which is how `rtfToHtml` knows a header cell: a bare `\clbrdrb\brdrs` and no border on any other side. A bottom border with a width or a color (`\brdrw`, `\brdrcf`), which is how Word and TextEdit write a line someone drew under a cell, is not a header: a signature line stays an ordinary cell.
522
+ - **Borders.** A cell's own borders are written, each side by itself: `border: 1px solid` is `\clbrdrt\brdrs\brdrw15` and the same for `l`, `b` and `r`. The line is `solid`, `double`, `dotted` or `dashed` (any other that draws one is a plain line), the width is in twentieths of a point up to the 3.75 pt RTF allows, and a color other than black is written by its place in the color table (`\brdrcf`). `rtfToHtml` reads them back as `border:1px solid` where the four sides are one, else as `border-top`, `border-right`, and so on. A border set on the `<table>` or by a style sheet is not a cell's own, and is not written.
523
+ - **Insert table.** The toolbar's table button asks for rows and columns (up to 50 by 12), whether the cells have borders, and whether the first row is a header, and puts the table after the paragraph the caret is in. `insertTable(rows, columns, { borders, header })` does the same from code. A table with no borders has none in the RTF; while it is edited its cells are drawn with a faint dashed line, which is not in `getHTML()` or the RTF. Adding and removing rows and columns is not there yet.
524
+ - **`<th>`** with no borders of its own gets a bottom border, on that cell only, which is how `rtfToHtml` knows a header cell: a bare `\clbrdrb\brdrs` and no border on any other side. A header cell that has borders is written with those, and marked in what it holds by `{\*\inkth}`, a group other readers skip: Word and TextEdit put a border on every cell of a gridded table, so a border cannot say which cells are headers there. A bottom border with a width or a color (`\brdrw`, `\brdrcf`), which is how Word and TextEdit write a line someone drew under a cell, is not a header: a signature line stays an ordinary cell.
441
525
  - **Each cell ends with `\cell` inside its group**, with no `\par` before it, and the last row of a table carries `\lastrow`. Through 1.9.0 a cell ended `\par}\cell`, which Apple's reader (TextEdit, Pages, Mail) showed as an empty second paragraph in every cell, and two tables with nothing between them were read back as one. `rtfToHtml` reads both shapes.
442
526
  - **`<thead>` and `<tfoot>`** are written first and last, wherever the source has them.
443
527
  - **A cell's `text-align`** is written on its paragraphs (`\qc`, `\qr`, `\qj`), and read back onto the cell.
@@ -489,7 +573,7 @@ Size is not the only way to exhaust a page: a file of nothing but braces is smal
489
573
 
490
574
  ### Markdown export
491
575
 
492
- `htmlToMarkdown` writes a table as a Markdown table (a merged cell where it starts, with the cells it covers left empty, since Markdown has none), a numbered list from its `start`, a list numbered in letters or Roman numerals as bullets that begin with their marker (`- B. Right breast, biopsy`: Markdown numbers in digits only), and `<h4>` to `<h6>` as headings. Characters that Markdown would read as markup are escaped in text (`*`, `_`, `` ` ``, `#`, `[`, `]`, `<`, `~`, `\` and `|`), and so are `-`, `+`, `>` and `1.` at the start of a line: a report line typed as `- Benign.` stays that line. A link with an address `isSafeLinkUrl` refuses is written as its text alone.
576
+ `htmlToMarkdown` writes a table as a Markdown table (a merged cell where it starts, with the cells it covers left empty, since Markdown has none), a numbered list from its `start` (an item with a number of its own, `<li value="7">`, and a numbered list right after another, are written with the other mark, `7)`: Markdown counts on from a list's first number whatever the numbers after it say, and the other mark is what starts a new list at its own number), a list numbered in letters or Roman numerals as bullets that begin with their marker (`- B. Right breast, biopsy`: Markdown numbers in digits only), and `<h4>` to `<h6>` as headings. Characters that Markdown would read as markup are escaped in text (`*`, `_`, `` ` ``, `#`, `[`, `]`, `<`, `~`, `\` and `|`), and so are `-`, `+`, `>` and `1.` at the start of a line: a report line typed as `- Benign.` stays that line. A link with an address `isSafeLinkUrl` refuses is written as its text alone.
493
577
 
494
578
  A line break in a paragraph is a hard break (two spaces before the new line; a `<br>` in a heading or a table cell, which are one line). Text typed before a block is a paragraph of its own, and so is each `<div>`, `<section>`, `<dt>` and `<dd>`. A quotation of several paragraphs, or one holding a code block, carries its `>` on every line. A list written straight inside a list is nested under the item before it. Bold with a space inside the tag (`<b>diagnosis </b>`) is written with the space outside the marks, and `<b style="font-weight:normal">` is not bold. `<sup>`, `<sub>`, `<u>` and `<ins>` are written as those tags, which Markdown allows, and `<del>` as `~~`. A table's `<caption>` is a line before the table; a figure writes everything it holds, then its caption. `&copy;` typed as text stays those characters, and a line of `---` or `===` is escaped so that it is not a rule or a heading. What the screen does not show (`<style>`, `<script>`, `hidden`, `display:none`, `visibility:hidden`, `mso-hide:all`) is not written.
495
579
 
@@ -517,6 +601,10 @@ The components use CSS custom properties with sensible fallbacks, so they work o
517
601
  }
518
602
  ```
519
603
 
604
+ ### In a page with styles of its own
605
+
606
+ The editor and the viewer say for themselves how a list is shown: a bullet, a circle and a square by depth, and numbers. A page that takes the markers off its own lists (`ol, ul { list-style: none }`, as Tailwind's base styles and most CSS resets do) does not take them off a document's; through 1.13 a list in such a page was indented lines with nothing in front of them. A list that says its own marker by `list-style-type` keeps it. One that says it by `type="A"` alone is still at the mercy of such a rule: CSS cannot tell `type="A"` from `type="a"` in every browser, so the editor has no rule of its own for it.
607
+
520
608
  ---
521
609
 
522
610
  ## Keyboard shortcuts
@@ -532,11 +620,14 @@ The components use CSS custom properties with sensible fallbacks, so they work o
532
620
  | `Backspace` / `Delete` | Remove the selected image |
533
621
  | `Ctrl+]` / `Cmd+]` | Increase indent of the selected paragraphs by 0.5 in (RTF `\li720` per step) |
534
622
  | `Ctrl+[` / `Cmd+[` | Decrease indent |
535
- | `Tab` | Insert a tab (sent to RTF as `\tab`); two spaces in a code block. With several lines selected, increase their indent |
536
- | `Shift+Tab` | Remove one tab from the start of the line. With several lines selected, decrease their indent |
623
+ | `Tab` | Insert a tab (sent to RTF as `\tab`); two spaces in a code block. With several lines selected, increase their indent. At the start of a list item, put the item under the item before it |
624
+ | `Shift+Tab` | Remove one tab from the start of the line. With several lines selected, decrease their indent. In an item of a list within a list, take the item out from under the item it is under |
625
+ | `Enter` in an empty list item, `Backspace` at the start of one | Take the item out of its list: one list out, then a paragraph |
626
+ | `Ctrl+Z` / `Cmd+Z` | Undo |
627
+ | `Ctrl+Shift+Z` / `Cmd+Shift+Z`, `Ctrl+Y` | Redo |
537
628
  | `Esc`, then `Tab` / `Shift+Tab` | Move focus out of the editor |
538
629
 
539
- The toolbar's Increase indent and Decrease indent buttons do the same as `Ctrl+]` and `Ctrl+[`. Undo reverses an indent step until the next edit.
630
+ The toolbar's Increase indent and Decrease indent buttons do the same as `Ctrl+]` and `Ctrl+[`. Each press is one Undo step. In a list they put the selected items under the item before them, and take them out again (see [Lists](#lists)).
540
631
 
541
632
  Four more toolbar buttons set the other two RTF indents, 0.5 in per press, on a paragraph outside a table cell (not on a list, a heading, a quotation or a code block):
542
633
 
@@ -594,7 +685,19 @@ Three ways to add a picture:
594
685
 
595
686
  Each picture is inserted as a `<figure>` with a `<figcaption>` under it. Click the caption line and type to describe the image — the description travels with the picture through every export. Insert as many images as a document needs.
596
687
 
597
- Click an image to select it. A frame appears with corner handles you can drag to resize (the aspect ratio is kept and the width is capped at the editor's text width), buttons for 25% / 50% / 100% width, left / centre / right placement, a shortcut to its description, and a remove button.
688
+ Click an image to select it. A frame appears with corner handles you can drag to resize (the aspect ratio is kept and the width is capped at the editor's text width), buttons for 25% / 50% / 100% width, left / centre / right placement, moving it, a shortcut to its description, and a remove button.
689
+
690
+ ### Where a picture is on the page
691
+
692
+ - **Move up** and **Move down** take the selected picture, with its description, over the block above or below it: a paragraph, a table, another picture.
693
+ - **Place beside the picture above** puts the selected picture to the right of the picture before it, each with its own description under it. A third and a fourth can join the row. Pictures too wide for their share of the page are made to fit; after that each is resized and aligned inside its own share, which is also how the distance between two of them is set (the left one aligned right and the right one aligned left are as close as they go).
694
+ - **Dragging a picture** with the mouse does the same as the buttons. Dropped on the left or right half of another picture, it is put beside it, in a row, each picture with its own description under it; dropped on a picture of a row, it joins the row there, or changes places in its own row; dropped anywhere else, it is moved there whole, with its description, before or after the block it is dropped on. (Through 1.13 the browser moved the picture alone into the line it was dropped in, inside the other picture's figure, and its description was left behind as an empty line.)
695
+ - **Gap** sets an exact distance between the pictures of a row, in points (72 pt = 1 inch), from the field in the frame of any picture in the row. Each picture's cell is then as wide as the picture and the gap is an empty cell between each two, so the distance is the same on the screen, in the RTF (`\cellx` edges, no padding inside a cell) and in Word; the row is as wide as what it holds, not stretched across the page. Pictures too wide for the page together with their gaps are made smaller alike. A picture that joins the row or leaves it keeps the gap; resizing one keeps it too. Left empty, the row shares the page equally again. `rtfToHtml` reads such a row back with the same widths.
696
+ - **Place on its own line** takes a picture out of a row, and puts it under the row. Removing a picture from a row closes the row up; the last picture left is on a line of its own again.
697
+ - A row of pictures is moved up and down as one.
698
+ - **The space above and below a picture** is set from the toolbar's Spacing list while the picture is selected (see [Line and paragraph spacing](#line-and-paragraph-spacing)). A row of pictures has none to set.
699
+
700
+ In the document a row of pictures is a table of one row with no borders, a `<figure>` in each cell (and, with a gap set, an empty cell between each two), and that is what the RTF holds: a row of cells, each with a picture and its description. Word and other readers show the pictures side by side; `rtfToHtml` reads the row back as it was written. A picture in a row that has no description is read back as the picture alone in its cell, and is given a `<figure>` again when one is typed (the frame's Edit description button). There is no wrapping of text around a picture: RTF can say it, but the systems these documents go to do not show it reliably.
598
701
 
599
702
  ### How images are stored
600
703
 
@@ -161,6 +161,29 @@
161
161
  margin-bottom: 0;
162
162
  }
163
163
 
164
+ /* The bullets and the numbers are said here: a page that takes them off its own lists
165
+ (`ol, ul { list-style: none }`, as Tailwind's base styles and most CSS resets do) does
166
+ not take them off a document's. A list that says its own marker keeps it. */
167
+ .rtf-viewer :global(ul:not([type])) {
168
+ list-style-type: disc;
169
+ }
170
+
171
+ .rtf-viewer :global(:is(ul, ol) ul:not([type])) {
172
+ list-style-type: circle;
173
+ }
174
+
175
+ .rtf-viewer :global(:is(ul, ol) :is(ul, ol) ul:not([type])) {
176
+ list-style-type: square;
177
+ }
178
+
179
+ .rtf-viewer :global(ol:not([type])) {
180
+ list-style-type: decimal;
181
+ }
182
+
183
+ .rtf-viewer :global(li) {
184
+ display: list-item;
185
+ }
186
+
164
187
  /* Code keeps the font the RTF names for it. A code block wraps, so a long line stays in
165
188
  the viewer. */
166
189
  .rtf-viewer :global(code),
@@ -187,8 +210,16 @@
187
210
  height: auto;
188
211
  }
189
212
 
213
+ /* (The space of a paragraph, as in the editor: the space before and after a picture is
214
+ what the document sets.) */
190
215
  .rtf-viewer :global(figure) {
191
- margin: 1em 0;
216
+ margin: 0 0 0.2em;
217
+ }
218
+
219
+ /* Pictures side by side are a row of cells, each picture at the top of its own, as the
220
+ RTF has them. */
221
+ .rtf-viewer :global(:is(td, th):has(> figure, > img)) {
222
+ vertical-align: top;
192
223
  }
193
224
 
194
225
  .rtf-viewer :global(figcaption) {
@@ -0,0 +1,187 @@
1
+ <script lang="ts">
2
+ /**
3
+ * The font menu a right-click on the text opens (InkEditor's `fontMenu`): the document's
4
+ * font and the fonts offered, each in itself, the font of the selected text checked. It
5
+ * takes the keyboard while it is open: the arrows, Home and End move in it, Enter or Space
6
+ * chooses, Escape or Tab closes it. A press anywhere else closes it, and so do a scroll
7
+ * and the window losing the keyboard.
8
+ */
9
+ import { onMount, tick } from 'svelte';
10
+
11
+ interface Choice {
12
+ key: string;
13
+ name: string;
14
+ css: string;
15
+ }
16
+
17
+ interface Props {
18
+ /** Where the menu opens, in the window's coordinates: its top left corner. */
19
+ x: number;
20
+ y: number;
21
+ /** The choices, the document's own font first, with the key ''. */
22
+ choices: Choice[];
23
+ /** The key of the font of the selected text; null where it is in more than one. */
24
+ current: string | null;
25
+ onpick: (key: string) => void;
26
+ /** `refocus`: the menu was left from the keyboard, and the text should have it back. */
27
+ onclose: (refocus: boolean) => void;
28
+ }
29
+
30
+ let { x, y, choices, current, onpick, onclose }: Props = $props();
31
+
32
+ let menuEl: HTMLDivElement | null = $state(null);
33
+ /** Where the menu is shown: where it opens, moved in so that all of it is in the window. */
34
+ let left = $state(0);
35
+ let top = $state(0);
36
+
37
+ const MARGIN = 8;
38
+
39
+ function items(): HTMLElement[] {
40
+ return menuEl ? Array.from(menuEl.querySelectorAll<HTMLElement>('[role="menuitemradio"]')) : [];
41
+ }
42
+
43
+ function focusItem(index: number): void {
44
+ const all = items();
45
+ if (all.length === 0) return;
46
+ all[(index + all.length) % all.length].focus();
47
+ }
48
+
49
+ onMount(() => {
50
+ left = x;
51
+ top = y;
52
+ void tick().then(() => {
53
+ if (!menuEl) return;
54
+ const box = menuEl.getBoundingClientRect();
55
+ left = Math.max(MARGIN, Math.min(x, window.innerWidth - box.width - MARGIN));
56
+ top = y + box.height + MARGIN > window.innerHeight ? Math.max(MARGIN, y - box.height) : y;
57
+ const at = choices.findIndex((choice) => choice.key === current);
58
+ focusItem(at < 0 ? 0 : at);
59
+ });
60
+ });
61
+
62
+ function onkeydown(e: KeyboardEvent): void {
63
+ const all = items();
64
+ const at = all.indexOf(document.activeElement as HTMLElement);
65
+ if (e.key === 'ArrowDown') focusItem(at + 1);
66
+ else if (e.key === 'ArrowUp') focusItem(at < 0 ? -1 : at - 1);
67
+ else if (e.key === 'Home') focusItem(0);
68
+ else if (e.key === 'End') focusItem(-1);
69
+ else if (e.key === 'Escape' || e.key === 'Tab') onclose(true);
70
+ else return;
71
+ e.preventDefault();
72
+ e.stopPropagation();
73
+ }
74
+
75
+ /** A press outside the menu closes it, and goes on to do what it does there. */
76
+ function pressedOutside(e: PointerEvent): void {
77
+ if (menuEl && !menuEl.contains(e.target as Node)) onclose(false);
78
+ }
79
+ </script>
80
+
81
+ <svelte:window
82
+ onpointerdowncapture={pressedOutside}
83
+ onscrollcapture={(e) => {
84
+ if (!menuEl?.contains(e.target as Node)) onclose(false);
85
+ }}
86
+ onresize={() => onclose(false)}
87
+ onblur={() => onclose(false)}
88
+ />
89
+
90
+ <div
91
+ class="ink-font-menu"
92
+ role="menu"
93
+ aria-label="Font"
94
+ tabindex="-1"
95
+ style:left="{left}px"
96
+ style:top="{top}px"
97
+ bind:this={menuEl}
98
+ {onkeydown}
99
+ oncontextmenu={(e) => e.preventDefault()}
100
+ >
101
+ <div class="ink-font-menu-title" aria-hidden="true">Font</div>
102
+ {#each choices as choice (choice.key)}
103
+ <button
104
+ type="button"
105
+ role="menuitemradio"
106
+ aria-checked={choice.key === current}
107
+ tabindex="-1"
108
+ style:font-family={choice.css}
109
+ onmousedown={(e) => e.preventDefault()}
110
+ onclick={() => onpick(choice.key)}
111
+ >
112
+ <span class="ink-font-menu-check" aria-hidden="true">{choice.key === current ? '✓' : ''}</span>
113
+ {choice.name}
114
+ </button>
115
+ {/each}
116
+ <div class="ink-font-menu-note" aria-hidden="true">Shift + right-click: the browser's menu</div>
117
+ </div>
118
+
119
+ <style>
120
+ .ink-font-menu {
121
+ position: fixed;
122
+ z-index: 1000;
123
+ box-sizing: border-box;
124
+ min-width: 190px;
125
+ max-width: min(320px, calc(100vw - 16px));
126
+ max-height: calc(100vh - 16px);
127
+ overflow-y: auto;
128
+ padding: 4px;
129
+ border: 1px solid var(--border, #d9d4cc);
130
+ border-radius: 10px;
131
+ background: var(--bg, #fff);
132
+ color: var(--text, #1a1714);
133
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
134
+ font-family: 'DM Sans', system-ui, sans-serif;
135
+ font-size: 14px;
136
+ }
137
+
138
+ .ink-font-menu:focus {
139
+ outline: none;
140
+ }
141
+
142
+ .ink-font-menu-title {
143
+ padding: 4px 10px 2px;
144
+ font-size: 11px;
145
+ font-weight: 600;
146
+ letter-spacing: 0.04em;
147
+ text-transform: uppercase;
148
+ color: var(--text-muted, #8a7e72);
149
+ }
150
+
151
+ .ink-font-menu button {
152
+ display: flex;
153
+ align-items: center;
154
+ gap: 6px;
155
+ width: 100%;
156
+ padding: 6px 10px 6px 6px;
157
+ border: 0;
158
+ border-radius: 6px;
159
+ background: transparent;
160
+ color: inherit;
161
+ font-size: 15px;
162
+ text-align: left;
163
+ cursor: pointer;
164
+ }
165
+
166
+ .ink-font-menu button:hover,
167
+ .ink-font-menu button:focus-visible,
168
+ .ink-font-menu button:focus {
169
+ outline: none;
170
+ background: var(--accent-soft, #ede9fe);
171
+ }
172
+
173
+ .ink-font-menu-check {
174
+ display: inline-block;
175
+ width: 1.1em;
176
+ font-family: 'DM Sans', system-ui, sans-serif;
177
+ color: var(--accent, #6e56cf);
178
+ }
179
+
180
+ .ink-font-menu-note {
181
+ margin-top: 4px;
182
+ padding: 6px 10px 4px;
183
+ border-top: 1px solid var(--border, #d9d4cc);
184
+ font-size: 11px;
185
+ color: var(--text-muted, #8a7e72);
186
+ }
187
+ </style>
@@ -0,0 +1,20 @@
1
+ interface Choice {
2
+ key: string;
3
+ name: string;
4
+ css: string;
5
+ }
6
+ interface Props {
7
+ /** Where the menu opens, in the window's coordinates: its top left corner. */
8
+ x: number;
9
+ y: number;
10
+ /** The choices, the document's own font first, with the key ''. */
11
+ choices: Choice[];
12
+ /** The key of the font of the selected text; null where it is in more than one. */
13
+ current: string | null;
14
+ onpick: (key: string) => void;
15
+ /** `refocus`: the menu was left from the keyboard, and the text should have it back. */
16
+ onclose: (refocus: boolean) => void;
17
+ }
18
+ declare const FontMenu: import("svelte").Component<Props, {}, "">;
19
+ type FontMenu = ReturnType<typeof FontMenu>;
20
+ export default FontMenu;