Skip to content
Merged
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
24 changes: 21 additions & 3 deletions ios/inputParser/InputParser.mm
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,25 @@ - (NSString *)parseToHtmlFromRange:(NSRange)range {
}
}

// if a style begins but there is a style inner to it that is (and was previously) active, it also should be closed and readded

// newly added styles
NSMutableSet *newStyles = [currentActiveStyles mutableCopy];
[newStyles minusSet: previousActiveStyles];
// styles that were and still are active
NSMutableSet *stillActiveStyles = [previousActiveStyles mutableCopy];
[stillActiveStyles intersectSet:currentActiveStyles];

for(NSNumber *style in newStyles) {
for(NSNumber *ongoingStyle in stillActiveStyles) {
if([ongoingStyle integerValue] > [style integerValue]) {
// the prev style is inner; needs to be closed and re-added later
[fixedEndedStyles addObject:ongoingStyle];
[stylesToBeReAdded addObject:ongoingStyle];
}
}
}

// they are sorted in a descending order
NSArray<NSNumber*> *sortedEndedStyles = [fixedEndedStyles sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"intValue" ascending:NO]]];

Expand All @@ -193,9 +212,8 @@ - (NSString *)parseToHtmlFromRange:(NSRange)range {
[result appendString: [NSString stringWithFormat:@"</%@>", tagContent]];
}

// get styles that have begun: they are sorted in a ascending manner to properly keep tags' FILO order
NSMutableSet<NSNumber *> *newStyles = [currentActiveStyles mutableCopy];
[newStyles minusSet: previousActiveStyles];
// all styles that have begun: new styles + the ones that need to be re-added
// they are sorted in a ascending manner to properly keep tags' FILO order
[newStyles unionSet: stylesToBeReAdded];
NSArray<NSNumber*> *sortedNewStyles = [newStyles sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"intValue" ascending:YES]]];

Expand Down
Loading