svelte-rtf-editor 1.12.0 → 1.15.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 +197 -20
- package/dist/RtfViewer.svelte +41 -5
- package/dist/RtfViewer.svelte.d.ts +1 -0
- package/dist/components/ImageOverlay.svelte +153 -17
- package/dist/components/ImageOverlay.svelte.d.ts +23 -2
- package/dist/components/InkEditor.svelte +1878 -307
- package/dist/components/InkEditor.svelte.d.ts +16 -0
- package/dist/components/Modal.svelte +9 -13
- package/dist/components/Toolbar.svelte +141 -18
- package/dist/components/Toolbar.svelte.d.ts +23 -0
- package/dist/history.d.ts +49 -0
- package/dist/history.js +329 -0
- package/dist/list-markers.d.ts +64 -0
- package/dist/list-markers.js +211 -0
- package/dist/lists.d.ts +48 -0
- package/dist/lists.js +576 -0
- package/dist/paste-pictures.d.ts +22 -0
- package/dist/paste-pictures.js +57 -0
- package/dist/picture-rows.d.ts +49 -0
- package/dist/picture-rows.js +109 -0
- package/dist/rtf-parser.d.ts +23 -0
- package/dist/rtf-parser.js +460 -39
- package/dist/rtf-writer.d.ts +65 -3
- package/dist/rtf-writer.js +509 -58
- package/dist/sanitize.d.ts +36 -0
- package/dist/sanitize.js +162 -6
- package/dist/utils.js +62 -3
- package/package.json +1 -1
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
|
-
-
|
|
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)
|
|
@@ -109,9 +113,10 @@ Pass an HTML string as `content`. If the content is already RTF, convert it firs
|
|
|
109
113
|
| Prop | Type | Default | Description |
|
|
110
114
|
|--------------|----------|-----------|------------------------------------------|
|
|
111
115
|
| `content` | `string` | — | Raw RTF string to parse and display |
|
|
112
|
-
| `fontFamily` | `string` | `'Segoe UI'` | Font the document is shown in. See [Fonts](#fonts) |
|
|
116
|
+
| `fontFamily` | `string` | `'Segoe UI'` | Font the document is shown in; a CSS list names the font first, then what a screen without it shows. See [Fonts](#fonts) |
|
|
113
117
|
| `fontSize` | `number` | `12` | Body text size in points |
|
|
114
118
|
| `maxRtfBytes` | `number` | `52428800` | The largest document it reads (50 MB); `0` reads any size. See [Size limit on import](#size-limit-on-import) |
|
|
119
|
+
| `fonts` | `string[]` | `[]` | The fonts text may be shown in beside the document's own: the same list you give the editor. See [Fonts for selected text](#fonts-for-selected-text) |
|
|
115
120
|
|
|
116
121
|
---
|
|
117
122
|
|
|
@@ -127,6 +132,7 @@ Pass an HTML string as `content`. If the content is already RTF, convert it firs
|
|
|
127
132
|
| `storageKey` | `string` | `'ink-editor-content'` | `localStorage` key the draft is kept under. Give each document its own |
|
|
128
133
|
| `ariaLabel` | `string` | `'Document'` | The name of the editing area for a screen reader |
|
|
129
134
|
| `showToolbar` | `boolean` | `true` | Show the formatting toolbar |
|
|
135
|
+
| `stickyToolbar` | `boolean` | `true` | Keep the toolbar in sight while a long document is scrolled. See [The toolbar of a long document](#the-toolbar-of-a-long-document) |
|
|
130
136
|
| `showStatusBar` | `boolean` | `true` | Show the word/character count bar |
|
|
131
137
|
| `minHeight` | `string` | `'40vh'` | CSS `min-height` of the editing area |
|
|
132
138
|
| `readonly` | `boolean` | `false` | Disable editing |
|
|
@@ -134,9 +140,10 @@ Pass an HTML string as `content`. If the content is already RTF, convert it firs
|
|
|
134
140
|
| `maxImageBytes` | `number` | `524288` | Encoded byte ceiling per image; an oversized picture is re-encoded and shrunk until it fits, and is not inserted if it cannot. `0` disables |
|
|
135
141
|
| `maxRtfBytes` | `number` | `52428800` | The largest RTF file Import reads (50 MB); `0` reads any size |
|
|
136
142
|
| `maxImageDisplayWidth` | `number` | `624` | Width (px) a newly inserted image is displayed at, unless the column is narrower — 6.5in of page. `0` fills the column |
|
|
137
|
-
| `fontFamily` | `string` | `'Segoe UI'` | Document font, on screen and in the RTF. See [Fonts](#fonts) |
|
|
143
|
+
| `fontFamily` | `string` | `'Segoe UI'` | Document font, on screen and in the RTF. A CSS list names the font first, then what a screen without it shows. See [Fonts](#fonts) |
|
|
138
144
|
| `fontSize` | `number` | `12` | Body text size in points, on screen and in the RTF |
|
|
139
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) |
|
|
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) |
|
|
140
147
|
| `keepAttributes` | `string[]` | `[]` | `data-` attributes of your own that stay on HTML you set or the user pastes. See [HTML from outside](#html-from-outside) |
|
|
141
148
|
| `keepClasses` | `string[]` | `[]` | Class names of your own that stay the same way |
|
|
142
149
|
|
|
@@ -162,7 +169,14 @@ editor.focus() // → void — focus the editor
|
|
|
162
169
|
editor.exportFile(format) // → void — download as 'html' | 'md' | 'rtf'
|
|
163
170
|
editor.importRtf() // → void — open the file picker to import .rtf
|
|
164
171
|
editor.setFontSize(14) // → void — size, in points, of the selected text, or of what is typed next
|
|
172
|
+
editor.setFont('Calibri') // → void — font of the selected text, or of what is typed next: one of `fonts`, or '' for the document font
|
|
165
173
|
editor.clearFormatting() // → void — take bold, italic, underline, strike, color, size and font off the selected text
|
|
174
|
+
editor.setLineSpacing(1.5) // → void — line spacing of the selected paragraphs, in lines; null for the document's own
|
|
175
|
+
editor.setParagraphSpacing({ before: 6, after: 12 }) // → void — space before and after them, in points; either may be left out, 0 or null is none
|
|
176
|
+
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
|
|
177
|
+
editor.insertTable(3, 2, { borders: true, header: false }) // → void — a table of empty cells after the paragraph the caret is in
|
|
178
|
+
editor.undo() // → boolean — take back the last step; false if there was none
|
|
179
|
+
editor.redo() // → boolean — make a step that was taken back again; false if there was none
|
|
166
180
|
```
|
|
167
181
|
|
|
168
182
|
#### Auto-save
|
|
@@ -217,13 +231,13 @@ import {
|
|
|
217
231
|
|
|
218
232
|
| Function | Description |
|
|
219
233
|
|---------------------------------------|----------------------------------------------------|
|
|
220
|
-
| `rtfToHtml(rtf: string, options?: { fontSize?, maxBytes? }): string` | Parse an RTF string and return an HTML string. `fontSize` is the size of the screen it will be shown on (default 12). Throws a `RangeError` for a string longer than `maxBytes` (default 50 MB; see [Size limit on import](#size-limit-on-import)) |
|
|
234
|
+
| `rtfToHtml(rtf: string, options?: { fontSize?, maxBytes?, fonts?, fontFamily? }): string` | Parse an RTF string and return an HTML string. `fontSize` is the size of the screen it will be shown on (default 12). `fonts` and `fontFamily` are the editor's: see [Fonts for selected text](#fonts-for-selected-text). Throws a `RangeError` for a string longer than `maxBytes` (default 50 MB; see [Size limit on import](#size-limit-on-import)) |
|
|
221
235
|
| `htmlToRtf(el: HTMLElement, options?: { fontFamily?, fontSize? }): string` | Convert a DOM element's content to RTF, in Segoe UI 12 pt unless told otherwise |
|
|
222
236
|
| `estimateRtfBytes(el: HTMLElement, options?: { fontFamily?, fontSize? }): number` | Approximate RTF size of a DOM element without converting it. Give it the options `htmlToRtf` is called with; it is never below the real size |
|
|
223
237
|
| `isSafeLinkUrl(url: string): boolean` | Whether a link address is a web, mail or phone address; `htmlToRtf` and `htmlToMarkdown` write any other link as its text alone, and `rtfToHtml` reads any other as text |
|
|
224
238
|
| `readRtfFile(file: File, options?: { fontSize?, maxBytes? }): Promise<string>` | Read a `.rtf` File object and return HTML. Rejects, without reading it, for a file larger than `maxBytes` |
|
|
225
239
|
| `htmlToMarkdown(el: HTMLElement): string` | Convert a DOM element's content to Markdown. See [Markdown export](#markdown-export) |
|
|
226
|
-
| `sanitizeHtml(html: string, options?: { keepAttributes?: string[]; keepClasses?: string[] }): string` | HTML made safe to show and edit. See [HTML from outside](#html-from-outside). Needs a DOM (`DOMParser`); without one it returns `''` |
|
|
240
|
+
| `sanitizeHtml(html: string, options?: { keepAttributes?: string[]; keepClasses?: string[]; fonts?: string[]; fontFamily?: string }): string` | HTML made safe to show and edit. See [HTML from outside](#html-from-outside). Needs a DOM (`DOMParser`); without one it returns `''` |
|
|
227
241
|
| `downloadFile(name, content, mime): void` | Trigger a file download in the browser |
|
|
228
242
|
|
|
229
243
|
---
|
|
@@ -250,15 +264,67 @@ An application that shows documents in more than one place does well to keep the
|
|
|
250
264
|
|
|
251
265
|
The default was Arial through 1.9.0. A document is written in the font of the editor that saves it, not in the font it was written in before: a report saved in Arial and opened and saved again by an editor left at the default comes out in Segoe UI. To keep Arial, pass `fontFamily="Arial"`.
|
|
252
266
|
|
|
253
|
-
Segoe UI is installed with Windows. On a system without it (macOS, Linux, a phone) the screen shows the system's sans-serif font in its place, and the RTF still names Segoe UI, which is what the receiving system reads.
|
|
267
|
+
Segoe UI is installed with Windows. On a system without it (macOS, Linux, a phone) the screen shows the system's sans-serif font in its place, and the RTF still names Segoe UI, which is what the receiving system reads. To show such a screen something closer, see [A font the screen does not have](#a-font-the-screen-does-not-have).
|
|
254
268
|
|
|
255
269
|
- `fontFamily` is used for the whole document: body text, headings, lists and tables. Code keeps Courier New.
|
|
256
270
|
- `fontSize` is the body size in points. Headings scale from it: at 12 pt, `h1` is 24 pt, `h2` 18 pt and `h3` 14 pt.
|
|
257
271
|
- If you call `htmlToRtf` yourself on the editor's content, pass the same options you gave the editor, or the two produce different RTF.
|
|
258
|
-
- `fontFamily` names one font. Given a CSS list such as `'
|
|
272
|
+
- `fontFamily` names one font. Given a CSS list such as `'Segoe UI, Selawik, sans-serif'`, the first family is the font: the one the RTF names, and the one the toolbar's font list shows. The rest of the list is for the screen alone, where the font is missing. Through 1.12.0 the rest of the list was ignored.
|
|
259
273
|
- `fontSize` is rounded to the nearest half-point, which is what RTF measures in, and kept between 1 and 1638 pt.
|
|
260
274
|
- If you show RTF in an editor or viewer set to another size, pass the same `fontSize` to `rtfToHtml`. Text at that size then carries no size of its own, text at any other size keeps it, and headings are recognized by the same ratios the writer uses. `InkEditor`'s RTF import and `RtfViewer` do this themselves. A heading must also be bold, at every body size, as every heading the writer emits is.
|
|
261
275
|
|
|
276
|
+
### The toolbar of a long document
|
|
277
|
+
|
|
278
|
+
The editing area grows with the document, and the page scrolls. The toolbar stays at the top of the window while it does, or at the top of the scrolling element the editor is in, and leaves with the end of the editor. A caret moved up with the keys is not left under it.
|
|
279
|
+
|
|
280
|
+
- Under a header of your own that stays at the top too, give the toolbar its place below it: `--ink-toolbar-top: 56px` on the editor or any element around it.
|
|
281
|
+
- It cannot stay where an element around the editor has `overflow: hidden`, `auto` or `scroll` and is not itself what scrolls: that is how `position: sticky` works. Take the `overflow` off that element, or make it the one that scrolls.
|
|
282
|
+
- `stickyToolbar={false}` lets the toolbar go with the page, as it did through 1.12.0.
|
|
283
|
+
|
|
284
|
+
### Opening a link
|
|
285
|
+
|
|
286
|
+
A click on a link in the editor puts the caret in it, as anywhere else in the text, so that its words can be changed. To open the link, click it with `Ctrl` held down (`Cmd` on a Mac), as in Word. The pointer over a link shows a note with the address and that instruction. The note is the editor's own: it is not in the HTML or the RTF.
|
|
287
|
+
|
|
288
|
+
- The link opens in a new tab, which is given no access to your page and is not told where it was opened from.
|
|
289
|
+
- Only an address `isSafeLinkUrl` accepts is opened: a web, mail or phone address.
|
|
290
|
+
- With `readonly` there is no caret to place, so a plain click opens the link, in a new tab like the viewer's. It used to open in place of your application.
|
|
291
|
+
- How a link opens for the reader of the RTF is the receiving system's own affair. The RTF holds the address and the words (a `HYPERLINK` field), and says nothing of clicks.
|
|
292
|
+
|
|
293
|
+
### A font the screen does not have
|
|
294
|
+
|
|
295
|
+
The RTF names a font; it does not carry one. Whoever opens the document sees it in that font only if their machine has it, and that goes for your users' browsers too. On a Mac, a document in Segoe UI is shown in Helvetica, which is hard to tell from Arial, and lines break in other places than they will for the reader on Windows.
|
|
296
|
+
|
|
297
|
+
A page cannot reliably find out which fonts a machine has, and does not need to. Give the font a stand-in the page loads itself, and name it after the font:
|
|
298
|
+
|
|
299
|
+
```css
|
|
300
|
+
/* Your page's stylesheet. The files are served by your own application. */
|
|
301
|
+
@font-face { font-family: "Selawik"; font-weight: 400; src: url("/fonts/selawik-regular.woff2") format("woff2"); }
|
|
302
|
+
@font-face { font-family: "Selawik"; font-weight: 700; src: url("/fonts/selawik-bold.woff2") format("woff2"); }
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
```svelte
|
|
306
|
+
<InkEditor fontFamily="Segoe UI, Selawik, sans-serif" />
|
|
307
|
+
<RtfViewer content={rtf} fontFamily="Segoe UI, Selawik, sans-serif" />
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Where Segoe UI is installed the browser uses it and does not fetch the stand-in. Where it is not, the stand-in is fetched and shown. The RTF names Segoe UI either way. The fonts you offer for selected text take a stand-in the same way: `fonts={['Calibri, Carlito, sans-serif']}`.
|
|
311
|
+
|
|
312
|
+
Fonts made to take the place of the usual ones, with letters of the same widths, so that lines break where they do in the original:
|
|
313
|
+
|
|
314
|
+
| Font | Stand-in |
|
|
315
|
+
| --- | --- |
|
|
316
|
+
| Segoe UI | Selawik (upright cuts only: italic is slanted by the browser) |
|
|
317
|
+
| Calibri | Carlito |
|
|
318
|
+
| Cambria | Caladea |
|
|
319
|
+
| Arial | Arimo, Liberation Sans |
|
|
320
|
+
| Times New Roman | Tinos, Liberation Serif |
|
|
321
|
+
| Courier New | Cousine, Liberation Mono |
|
|
322
|
+
|
|
323
|
+
- Use a stand-in rather than the font itself. Segoe UI, Calibri and the others belong to their makers and are not yours to serve from a web page; the stand-ins are published under open licences. Read each one's licence before you ship it.
|
|
324
|
+
- Serve the files from your own application, not from a font service. A request to someone else's server tells them who opened a document and when, is stopped by a strict content security policy, and does not work on a network that is closed to the outside.
|
|
325
|
+
- Give the stand-in its own name, as above, and do not declare it under the name of the font it stands in for. A page that declares `"Segoe UI"` with one regular file takes the place of the installed Segoe UI too, and its bold is then the regular cut drawn thicker.
|
|
326
|
+
- This package loads no fonts and makes no requests. The stylesheet and the files are your page's.
|
|
327
|
+
|
|
262
328
|
### Size of selected text
|
|
263
329
|
|
|
264
330
|
The toolbar has a list of sizes, next to the list of paragraph kinds. A size chosen there is given to the selected text; with nothing selected, to what is typed next. The list shows the size of the text at the caret, also when it is not one of the sizes offered, and is empty where the selection starts in one size and ends in another.
|
|
@@ -272,6 +338,30 @@ The toolbar has a list of sizes, next to the list of paragraph kinds. A size cho
|
|
|
272
338
|
|
|
273
339
|
The font has to be installed on the machine that displays the document. The RTF names it, and a reader without it substitutes one of its own.
|
|
274
340
|
|
|
341
|
+
### Fonts for selected text
|
|
342
|
+
|
|
343
|
+
By default a document has one font, `fontFamily`, and the toolbar has no font list. To let users set words in other fonts, name the fonts you offer:
|
|
344
|
+
|
|
345
|
+
```svelte
|
|
346
|
+
<InkEditor fonts={['Georgia', 'Calibri, Carlito, sans-serif', 'Arial']} bind:this={editor} />
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
The toolbar then has a font list before the size list: the document font first, then yours. A font chosen there is given to the selected text; with nothing selected, to what is typed next. `editor.setFont(name)` does the same from your own toolbar, and `editor.setFont('')` sets text back to the document font.
|
|
350
|
+
|
|
351
|
+
Which fonts to offer is decided by the system that receives the RTF, not by what is installed where the document is written or viewed. A font that system cannot show is a choice the user only appears to have: the words come out in whatever it substitutes. So the list is set by whoever integrates the editor, once for each receiving system, and leaving it out is as good a decision as any: one font, and no font list.
|
|
352
|
+
|
|
353
|
+
The list is the limit. A font that is not on it is not offered, is taken off HTML that is set or pasted, is not written to the RTF and is not read back from one. Keep it with `fontFamily` and `fontSize` in one module of your own, and pass all three wherever a document goes. What your own screens show of a font they do not have is a separate matter: see [A font the screen does not have](#a-font-the-screen-does-not-have).
|
|
354
|
+
|
|
355
|
+
- An entry is a font name, or a CSS list whose first family is the name. The rest of the list is what a screen without that font shows the text in: `'Calibri, Carlito, sans-serif'` is Calibri in the list and in the RTF, and Carlito on a machine that has no Calibri. A name alone is given `serif`, `sans-serif` or `monospace` after it, whichever suits it.
|
|
356
|
+
- In the RTF, each font the document has text in is one more entry of the font table, and the text is written between `\fN` and the font it was in before. A font that is offered and not used is not in the table.
|
|
357
|
+
- An editor that offers no fonts lets none in. Text pasted from Word or a web page is shown in the document font, as the RTF has it. Through 1.12.0 the font of a paste stayed on the screen and was never written to the RTF: the editor showed Calibri and sent Segoe UI. If you use the editor for its HTML and want pasted fonts kept, name them in `fonts`.
|
|
358
|
+
- Pass the same list wherever the document goes: `<RtfViewer fonts={…}>`, `htmlToRtf(el, { fonts })`, `rtfToHtml(rtf, { fonts, fontFamily })` and `sanitizeHtml(html, { fonts, fontFamily })`. Without it the writer writes one font and the reader gives none. `sanitizeHtml` called without `fonts` leaves fonts as they come, as before; with a list, `[]` included, it keeps those fonts and the document's and takes any other off.
|
|
359
|
+
- An RTF file from another program is read the same way. Text it sets in a font you offer carries that font; text in any other font, and text in the font your screen shows the document in, carries none. TextEdit names each cut of a font (`TimesNewRomanPS-BoldMT`, `Arial-ItalicMT`): those are read as Times New Roman and Arial.
|
|
360
|
+
- The editor uses the browser's own font command, so a change of font is undone and redone with everything else. In the HTML the font is on a `<font>` element (`<font face="Georgia, serif">`); what is read from RTF has it as a style (`<span style="font-family:Georgia, serif">`). Both are written to RTF alike.
|
|
361
|
+
- Set back to the document font, the words lose their `<font>` in Chromium and Safari, and in Firefox are given one that names the document font. The RTF is the same.
|
|
362
|
+
- 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.
|
|
363
|
+
- [Clear formatting](#clear-formatting) takes a font off with the rest.
|
|
364
|
+
|
|
275
365
|
### Clear formatting
|
|
276
366
|
|
|
277
367
|
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.
|
|
@@ -286,12 +376,41 @@ The toolbar's Clear formatting button, next to the text color, takes the formatt
|
|
|
286
376
|
| | Elements carrying your `keepAttributes` or `keepClasses` |
|
|
287
377
|
|
|
288
378
|
- Only the selected words change: clearing two words of a bold sentence leaves the rest bold.
|
|
289
|
-
- The result is the same HTML in Chromium, Firefox and Safari. 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.
|
|
290
|
-
- 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.
|
|
379
|
+
- 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.
|
|
380
|
+
- 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.
|
|
381
|
+
- 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.
|
|
291
382
|
- 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.
|
|
292
383
|
|
|
293
384
|
---
|
|
294
385
|
|
|
386
|
+
## Lists
|
|
387
|
+
|
|
388
|
+
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.
|
|
389
|
+
|
|
390
|
+
- **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.
|
|
391
|
+
- **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.
|
|
392
|
+
- **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.
|
|
393
|
+
- **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.
|
|
394
|
+
- **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.
|
|
395
|
+
- 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.
|
|
396
|
+
- Not made an item: a picture with its caption, a table as a whole (a line inside a cell is), a code block.
|
|
397
|
+
- 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.
|
|
398
|
+
|
|
399
|
+
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).
|
|
400
|
+
|
|
401
|
+
## Undo and Redo
|
|
402
|
+
|
|
403
|
+
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.
|
|
404
|
+
|
|
405
|
+
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.
|
|
406
|
+
|
|
407
|
+
- **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.
|
|
408
|
+
- **The caret** is put back where it was before the step.
|
|
409
|
+
- **Redo** makes a step again that Undo took back, until something else is changed.
|
|
410
|
+
- **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.
|
|
411
|
+
- What Undo puts back is checked as everything that reaches the editor is (see [HTML from outside](#html-from-outside)).
|
|
412
|
+
- 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.
|
|
413
|
+
|
|
295
414
|
## Paragraph formatting
|
|
296
415
|
|
|
297
416
|
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:
|
|
@@ -302,16 +421,40 @@ A `<p>` or `<div>` keeps its own indents, spacing and tab stops in the RTF, so a
|
|
|
302
421
|
| `margin-right: 0.5in` | `\ri720` |
|
|
303
422
|
| `text-indent: -1.75in` | `\fi-2520` |
|
|
304
423
|
| `margin-top: 5pt` / `margin-bottom: 5pt` | `\sb100` / `\sa100` |
|
|
424
|
+
| `line-height: 1.5` (or `150%`) | `\sl360\slmult1` |
|
|
425
|
+
| `line-height: 14pt` | `\sl-280\slmult0` (exactly 14 pt) |
|
|
305
426
|
| `break-after: avoid` or `page-break-after: avoid` | `\keepn` |
|
|
306
427
|
| `data-rtf-tab-stops="1.75in"` (comma-separated) | `\tx2520` |
|
|
307
428
|
|
|
308
429
|
- 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.
|
|
309
430
|
- 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`.
|
|
310
431
|
- `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`.
|
|
311
|
-
- Inside a table cell the cell declares its own paragraph:
|
|
432
|
+
- 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.
|
|
312
433
|
- `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.
|
|
313
434
|
- 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.
|
|
314
|
-
- `rtfToHtml`
|
|
435
|
+
- `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.
|
|
436
|
+
- `rtfToHtml` does not yet read keep-with-next or tab stops back.
|
|
437
|
+
|
|
438
|
+
### Line and paragraph spacing
|
|
439
|
+
|
|
440
|
+
The **Spacing** list in the toolbar sets, for the paragraphs the selection touches:
|
|
441
|
+
|
|
442
|
+
- **Line spacing**: 1, 1.15, 1.5 or 2 lines, or Default (the document's own).
|
|
443
|
+
- **Space before paragraph** and **Space after paragraph**: 0, 6 or 12 pt.
|
|
444
|
+
|
|
445
|
+
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.
|
|
446
|
+
|
|
447
|
+
`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.
|
|
448
|
+
|
|
449
|
+
#### The gap after a list's bullets or numbers
|
|
450
|
+
|
|
451
|
+
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.
|
|
452
|
+
|
|
453
|
+
- **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.
|
|
454
|
+
- **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.
|
|
455
|
+
- **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.
|
|
456
|
+
|
|
457
|
+
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.)
|
|
315
458
|
|
|
316
459
|
---
|
|
317
460
|
|
|
@@ -326,6 +469,7 @@ A `<p>` or `<div>` keeps its own indents, spacing and tab stops in the RTF, so a
|
|
|
326
469
|
| `<ul>`, `<ol>` | one paragraph per item: `\li720\fi-360`, then `\bullet\tab` or `1.\tab` | `<ul>`, `<ol>` |
|
|
327
470
|
| a list inside a list item | the same, `\li720` further in for each level | a list inside the item |
|
|
328
471
|
| `<ol start="5">` | `5.\tab`, `6.\tab`, … | `<ol start="5">` |
|
|
472
|
+
| `<ol type="A">`, and `a`, `I`, `i`; the same by `list-style-type` | `A.\tab`, `B.\tab`, …: the marker the list shows | `<ol type="A">` |
|
|
329
473
|
| `<a href="https://…">` | `{\field{\*\fldinst HYPERLINK "…"}{\fldrslt …}}`, underlined, in the link color | `<a href="https://…" target="_blank" rel="noopener noreferrer">` |
|
|
330
474
|
| `<code>` | `\f1` (Courier New) | `<code>` |
|
|
331
475
|
| `<pre>` | a paragraph in `\f1` at 5/6 of the body size, lines separated by `\line` | `<pre>` |
|
|
@@ -335,7 +479,10 @@ A `<p>` or `<div>` keeps its own indents, spacing and tab stops in the RTF, so a
|
|
|
335
479
|
| `<table>` | one `\trowd … \row` per row; see [Tables](#tables) | `<table>` |
|
|
336
480
|
| `<br>` | `\line` | `<br>` |
|
|
337
481
|
|
|
338
|
-
- **
|
|
482
|
+
- **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.
|
|
483
|
+
- **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.
|
|
484
|
+
- **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.
|
|
485
|
+
- **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.
|
|
339
486
|
- **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.
|
|
340
487
|
- **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.
|
|
341
488
|
- **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.
|
|
@@ -353,7 +500,9 @@ RTF has no table element: each row says where its cells end (`\cellx`), so colum
|
|
|
353
500
|
- **`<caption>`** is written as a centered paragraph before the table, where a browser shows it, and is read back as that paragraph.
|
|
354
501
|
- **A column no cell starts in is not a column.** `colspan="100"` on a cell meant to cross the whole table adds none.
|
|
355
502
|
- **A row short of cells** is filled with empty ones, so its edges are the table's.
|
|
356
|
-
-
|
|
503
|
+
- **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.
|
|
504
|
+
- **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.
|
|
505
|
+
- **`<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.
|
|
357
506
|
- **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.
|
|
358
507
|
- **`<thead>` and `<tfoot>`** are written first and last, wherever the source has them.
|
|
359
508
|
- **A cell's `text-align`** is written on its paragraphs (`\qc`, `\qr`, `\qj`), and read back onto the cell.
|
|
@@ -405,7 +554,7 @@ Size is not the only way to exhaust a page: a file of nothing but braces is smal
|
|
|
405
554
|
|
|
406
555
|
### Markdown export
|
|
407
556
|
|
|
408
|
-
`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
|
|
557
|
+
`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.
|
|
409
558
|
|
|
410
559
|
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. `©` 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.
|
|
411
560
|
|
|
@@ -420,7 +569,11 @@ The components use CSS custom properties with sensible fallbacks, so they work o
|
|
|
420
569
|
--text: #2c2520;
|
|
421
570
|
--text-muted: #8a7e72;
|
|
422
571
|
--surface: #f2f0ec;
|
|
423
|
-
--border: #e5e2dc;
|
|
572
|
+
--border: #e5e2dc; /* also the box around the toolbar's lists */
|
|
573
|
+
--border-active: #c4b5a0; /* that box, and the editor's, under the pointer */
|
|
574
|
+
--bg-select: transparent; /* inside the toolbar's lists */
|
|
575
|
+
--bg-toolbar: #fff; /* the toolbar; not see-through, the document passes under it */
|
|
576
|
+
--ink-toolbar-top: 0px; /* where the toolbar stays: the height of a header of yours that stays too */
|
|
424
577
|
--ink: #1a1714;
|
|
425
578
|
--accent: #6e56cf;
|
|
426
579
|
--accent-soft: #ede9fe;
|
|
@@ -429,6 +582,10 @@ The components use CSS custom properties with sensible fallbacks, so they work o
|
|
|
429
582
|
}
|
|
430
583
|
```
|
|
431
584
|
|
|
585
|
+
### In a page with styles of its own
|
|
586
|
+
|
|
587
|
+
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.
|
|
588
|
+
|
|
432
589
|
---
|
|
433
590
|
|
|
434
591
|
## Keyboard shortcuts
|
|
@@ -439,15 +596,19 @@ The components use CSS custom properties with sensible fallbacks, so they work o
|
|
|
439
596
|
| `Ctrl+I` | Italic |
|
|
440
597
|
| `Ctrl+U` | Underline |
|
|
441
598
|
| `Ctrl+K` | Insert link |
|
|
599
|
+
| `Ctrl+click` / `Cmd+click` | Open the link under the pointer in a new tab |
|
|
442
600
|
| `Ctrl+S` | Save (fires `onsave`) |
|
|
443
601
|
| `Backspace` / `Delete` | Remove the selected image |
|
|
444
602
|
| `Ctrl+]` / `Cmd+]` | Increase indent of the selected paragraphs by 0.5 in (RTF `\li720` per step) |
|
|
445
603
|
| `Ctrl+[` / `Cmd+[` | Decrease indent |
|
|
446
|
-
| `Tab` | Insert a tab (sent to RTF as `\tab`); two spaces in a code block. With several lines selected, increase their indent |
|
|
447
|
-
| `Shift+Tab` | Remove one tab from the start of the line. With several lines selected, decrease their indent |
|
|
604
|
+
| `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 |
|
|
605
|
+
| `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 |
|
|
606
|
+
| `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 |
|
|
607
|
+
| `Ctrl+Z` / `Cmd+Z` | Undo |
|
|
608
|
+
| `Ctrl+Shift+Z` / `Cmd+Shift+Z`, `Ctrl+Y` | Redo |
|
|
448
609
|
| `Esc`, then `Tab` / `Shift+Tab` | Move focus out of the editor |
|
|
449
610
|
|
|
450
|
-
The toolbar's Increase indent and Decrease indent buttons do the same as `Ctrl+]` and `Ctrl+[`.
|
|
611
|
+
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)).
|
|
451
612
|
|
|
452
613
|
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):
|
|
453
614
|
|
|
@@ -482,6 +643,10 @@ A browser copies a paragraph with its looks written out as inline styles, and re
|
|
|
482
643
|
|
|
483
644
|
A picture copied with its text comes in by address (`<img src="https://…">`). The editor fetches it and holds its data in the document, as it does for an address typed in the image dialog, so it reaches the RTF as a picture. When it cannot be fetched (the site forbids it, there is no network, it takes longer than 15 seconds or is larger than 25 MB) the picture still shows and the editor says that it will export as a placeholder. The pictures in one paste are fetched at the same time, so one slow site does not hold up the others. A picture pasted as data in a format RTF cannot carry (GIF, WebP, SVG), or larger than `maxImageBytes`, is converted and scaled the same way.
|
|
484
645
|
|
|
646
|
+
A picture copied in Word with its text is another case. Word's HTML names it by a file on the writer's own disk (`file:///…/msohtmlclip/clip_image001.png`), which no page may open, and puts the picture itself in the RTF it copies beside the HTML. The editor reads the pictures from that RTF and gives each image its own, so the picture is on the screen and in the RTF that is written. Through 1.12.0 it was a broken image on the screen and `[Image: description]` in the RTF. Nothing is guessed: unless the RTF has exactly as many pictures as the HTML has images on the disk, none is given, and the paste is as before. A picture Word holds as a metafile (a chart, an old drawing) has no form a browser shows and stays a placeholder. A browser that does not hand a page the RTF of a paste leaves all of them so.
|
|
647
|
+
|
|
648
|
+
Word also writes that address in an HTML comment, with the name of the writer's account in it. A comment is not shown and not written to the RTF, but it is kept in the HTML that is saved. A browser leaves comments out of a paste; Firefox keeps those of markup that is dropped. So a comment that comes in with a paste or a drop is emptied (`<!---->`); it is not taken out, because Firefox cannot undo a drop from which a node is gone. Comments in the HTML your application gives the editor stay as they are.
|
|
649
|
+
|
|
485
650
|
A picture pasted as data that cannot be brought under `maxImageBytes`, or that the browser cannot open, is taken out of the paste, and the editor says so. What was only there for it goes with it: its figure and caption, a link around it, a paragraph or list item that held nothing else. Text that shared its paragraph stays, a table cell stays, and so does anything that was in the document before the paste. Chromium, pasting a figure at the end of a line of text, moves its pictures into that line and leaves the caption in a figure of its own (inside the `<div>` or `<section>` the figure came in, if it had one); that caption goes with the picture too, unless another picture pasted with it is still there. Pasting a block into an empty line, Chromium puts the block in the line's place; if nothing of the paste is left once its pictures are out, the empty line is put back, with the caret in it. Pasting a figure into the middle of a line, it turns the caption into ordinary text of that line, and there the caption stays, since it can no longer be told from the words around it. When one paste has a picture left out and another that will export as a placeholder, the message says both.
|
|
486
651
|
|
|
487
652
|
Paragraph alignment (left, center, right, justify) is written to RTF as `\qc`, `\qr` or `\qj`.
|
|
@@ -501,7 +666,19 @@ Three ways to add a picture:
|
|
|
501
666
|
|
|
502
667
|
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.
|
|
503
668
|
|
|
504
|
-
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.
|
|
669
|
+
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.
|
|
670
|
+
|
|
671
|
+
### Where a picture is on the page
|
|
672
|
+
|
|
673
|
+
- **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.
|
|
674
|
+
- **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).
|
|
675
|
+
- **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.)
|
|
676
|
+
- **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.
|
|
677
|
+
- **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.
|
|
678
|
+
- A row of pictures is moved up and down as one.
|
|
679
|
+
- **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.
|
|
680
|
+
|
|
681
|
+
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.
|
|
505
682
|
|
|
506
683
|
### How images are stored
|
|
507
684
|
|
|
@@ -582,7 +759,7 @@ Four commands must pass before a change is merged, and CI (`.github/workflows/ci
|
|
|
582
759
|
npm run check # svelte-check: types
|
|
583
760
|
npm run test:coverage # vitest, with a floor under the coverage (vite.config.ts)
|
|
584
761
|
npm run prepack # build the package and lint it with publint
|
|
585
|
-
npm run test:e2e # Playwright, in Chromium (once: npx playwright install chromium)
|
|
762
|
+
npm run test:e2e # Playwright, in Chromium, Firefox and WebKit (once: npx playwright install chromium firefox webkit)
|
|
586
763
|
```
|
|
587
764
|
|
|
588
765
|
`npm test` runs the same unit tests without measuring coverage. They run in a test DOM, which has no caret, no editing commands and no clipboard; `e2e/` holds what only a browser shows: where the first words typed go, what a key does after a dialog closes, what a real paste brings in. It drives the page at `src/routes/e2e`.
|
package/dist/RtfViewer.svelte
CHANGED
|
@@ -9,15 +9,20 @@
|
|
|
9
9
|
|
|
10
10
|
// fontFamily and fontSize (points) set how the document is shown, and
|
|
11
11
|
// default to the font the editor writes, so a document reads the same in
|
|
12
|
-
// the viewer as in the editor.
|
|
12
|
+
// the viewer as in the editor. fontFamily may be a CSS list: the font, then
|
|
13
|
+
// what a screen without it shows. maxRtfBytes is the largest document it will
|
|
13
14
|
// read (rtfToHtml's maxBytes): a picture costs two characters per byte, so
|
|
14
15
|
// raise it where reports can carry large pictures, or pass 0 for no limit.
|
|
16
|
+
// fonts are the fonts text may be shown in beside the document's own, as the
|
|
17
|
+
// editor's `fonts`: text in any other font is shown in the document font.
|
|
18
|
+
const NO_FONTS: string[] = [];
|
|
15
19
|
let {
|
|
16
20
|
content,
|
|
17
21
|
fontFamily = DEFAULT_FONT_FAMILY,
|
|
18
22
|
fontSize = DEFAULT_FONT_SIZE,
|
|
19
|
-
maxRtfBytes = DEFAULT_MAX_RTF_BYTES
|
|
20
|
-
|
|
23
|
+
maxRtfBytes = DEFAULT_MAX_RTF_BYTES,
|
|
24
|
+
fonts = NO_FONTS
|
|
25
|
+
}: { content: string | null | undefined; fontFamily?: string; fontSize?: number; maxRtfBytes?: number; fonts?: string[] } = $props();
|
|
21
26
|
|
|
22
27
|
const screenFontFamily = $derived(cssFontFamily(fontFamily));
|
|
23
28
|
const screenFontSize = $derived(normalizeFontSize(fontSize));
|
|
@@ -27,7 +32,7 @@
|
|
|
27
32
|
const parsed = $derived.by(() => {
|
|
28
33
|
try {
|
|
29
34
|
// A report that has not loaded yet shows as an empty document.
|
|
30
|
-
return { html: rtfToHtml(content ?? '', { fontSize, maxBytes: maxRtfBytes }), error: '' };
|
|
35
|
+
return { html: rtfToHtml(content ?? '', { fontSize, fontFamily, fonts, maxBytes: maxRtfBytes }), error: '' };
|
|
31
36
|
} catch (err) {
|
|
32
37
|
// Only the size limit's message is meant for the reader; anything else is a fault in
|
|
33
38
|
// the reader, not something the person looking at the report can act on.
|
|
@@ -156,6 +161,29 @@
|
|
|
156
161
|
margin-bottom: 0;
|
|
157
162
|
}
|
|
158
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
|
+
|
|
159
187
|
/* Code keeps the font the RTF names for it. A code block wraps, so a long line stays in
|
|
160
188
|
the viewer. */
|
|
161
189
|
.rtf-viewer :global(code),
|
|
@@ -182,8 +210,16 @@
|
|
|
182
210
|
height: auto;
|
|
183
211
|
}
|
|
184
212
|
|
|
213
|
+
/* (The space of a paragraph, as in the editor: the space before and after a picture is
|
|
214
|
+
what the document sets.) */
|
|
185
215
|
.rtf-viewer :global(figure) {
|
|
186
|
-
margin:
|
|
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;
|
|
187
223
|
}
|
|
188
224
|
|
|
189
225
|
.rtf-viewer :global(figcaption) {
|