Skip to content

Commit

Permalink
Pass ranges as objects instead of arrays (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertKozik authored Feb 23, 2024
1 parent 56b3ca8 commit d0aa9ec
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -91,10 +92,11 @@ public void applyMarkdownFormatting(SpannableStringBuilder ssb) {
try {
JSONArray ranges = new JSONArray(output);
for (int i = 0; i < ranges.length(); i++) {
JSONArray range = ranges.getJSONArray(i);
String type = range.getString(0);
int start = range.getInt(1);
int end = start + range.getInt(2);
JSONObject range = ranges.getJSONObject(i);
String type = range.getString("type");
int start = range.getInt("start");
int length = range.getInt("length");
int end = start + length;
applyRange(ssb, type, start, end);
}
} catch (JSONException e) {
Expand Down
8 changes: 4 additions & 4 deletions ios/RCTMarkdownUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ - (NSAttributedString *)parseMarkdown:(nullable NSAttributedString *)input
_blockquoteRanges = [NSMutableArray new];

[ranges enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSArray *item = obj;
NSString *type = item[0];
NSUInteger location = [item[1] unsignedIntegerValue];
NSUInteger length = [item[2] unsignedIntegerValue];
NSDictionary *item = obj;
NSString *type = [item valueForKey:@"type"];
NSInteger location = [[item valueForKey:@"start"] unsignedIntegerValue];
NSInteger length = [[item valueForKey:@"length"] unsignedIntegerValue];
NSRange range = NSMakeRange(location, length);

if ([type isEqualToString:@"bold"] || [type isEqualToString:@"italic"] || [type isEqualToString:@"code"] || [type isEqualToString:@"pre"] || [type isEqualToString:@"h1"]) {
Expand Down
Loading

0 comments on commit d0aa9ec

Please sign in to comment.