Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass ranges as objects instead of arrays #200

Merged
merged 4 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading