svelte-rtf-editor 1.12.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -11
- package/dist/RtfViewer.svelte +9 -4
- package/dist/RtfViewer.svelte.d.ts +1 -0
- package/dist/components/InkEditor.svelte +552 -44
- package/dist/components/InkEditor.svelte.d.ts +4 -0
- package/dist/components/Modal.svelte +9 -13
- package/dist/components/Toolbar.svelte +71 -16
- package/dist/components/Toolbar.svelte.d.ts +11 -0
- package/dist/list-markers.d.ts +38 -0
- package/dist/list-markers.js +129 -0
- package/dist/paste-pictures.d.ts +22 -0
- package/dist/paste-pictures.js +57 -0
- package/dist/rtf-parser.d.ts +23 -0
- package/dist/rtf-parser.js +186 -17
- package/dist/rtf-writer.d.ts +55 -3
- package/dist/rtf-writer.js +257 -32
- package/dist/sanitize.d.ts +36 -0
- package/dist/sanitize.js +78 -5
- package/dist/utils.js +22 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -109,9 +109,10 @@ Pass an HTML string as `content`. If the content is already RTF, convert it firs
|
|
|
109
109
|
| Prop | Type | Default | Description |
|
|
110
110
|
|--------------|----------|-----------|------------------------------------------|
|
|
111
111
|
| `content` | `string` | — | Raw RTF string to parse and display |
|
|
112
|
-
| `fontFamily` | `string` | `'Segoe UI'` | Font the document is shown in. See [Fonts](#fonts) |
|
|
112
|
+
| `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
113
|
| `fontSize` | `number` | `12` | Body text size in points |
|
|
114
114
|
| `maxRtfBytes` | `number` | `52428800` | The largest document it reads (50 MB); `0` reads any size. See [Size limit on import](#size-limit-on-import) |
|
|
115
|
+
| `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
116
|
|
|
116
117
|
---
|
|
117
118
|
|
|
@@ -127,6 +128,7 @@ Pass an HTML string as `content`. If the content is already RTF, convert it firs
|
|
|
127
128
|
| `storageKey` | `string` | `'ink-editor-content'` | `localStorage` key the draft is kept under. Give each document its own |
|
|
128
129
|
| `ariaLabel` | `string` | `'Document'` | The name of the editing area for a screen reader |
|
|
129
130
|
| `showToolbar` | `boolean` | `true` | Show the formatting toolbar |
|
|
131
|
+
| `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
132
|
| `showStatusBar` | `boolean` | `true` | Show the word/character count bar |
|
|
131
133
|
| `minHeight` | `string` | `'40vh'` | CSS `min-height` of the editing area |
|
|
132
134
|
| `readonly` | `boolean` | `false` | Disable editing |
|
|
@@ -134,9 +136,10 @@ Pass an HTML string as `content`. If the content is already RTF, convert it firs
|
|
|
134
136
|
| `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
137
|
| `maxRtfBytes` | `number` | `52428800` | The largest RTF file Import reads (50 MB); `0` reads any size |
|
|
136
138
|
| `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) |
|
|
139
|
+
| `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
140
|
| `fontSize` | `number` | `12` | Body text size in points, on screen and in the RTF |
|
|
139
141
|
| `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
|
+
| `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
143
|
| `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
144
|
| `keepClasses` | `string[]` | `[]` | Class names of your own that stay the same way |
|
|
142
145
|
|
|
@@ -162,6 +165,7 @@ editor.focus() // → void — focus the editor
|
|
|
162
165
|
editor.exportFile(format) // → void — download as 'html' | 'md' | 'rtf'
|
|
163
166
|
editor.importRtf() // → void — open the file picker to import .rtf
|
|
164
167
|
editor.setFontSize(14) // → void — size, in points, of the selected text, or of what is typed next
|
|
168
|
+
editor.setFont('Calibri') // → void — font of the selected text, or of what is typed next: one of `fonts`, or '' for the document font
|
|
165
169
|
editor.clearFormatting() // → void — take bold, italic, underline, strike, color, size and font off the selected text
|
|
166
170
|
```
|
|
167
171
|
|
|
@@ -217,13 +221,13 @@ import {
|
|
|
217
221
|
|
|
218
222
|
| Function | Description |
|
|
219
223
|
|---------------------------------------|----------------------------------------------------|
|
|
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)) |
|
|
224
|
+
| `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
225
|
| `htmlToRtf(el: HTMLElement, options?: { fontFamily?, fontSize? }): string` | Convert a DOM element's content to RTF, in Segoe UI 12 pt unless told otherwise |
|
|
222
226
|
| `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
227
|
| `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
228
|
| `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
229
|
| `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 `''` |
|
|
230
|
+
| `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
231
|
| `downloadFile(name, content, mime): void` | Trigger a file download in the browser |
|
|
228
232
|
|
|
229
233
|
---
|
|
@@ -250,15 +254,67 @@ An application that shows documents in more than one place does well to keep the
|
|
|
250
254
|
|
|
251
255
|
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
256
|
|
|
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.
|
|
257
|
+
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
258
|
|
|
255
259
|
- `fontFamily` is used for the whole document: body text, headings, lists and tables. Code keeps Courier New.
|
|
256
260
|
- `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
261
|
- 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 `'
|
|
262
|
+
- `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
263
|
- `fontSize` is rounded to the nearest half-point, which is what RTF measures in, and kept between 1 and 1638 pt.
|
|
260
264
|
- 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
265
|
|
|
266
|
+
### The toolbar of a long document
|
|
267
|
+
|
|
268
|
+
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.
|
|
269
|
+
|
|
270
|
+
- 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.
|
|
271
|
+
- 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.
|
|
272
|
+
- `stickyToolbar={false}` lets the toolbar go with the page, as it did through 1.12.0.
|
|
273
|
+
|
|
274
|
+
### Opening a link
|
|
275
|
+
|
|
276
|
+
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.
|
|
277
|
+
|
|
278
|
+
- The link opens in a new tab, which is given no access to your page and is not told where it was opened from.
|
|
279
|
+
- Only an address `isSafeLinkUrl` accepts is opened: a web, mail or phone address.
|
|
280
|
+
- 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.
|
|
281
|
+
- 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.
|
|
282
|
+
|
|
283
|
+
### A font the screen does not have
|
|
284
|
+
|
|
285
|
+
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.
|
|
286
|
+
|
|
287
|
+
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:
|
|
288
|
+
|
|
289
|
+
```css
|
|
290
|
+
/* Your page's stylesheet. The files are served by your own application. */
|
|
291
|
+
@font-face { font-family: "Selawik"; font-weight: 400; src: url("/fonts/selawik-regular.woff2") format("woff2"); }
|
|
292
|
+
@font-face { font-family: "Selawik"; font-weight: 700; src: url("/fonts/selawik-bold.woff2") format("woff2"); }
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
```svelte
|
|
296
|
+
<InkEditor fontFamily="Segoe UI, Selawik, sans-serif" />
|
|
297
|
+
<RtfViewer content={rtf} fontFamily="Segoe UI, Selawik, sans-serif" />
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
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']}`.
|
|
301
|
+
|
|
302
|
+
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:
|
|
303
|
+
|
|
304
|
+
| Font | Stand-in |
|
|
305
|
+
| --- | --- |
|
|
306
|
+
| Segoe UI | Selawik (upright cuts only: italic is slanted by the browser) |
|
|
307
|
+
| Calibri | Carlito |
|
|
308
|
+
| Cambria | Caladea |
|
|
309
|
+
| Arial | Arimo, Liberation Sans |
|
|
310
|
+
| Times New Roman | Tinos, Liberation Serif |
|
|
311
|
+
| Courier New | Cousine, Liberation Mono |
|
|
312
|
+
|
|
313
|
+
- 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.
|
|
314
|
+
- 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.
|
|
315
|
+
- 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.
|
|
316
|
+
- This package loads no fonts and makes no requests. The stylesheet and the files are your page's.
|
|
317
|
+
|
|
262
318
|
### Size of selected text
|
|
263
319
|
|
|
264
320
|
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 +328,30 @@ The toolbar has a list of sizes, next to the list of paragraph kinds. A size cho
|
|
|
272
328
|
|
|
273
329
|
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
330
|
|
|
331
|
+
### Fonts for selected text
|
|
332
|
+
|
|
333
|
+
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:
|
|
334
|
+
|
|
335
|
+
```svelte
|
|
336
|
+
<InkEditor fonts={['Georgia', 'Calibri, Carlito, sans-serif', 'Arial']} bind:this={editor} />
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
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.
|
|
340
|
+
|
|
341
|
+
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.
|
|
342
|
+
|
|
343
|
+
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).
|
|
344
|
+
|
|
345
|
+
- 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.
|
|
346
|
+
- 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.
|
|
347
|
+
- 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`.
|
|
348
|
+
- 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.
|
|
349
|
+
- 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.
|
|
350
|
+
- 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.
|
|
351
|
+
- 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.
|
|
352
|
+
- 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
|
+
- [Clear formatting](#clear-formatting) takes a font off with the rest.
|
|
354
|
+
|
|
275
355
|
### Clear formatting
|
|
276
356
|
|
|
277
357
|
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,8 +366,9 @@ The toolbar's Clear formatting button, next to the text color, takes the formatt
|
|
|
286
366
|
| | Elements carrying your `keepAttributes` or `keepClasses` |
|
|
287
367
|
|
|
288
368
|
- 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.
|
|
369
|
+
- 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.
|
|
290
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.
|
|
291
372
|
- 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
373
|
|
|
293
374
|
---
|
|
@@ -326,6 +407,7 @@ A `<p>` or `<div>` keeps its own indents, spacing and tab stops in the RTF, so a
|
|
|
326
407
|
| `<ul>`, `<ol>` | one paragraph per item: `\li720\fi-360`, then `\bullet\tab` or `1.\tab` | `<ul>`, `<ol>` |
|
|
327
408
|
| a list inside a list item | the same, `\li720` further in for each level | a list inside the item |
|
|
328
409
|
| `<ol start="5">` | `5.\tab`, `6.\tab`, … | `<ol start="5">` |
|
|
410
|
+
| `<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
411
|
| `<a href="https://…">` | `{\field{\*\fldinst HYPERLINK "…"}{\fldrslt …}}`, underlined, in the link color | `<a href="https://…" target="_blank" rel="noopener noreferrer">` |
|
|
330
412
|
| `<code>` | `\f1` (Courier New) | `<code>` |
|
|
331
413
|
| `<pre>` | a paragraph in `\f1` at 5/6 of the body size, lines separated by `\line` | `<pre>` |
|
|
@@ -335,7 +417,9 @@ A `<p>` or `<div>` keeps its own indents, spacing and tab stops in the RTF, so a
|
|
|
335
417
|
| `<table>` | one `\trowd … \row` per row; see [Tables](#tables) | `<table>` |
|
|
336
418
|
| `<br>` | `\line` | `<br>` |
|
|
337
419
|
|
|
338
|
-
- **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
|
|
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.
|
|
421
|
+
- **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.
|
|
339
423
|
- **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
424
|
- **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
425
|
- **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.
|
|
@@ -405,7 +489,7 @@ Size is not the only way to exhaust a page: a file of nothing but braces is smal
|
|
|
405
489
|
|
|
406
490
|
### Markdown export
|
|
407
491
|
|
|
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`, 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.
|
|
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.
|
|
409
493
|
|
|
410
494
|
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
495
|
|
|
@@ -420,7 +504,11 @@ The components use CSS custom properties with sensible fallbacks, so they work o
|
|
|
420
504
|
--text: #2c2520;
|
|
421
505
|
--text-muted: #8a7e72;
|
|
422
506
|
--surface: #f2f0ec;
|
|
423
|
-
--border: #e5e2dc;
|
|
507
|
+
--border: #e5e2dc; /* also the box around the toolbar's lists */
|
|
508
|
+
--border-active: #c4b5a0; /* that box, and the editor's, under the pointer */
|
|
509
|
+
--bg-select: transparent; /* inside the toolbar's lists */
|
|
510
|
+
--bg-toolbar: #fff; /* the toolbar; not see-through, the document passes under it */
|
|
511
|
+
--ink-toolbar-top: 0px; /* where the toolbar stays: the height of a header of yours that stays too */
|
|
424
512
|
--ink: #1a1714;
|
|
425
513
|
--accent: #6e56cf;
|
|
426
514
|
--accent-soft: #ede9fe;
|
|
@@ -439,6 +527,7 @@ The components use CSS custom properties with sensible fallbacks, so they work o
|
|
|
439
527
|
| `Ctrl+I` | Italic |
|
|
440
528
|
| `Ctrl+U` | Underline |
|
|
441
529
|
| `Ctrl+K` | Insert link |
|
|
530
|
+
| `Ctrl+click` / `Cmd+click` | Open the link under the pointer in a new tab |
|
|
442
531
|
| `Ctrl+S` | Save (fires `onsave`) |
|
|
443
532
|
| `Backspace` / `Delete` | Remove the selected image |
|
|
444
533
|
| `Ctrl+]` / `Cmd+]` | Increase indent of the selected paragraphs by 0.5 in (RTF `\li720` per step) |
|
|
@@ -482,6 +571,10 @@ A browser copies a paragraph with its looks written out as inline styles, and re
|
|
|
482
571
|
|
|
483
572
|
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
573
|
|
|
574
|
+
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.
|
|
575
|
+
|
|
576
|
+
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.
|
|
577
|
+
|
|
485
578
|
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
579
|
|
|
487
580
|
Paragraph alignment (left, center, right, justify) is written to RTF as `\qc`, `\qr` or `\qj`.
|
|
@@ -582,7 +675,7 @@ Four commands must pass before a change is merged, and CI (`.github/workflows/ci
|
|
|
582
675
|
npm run check # svelte-check: types
|
|
583
676
|
npm run test:coverage # vitest, with a floor under the coverage (vite.config.ts)
|
|
584
677
|
npm run prepack # build the package and lint it with publint
|
|
585
|
-
npm run test:e2e # Playwright, in Chromium (once: npx playwright install chromium)
|
|
678
|
+
npm run test:e2e # Playwright, in Chromium, Firefox and WebKit (once: npx playwright install chromium firefox webkit)
|
|
586
679
|
```
|
|
587
680
|
|
|
588
681
|
`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.
|