diff --git a/ios/inputParser/InputParser.mm b/ios/inputParser/InputParser.mm index 1348728d..dd4008be 100644 --- a/ios/inputParser/InputParser.mm +++ b/ios/inputParser/InputParser.mm @@ -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:@""]; - NSRange closingBodyRange = [htmlWithoutSpaces rangeOfString:@""]; - - 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:@"\n" + withString:@""]; + fixedHtml = [fixedHtml stringByReplacingOccurrencesOfString:@"\n" + withString:@""]; + // Then, if there actually are body tags, use the content between them. + NSRange openingBodyRange = [htmlWithoutSpaces rangeOfString:@""]; + NSRange closingBodyRange = [htmlWithoutSpaces rangeOfString:@""]; + 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)]; } }