svelte-rtf-editor 1.6.0 → 1.8.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 +59 -2
- package/dist/components/InkEditor.svelte +803 -1
- package/dist/components/Toolbar.svelte +42 -1
- package/dist/components/Toolbar.svelte.d.ts +3 -0
- package/dist/rtf-parser.js +84 -9
- package/dist/rtf-writer.js +248 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -202,6 +202,27 @@ The font has to be installed on the machine that displays the document. The RTF
|
|
|
202
202
|
|
|
203
203
|
---
|
|
204
204
|
|
|
205
|
+
## Paragraph formatting
|
|
206
|
+
|
|
207
|
+
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:
|
|
208
|
+
|
|
209
|
+
| HTML on the paragraph | RTF |
|
|
210
|
+
|---|---|
|
|
211
|
+
| `margin-left: 1.75in` | `\li2520` |
|
|
212
|
+
| `margin-right: 0.5in` | `\ri720` |
|
|
213
|
+
| `text-indent: -1.75in` | `\fi-2520` |
|
|
214
|
+
| `margin-top: 5pt` / `margin-bottom: 5pt` | `\sb100` / `\sa100` |
|
|
215
|
+
| `break-after: avoid` or `page-break-after: avoid` | `\keepn` |
|
|
216
|
+
| `data-rtf-tab-stops="1.75in"` (comma-separated) | `\tx2520` |
|
|
217
|
+
|
|
218
|
+
- 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.
|
|
219
|
+
- 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`.
|
|
220
|
+
- `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`.
|
|
221
|
+
- Inside a table cell the cell declares its own paragraph: only alignment and the left indent are written there, not the right or first-line indent, spacing, tab stops or keep-with-next.
|
|
222
|
+
- `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.
|
|
223
|
+
- 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.
|
|
224
|
+
- `rtfToHtml` does not yet read spacing, keep-with-next or tab stops back.
|
|
225
|
+
|
|
205
226
|
## Theming
|
|
206
227
|
|
|
207
228
|
The components use CSS custom properties with sensible fallbacks, so they work out of the box but are easy to customise. Override these in your own CSS:
|
|
@@ -232,10 +253,46 @@ The components use CSS custom properties with sensible fallbacks, so they work o
|
|
|
232
253
|
| `Ctrl+K` | Insert link |
|
|
233
254
|
| `Ctrl+S` | Save (fires `onsave`) |
|
|
234
255
|
| `Backspace` / `Delete` | Remove the selected image |
|
|
235
|
-
| `
|
|
236
|
-
| `
|
|
256
|
+
| `Ctrl+]` / `Cmd+]` | Increase indent of the selected paragraphs by 0.5 in (RTF `\li720` per step) |
|
|
257
|
+
| `Ctrl+[` / `Cmd+[` | Decrease indent |
|
|
258
|
+
| `Tab` | Insert a tab (sent to RTF as `\tab`); two spaces in a code block. With several lines selected, increase their indent |
|
|
259
|
+
| `Shift+Tab` | Remove one tab from the start of the line. With several lines selected, decrease their indent |
|
|
237
260
|
| `Esc`, then `Tab` / `Shift+Tab` | Move focus out of the editor |
|
|
238
261
|
|
|
262
|
+
The toolbar's Increase indent and Decrease indent buttons do the same as `Ctrl+]` and `Ctrl+[`. Undo reverses an indent step until the next edit.
|
|
263
|
+
|
|
264
|
+
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):
|
|
265
|
+
|
|
266
|
+
| Button | What moves | RTF per step |
|
|
267
|
+
|---|---|---|
|
|
268
|
+
| Increase / Decrease hanging indent | Every line but the first; the first line stays where it is | `\li720\fi-720` |
|
|
269
|
+
| Increase / Decrease right indent | The right edge of the paragraph | `\ri720` |
|
|
270
|
+
|
|
271
|
+
Decrease indent stops where the first line of a hanging paragraph reaches the left edge.
|
|
272
|
+
|
|
273
|
+
**Hang at caret** sets the hanging indent to any distance: put the caret where the later lines should begin, for example after `A. Pancreas: `, and press the button. The first line stays where it starts and the lines after it begin under the caret. With the caret at the start of the line, the hang is taken away. When a tab comes before the caret, the paragraph also gets a tab stop at the new indent (`tab-size` on screen, `data-rtf-tab-stops` for the RTF's `\tx`), so the text after the tab lines up with the lines below it. Tab stops the paragraph already has are kept. It works on a paragraph outside a table cell that is aligned left or justified.
|
|
274
|
+
|
|
275
|
+
### Copy format
|
|
276
|
+
|
|
277
|
+
The **Copy format** button gives several paragraphs the same alignment and indents:
|
|
278
|
+
|
|
279
|
+
1. Press the button. The pointer becomes a crosshair and a bar under the toolbar says what to click.
|
|
280
|
+
2. Click the paragraph to copy from. A dashed frame marks it and the pointer becomes a brush.
|
|
281
|
+
3. Click each paragraph that should get the format. The one under the pointer is highlighted.
|
|
282
|
+
|
|
283
|
+
It stays on until **Done** in the bar, `Esc`, or the button again. Each click is one Undo step.
|
|
284
|
+
|
|
285
|
+
- What is copied is the paragraph's alignment, indent, right indent and hanging indent, with the tab stop Hang at caret sets. Bold, italic, color and size are not.
|
|
286
|
+
- A click in the margin beside a paragraph, or in the empty space below the text, does nothing.
|
|
287
|
+
- Copying from a plain paragraph clears those from the paragraphs clicked.
|
|
288
|
+
- Each block takes what the RTF carries for it: a heading everything but the tab stop, and a heading or paragraph in a table cell the alignment and the indent only. Lists, code blocks and pictures are left alone.
|
|
289
|
+
- The frame, the highlight and the bar are not part of the text and never reach `getHTML()` or the RTF.
|
|
290
|
+
|
|
291
|
+
### Pasted text
|
|
292
|
+
|
|
293
|
+
A browser copies a paragraph with its looks written out as inline styles, and repeats its `id`. After a paste, each element that came in loses its `id` and any margin or first-line indent that changes nothing on screen, so a copy pasted inside the editor is the same markup as its source. A line the browser makes as a `<div>` is spaced like a `<p>`; both are written to RTF as a paragraph.
|
|
294
|
+
Paragraph alignment (left, center, right, justify) is written to RTF as `\qc`, `\qr` or `\qj`.
|
|
295
|
+
|
|
239
296
|
Tab stays in the editor so a line can be indented. To leave the editor from the keyboard, press
|
|
240
297
|
`Esc` first. A readonly editor leaves Tab to the browser.
|
|
241
298
|
|