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
30 changes: 18 additions & 12 deletions ios/inputParser/InputParser.mm
Original file line number Diff line number Diff line change
Expand Up @@ -772,18 +772,24 @@ - (NSString *_Nullable)initiallyProcessHtml:(NSString *_Nonnull)html {
if (normalized != nil) {
fixedHtml = normalized;
}
} else {
// in other case we are most likely working with some external html - try
// getting the styles from between body tags
NSRange openingBodyRange = [htmlWithoutSpaces rangeOfString:@"<body>"];
NSRange closingBodyRange = [htmlWithoutSpaces rangeOfString:@"</body>"];

if (openingBodyRange.length != 0 && closingBodyRange.length != 0) {
NSInteger newStart = openingBodyRange.location + 7;
NSInteger newEnd = closingBodyRange.location - 1;
fixedHtml = [htmlWithoutSpaces
substringWithRange:NSMakeRange(newStart, newEnd - newStart + 1)];
}
}

// Additionally, try getting the content from between body tags if there are
// some:

// Firstly make sure there are no newlines between them.
fixedHtml = [fixedHtml stringByReplacingOccurrencesOfString:@"<body>\n"
withString:@"<body>"];
fixedHtml = [fixedHtml stringByReplacingOccurrencesOfString:@"\n</body>"
withString:@"</body>"];
// Then, if there actually are body tags, use the content between them.
NSRange openingBodyRange = [htmlWithoutSpaces rangeOfString:@"<body>"];
NSRange closingBodyRange = [htmlWithoutSpaces rangeOfString:@"</body>"];
if (openingBodyRange.length != 0 && closingBodyRange.length != 0) {
NSInteger newStart = openingBodyRange.location + 6;
NSInteger newEnd = closingBodyRange.location - 1;
fixedHtml = [htmlWithoutSpaces
substringWithRange:NSMakeRange(newStart, newEnd - newStart + 1)];
}
}

Expand Down
Loading