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/dist/utils.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { linkTarget } from './rtf-writer.js';
|
|
2
2
|
import { tableModel } from './table-model.js';
|
|
3
|
+
import { itemNumber, listStart, markerText, numberStyleOf } from './list-markers.js';
|
|
3
4
|
/** Elements whose text is never shown. */
|
|
4
5
|
const UNSHOWN_TAGS = new Set(['style', 'script', 'template', 'noscript', 'title', 'head']);
|
|
5
6
|
/** Elements that are a line of their own and nothing more, as a <div> is. */
|
|
@@ -75,6 +76,8 @@ function imageToMarkdown(alt, src, ctx) {
|
|
|
75
76
|
* A list item's Markdown under its marker: later lines are indented to the item's text, so a
|
|
76
77
|
* table, a code block or a list inside the item stays in it.
|
|
77
78
|
*/
|
|
79
|
+
/** A block of Markdown that is not a paragraph of words: a list, a quotation, a heading, code, a table, a rule. */
|
|
80
|
+
const BLOCK_START = /^(?:```|~~~|>|#{1,6}(?: |$)|[-+*](?: |$)|\d{1,9}[.)](?: |$)|\||(?:-{3,}|\*{3,}|_{3,})\s*$| {4})/;
|
|
78
81
|
function listItem(marker, body) {
|
|
79
82
|
// (Spaces and line breaks only are taken off its ends: other white space is the document's.)
|
|
80
83
|
return `${marker}${body.replace(/^[ \n]+|[ \n]+$/g, '').replace(/\n(?=[^\n])/g, `\n${' '.repeat(marker.length)}`)}`;
|
|
@@ -550,6 +553,10 @@ function listToMarkdown(list, ordered, ctx, out) {
|
|
|
550
553
|
// block: the list starts as near to its own number as Markdown can count from.
|
|
551
554
|
const itemCount = Array.from(list.children).filter((child) => child.tagName === 'LI').length;
|
|
552
555
|
let number = Number.isFinite(start) ? Math.max(0, Math.min(start, 1_000_000_000 - Math.max(itemCount, 1))) : 1;
|
|
556
|
+
// The number the screen shows, for an item numbered in letters or Roman numerals. Markdown
|
|
557
|
+
// numbers a list in digits only, and "see part B" has to find an item that says "B.": such
|
|
558
|
+
// an item is written as a bullet with its marker as the first words, "- B. Left breast".
|
|
559
|
+
let shownNumber = listStart(list);
|
|
553
560
|
let items = [];
|
|
554
561
|
let loose = [];
|
|
555
562
|
const endItems = () => {
|
|
@@ -573,9 +580,23 @@ function listToMarkdown(list, ordered, ctx, out) {
|
|
|
573
580
|
if (!inside)
|
|
574
581
|
return;
|
|
575
582
|
const blocks = blocksOf(node.childNodes, inside);
|
|
583
|
+
const style = ordered ? numberStyleOf(list, node) : 'decimal';
|
|
584
|
+
shownNumber = itemNumber(node, shownNumber);
|
|
585
|
+
const label = style === 'decimal' ? '' : `${markerText(shownNumber, style)}.`;
|
|
586
|
+
shownNumber++;
|
|
587
|
+
if (label) {
|
|
588
|
+
// Before the words of the item; on a line of its own before a block that is not
|
|
589
|
+
// words (a list, a code block, a table, a quotation).
|
|
590
|
+
if (blocks.length && !BLOCK_START.test(blocks[0]))
|
|
591
|
+
blocks[0] = `${label} ${blocks[0]}`;
|
|
592
|
+
else
|
|
593
|
+
blocks.unshift(label);
|
|
594
|
+
}
|
|
576
595
|
// An item whose text is hidden shows no marker either.
|
|
577
596
|
if (blocks.length || !inside.unseen)
|
|
578
|
-
items.push({ marker: ordered ? `${number++}. ` : '- ', blocks });
|
|
597
|
+
items.push({ marker: ordered && !label ? `${number++}. ` : '- ', blocks });
|
|
598
|
+
else if (label)
|
|
599
|
+
blocks.shift();
|
|
579
600
|
}
|
|
580
601
|
else if (['ul', 'ol', 'menu', 'dir'].includes(tag)) {
|
|
581
602
|
endLoose();
|
package/package.json
CHANGED