@expensify/react-native-live-markdown 0.1.13 → 0.1.14

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.
@@ -78,6 +78,20 @@ function addSubstringAsTextNode(root: HTMLElement, text: string, startIndex: num
78
78
  }
79
79
  }
80
80
 
81
+ function ungroupRanges(ranges: MarkdownRange[]): MarkdownRange[] {
82
+ const ungroupedRanges: MarkdownRange[] = [];
83
+ ranges.forEach((range) => {
84
+ if (!range.depth) {
85
+ ungroupedRanges.push(range);
86
+ }
87
+ const {depth, ...rangeWithoutDepth} = range;
88
+ Array.from({length: depth!}).forEach(() => {
89
+ ungroupedRanges.push(rangeWithoutDepth);
90
+ });
91
+ });
92
+ return ungroupedRanges;
93
+ }
94
+
81
95
  function parseRangesToHTMLNodes(text: string, ranges: MarkdownRange[], markdownStyle: PartialMarkdownStyle = {}, disableInlineStyles = false): HTMLElement {
82
96
  const root: HTMLElement = document.createElement('span');
83
97
  root.className = 'root';
@@ -87,7 +101,7 @@ function parseRangesToHTMLNodes(text: string, ranges: MarkdownRange[], markdownS
87
101
  return root;
88
102
  }
89
103
 
90
- const stack = [...ranges];
104
+ const stack = ungroupRanges(ranges);
91
105
  const nestedStack: NestedNode[] = [{node: root, endIndex: textLength}];
92
106
  let lastRangeEndIndex = 0;
93
107
  while (stack.length > 0) {