@expensify/react-native-live-markdown 0.1.190 → 0.1.191

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.
@@ -0,0 +1,31 @@
1
+ package com.expensify.livemarkdown;
2
+
3
+ public class MarkdownRange {
4
+ private final String mType;
5
+ private final int mStart;
6
+ private final int mLength;
7
+ private final int mDepth;
8
+
9
+ public MarkdownRange(String type, int start, int length, int depth) {
10
+ mType = type;
11
+ mStart = start;
12
+ mLength = length;
13
+ mDepth = depth;
14
+ }
15
+
16
+ public String getType() {
17
+ return mType;
18
+ }
19
+
20
+ public int getStart() {
21
+ return mStart;
22
+ }
23
+
24
+ public int getLength() {
25
+ return mLength;
26
+ }
27
+
28
+ public int getDepth() {
29
+ return mDepth;
30
+ }
31
+ }
@@ -16,6 +16,8 @@ import org.json.JSONArray;
16
16
  import org.json.JSONException;
17
17
  import org.json.JSONObject;
18
18
 
19
+ import java.util.LinkedList;
20
+ import java.util.List;
19
21
  import java.util.Objects;
20
22
 
21
23
  public class MarkdownUtils {
@@ -68,6 +70,7 @@ public class MarkdownUtils {
68
70
  mPrevParserId = mParserId;
69
71
  }
70
72
 
73
+ List<MarkdownRange> markdownRanges = new LinkedList<>();
71
74
  try {
72
75
  JSONArray ranges = new JSONArray(output);
73
76
  for (int i = 0; i < ranges.length(); i++) {
@@ -80,14 +83,21 @@ public class MarkdownUtils {
80
83
  if (length == 0 || end > input.length()) {
81
84
  continue;
82
85
  }
83
- applyRange(ssb, type, start, end, depth);
86
+ markdownRanges.add(new MarkdownRange(type, start, length, depth));
84
87
  }
85
88
  } catch (JSONException e) {
86
89
  RNLog.w(mReactContext, "[react-native-live-markdown] Incorrect schema of worklet parser output: " + e.getMessage());
87
90
  }
91
+
92
+ for (MarkdownRange markdownRange : markdownRanges) {
93
+ applyRange(ssb, markdownRange);
94
+ }
88
95
  }
89
96
 
90
- private void applyRange(SpannableStringBuilder ssb, String type, int start, int end, int depth) {
97
+ private void applyRange(SpannableStringBuilder ssb, MarkdownRange markdownRange) {
98
+ String type = markdownRange.getType();
99
+ int start = markdownRange.getStart();
100
+ int end = start + markdownRange.getLength();
91
101
  switch (type) {
92
102
  case "bold":
93
103
  setSpan(ssb, new MarkdownBoldSpan(), start, end);
@@ -149,7 +159,7 @@ public class MarkdownUtils {
149
159
  mMarkdownStyle.getBlockquoteBorderWidth(),
150
160
  mMarkdownStyle.getBlockquoteMarginLeft(),
151
161
  mMarkdownStyle.getBlockquotePaddingLeft(),
152
- depth);
162
+ markdownRange.getDepth());
153
163
  setSpan(ssb, span, start, end);
154
164
  break;
155
165
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expensify/react-native-live-markdown",
3
- "version": "0.1.190",
3
+ "version": "0.1.191",
4
4
  "description": "Drop-in replacement for React Native's TextInput component with Markdown formatting.",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",