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/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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-rtf-editor",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "RTF viewer and rich-text editor components for Svelte 5",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/jcelano/svelte-rtf-editor#readme",