@expensify/react-native-live-markdown 0.1.11 → 0.1.13
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/android/src/main/java/com/expensify/livemarkdown/MarkdownUtils.java +6 -4
- package/ios/RCTBaseTextInputView+Markdown.m +13 -4
- package/ios/RCTMarkdownUtils.mm +4 -4
- package/lib/commonjs/web/parserUtils.js +6 -13
- package/lib/commonjs/web/parserUtils.js.map +1 -1
- package/lib/module/web/parserUtils.js +6 -13
- package/lib/module/web/parserUtils.js.map +1 -1
- package/lib/parser/react-native-live-markdown-parser.js +4 -4
- package/lib/typescript/src/web/parserUtils.d.ts +2 -1
- package/lib/typescript/src/web/parserUtils.d.ts.map +1 -1
- package/package.json +1 -1
- package/parser/react-native-live-markdown-parser.js +4 -4
- package/src/web/parserUtils.ts +8 -14
package/src/web/parserUtils.ts
CHANGED
|
@@ -7,8 +7,9 @@ type MarkdownType = 'bold' | 'italic' | 'strikethrough' | 'link' | 'code' | 'pre
|
|
|
7
7
|
|
|
8
8
|
type MarkdownRange = {
|
|
9
9
|
type: MarkdownType;
|
|
10
|
-
|
|
10
|
+
start: number;
|
|
11
11
|
length: number;
|
|
12
|
+
depth?: number;
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
type NestedNode = {
|
|
@@ -99,10 +100,10 @@ function parseRangesToHTMLNodes(text: string, ranges: MarkdownRange[], markdownS
|
|
|
99
100
|
break;
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
const endOfCurrentRange = range.
|
|
103
|
-
const nextRangeStartIndex = stack.length > 0 && !!stack[0] ? stack[0].
|
|
103
|
+
const endOfCurrentRange = range.start + range.length;
|
|
104
|
+
const nextRangeStartIndex = stack.length > 0 && !!stack[0] ? stack[0].start || 0 : textLength;
|
|
104
105
|
|
|
105
|
-
addSubstringAsTextNode(currentRoot.node, text, lastRangeEndIndex, range.
|
|
106
|
+
addSubstringAsTextNode(currentRoot.node, text, lastRangeEndIndex, range.start); // add text with newlines before current range
|
|
106
107
|
|
|
107
108
|
const span = document.createElement('span');
|
|
108
109
|
if (disableInlineStyles) {
|
|
@@ -115,9 +116,9 @@ function parseRangesToHTMLNodes(text: string, ranges: MarkdownRange[], markdownS
|
|
|
115
116
|
// tag nesting
|
|
116
117
|
currentRoot.node.appendChild(span);
|
|
117
118
|
nestedStack.push({node: span, endIndex: endOfCurrentRange});
|
|
118
|
-
lastRangeEndIndex = range.
|
|
119
|
+
lastRangeEndIndex = range.start;
|
|
119
120
|
} else {
|
|
120
|
-
addSubstringAsTextNode(span, text, range.
|
|
121
|
+
addSubstringAsTextNode(span, text, range.start, endOfCurrentRange);
|
|
121
122
|
currentRoot.node.appendChild(span);
|
|
122
123
|
lastRangeEndIndex = endOfCurrentRange;
|
|
123
124
|
|
|
@@ -162,14 +163,7 @@ function parseText(
|
|
|
162
163
|
}
|
|
163
164
|
const ranges = global.parseExpensiMarkToRanges(text);
|
|
164
165
|
|
|
165
|
-
const markdownRanges: MarkdownRange[] = ranges
|
|
166
|
-
const [type, startIndex, length] = range;
|
|
167
|
-
return {
|
|
168
|
-
type: type as MarkdownType,
|
|
169
|
-
startIndex,
|
|
170
|
-
length,
|
|
171
|
-
};
|
|
172
|
-
});
|
|
166
|
+
const markdownRanges: MarkdownRange[] = ranges as MarkdownRange[];
|
|
173
167
|
|
|
174
168
|
targetElement.innerHTML = '';
|
|
175
169
|
targetElement.innerText = '';
|