svelte-rtf-editor 1.11.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,7 +16,7 @@ RTF viewer and rich-text editor components for **Svelte 5**.
16
16
  - Images: upload, paste or drag-and-drop, with a description below each picture, drag-to-resize and left/centre/right placement — embedded in the RTF, not linked
17
17
  - Import an RTF file from disk; export as RTF, HTML, or Markdown
18
18
  - Optional auto-save to `localStorage` (off unless asked for)
19
- - HTML from outside (the `content` prop, `setHTML`, a restored draft, a paste) is made safe before it is shown. See [HTML from outside](#html-from-outside)
19
+ - 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)
20
20
  - Word count and character count status bar
21
21
  - Keyboard shortcuts (`Ctrl+S` to save, `Ctrl+B/I/U` for formatting)
22
22
  - **Utility functions** — `rtfToHtml`, `htmlToRtf`, `readRtfFile`, `htmlToMarkdown`, `downloadFile`
@@ -145,7 +145,7 @@ Pass an HTML string as `content`. If the content is already RTF, convert it firs
145
145
  | Prop | Payload | Description |
146
146
  |------------|----------------------------------------------|---------------------------------------------|
147
147
  | `onchange` | `{ html, text, wordCount, charCount, estimatedRtfBytes }` | Fired on every content change. `html`, `text` and `estimatedRtfBytes` are worked out when the handler reads them, so a handler that only wants the counts costs nothing on a long document. They are the document as it is when first read: read them in the handler. A payload kept and read after a later edit gives the document as it is by then |
148
- | `onsave` | `{ html }` | Fired on auto-save or `Ctrl+S` |
148
+ | `onsave` | `{ html }` | Fired on `Ctrl+S`, and after each auto-save where `autosave` is on |
149
149
  | `onimport` | `{ html }` | Fired after a successful RTF file import |
150
150
 
151
151
  #### Methods (via `bind:this`)
@@ -153,7 +153,7 @@ Pass an HTML string as `content`. If the content is already RTF, convert it firs
153
153
  ```ts
154
154
  editor.getHTML() // → string — current editor HTML
155
155
  editor.getText() // → string — plain text (no tags)
156
- editor.setHTML(html) // → void — replace content programmatically (made safe first)
156
+ editor.setHTML(html) // → void — replace content programmatically (made safe first; throws, leaving the editor empty, if it cannot be)
157
157
  editor.getMarkdown() // → string — Markdown conversion of content
158
158
  editor.getRTF() // → string — RTF conversion of content
159
159
  editor.getRtfSize() // → number — exact byte size of that RTF
@@ -162,6 +162,7 @@ editor.focus() // → void — focus the editor
162
162
  editor.exportFile(format) // → void — download as 'html' | 'md' | 'rtf'
163
163
  editor.importRtf() // → void — open the file picker to import .rtf
164
164
  editor.setFontSize(14) // → void — size, in points, of the selected text, or of what is typed next
165
+ editor.clearFormatting() // → void — take bold, italic, underline, strike, color, size and font off the selected text
165
166
  ```
166
167
 
167
168
  #### Auto-save
@@ -173,7 +174,11 @@ editor.setFontSize(14) // → void — size, in points, of the selected te
173
174
 
174
175
  #### HTML from outside
175
176
 
176
- Whatever HTML reaches the editor is made safe before it is shown: the `content` prop, `setHTML()`, a draft restored from `localStorage`, and what a paste brings. `sanitizeHtml` is exported for HTML you show yourself (stored editor output in a preview, say).
177
+ Whatever HTML reaches the editor is made safe before it is shown: the `content` prop, `setHTML()`, a draft restored from `localStorage`, what a paste brings, what is dragged in from another page or from elsewhere in the document, and what Undo and Redo put back (Redo after a paste gives the browser's own copy of the paste, not the one that was made safe). `sanitizeHtml` is exported for HTML you show yourself (stored editor output in a preview, say).
178
+
179
+ A paste and a drop are made safe just after the browser has put them in the document, not before: a frame or a picture in them may be asked for from its address in that moment, though it does not stay.
180
+
181
+ An element that cannot be checked is taken out, and a document that cannot be checked at all is not shown: the editor is left empty and says so, `setHTML()` throws, and the document that was there before does not stay on the screen in its place.
177
182
 
178
183
  | Taken out | Why |
179
184
  |---|---|
@@ -267,6 +272,24 @@ The toolbar has a list of sizes, next to the list of paragraph kinds. A size cho
267
272
 
268
273
  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.
269
274
 
275
+ ### Clear formatting
276
+
277
+ 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.
278
+
279
+ | Taken off | Stays |
280
+ | --- | --- |
281
+ | Bold, italic, underline, strikethrough | Headings, lists, block quotes, code blocks, tables |
282
+ | Text color and highlight | Links |
283
+ | Size and font | Alignment, indents, hanging indents, tabs |
284
+ | Superscript, subscript, inline code | Pictures, their size and captions |
285
+ | The same written as a style on a paragraph, a table cell or a pasted `<span>` | A table cell's shading |
286
+ | | Elements carrying your `keepAttributes` or `keepClasses` |
287
+
288
+ - 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. In Safari one Undo may take back the step before it as well.
291
+ - 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
+
270
293
  ---
271
294
 
272
295
  ## Paragraph formatting