@@ -405,24 +405,16 @@ - (NSString * _Nullable)initiallyProcessHtml:(NSString * _Nonnull)html {
405405 if (html.length >= 13 ) {
406406 NSString *firstSix = [html substringWithRange: NSMakeRange (0 , 6 )];
407407 NSString *lastSeven = [html substringWithRange: NSMakeRange (html.length-7 , 7 )];
408- NSInteger newlinesCount = [[html componentsSeparatedByString: @" \n " ] count ] - 1 ;
409408
410409 if ([firstSix isEqualToString: @" <html>" ] && [lastSeven isEqualToString: @" </html>" ]) {
411- if (newlinesCount >= 2 ) {
412- // looks like our format
413- // we want to get the string without <html> and </html> and their newlines
414- // so we skip first 7 characters and get the string 7+8 = 15 characters shorter
415- fixedHtml = [html substringWithRange: NSMakeRange (7 , html.length - 15 )];
416- } else {
417- // most likely a valid html but with some newline differences
418- fixedHtml = [html copy ];
410+ // remove html tags, might be with newlines or without them
411+ fixedHtml = [html copy ];
419412 // firstly remove newlined html tags if any:
420413 fixedHtml = [fixedHtml stringByReplacingOccurrencesOfString: @" <html>\n " withString: @" " ];
421414 fixedHtml = [fixedHtml stringByReplacingOccurrencesOfString: @" \n </html>" withString: @" " ];
422415 // fallback; remove html tags without their newlines
423416 fixedHtml = [fixedHtml stringByReplacingOccurrencesOfString: @" <html>" withString: @" " ];
424417 fixedHtml = [fixedHtml stringByReplacingOccurrencesOfString: @" </html>" withString: @" " ];
425- }
426418 } else {
427419 // in other case we are most likely working with some external html - try getting the styles from between body tags
428420 NSRange openingBodyRange = [html rangeOfString: @" <body>" ];
@@ -438,8 +430,6 @@ - (NSString * _Nullable)initiallyProcessHtml:(NSString * _Nonnull)html {
438430
439431 // second processing - try fixing htmls with wrong newlines' setup
440432 if (fixedHtml != nullptr ) {
441- NSInteger newlinesCount = [[fixedHtml componentsSeparatedByString: @" /n" ] count ] - 1 ;
442- if (newlinesCount == 0 ) {
443433 // add <br> tag wherever needed
444434 fixedHtml = [fixedHtml stringByReplacingOccurrencesOfString: @" <p></p>" withString: @" <br>" ];
445435
@@ -469,7 +459,6 @@ - (NSString * _Nullable)initiallyProcessHtml:(NSString * _Nonnull)html {
469459 fixedHtml = [self stringByAddingNewlinesToTag: @" </h1>" inString: fixedHtml leading: NO trailing: YES ];
470460 fixedHtml = [self stringByAddingNewlinesToTag: @" </h2>" inString: fixedHtml leading: NO trailing: YES ];
471461 fixedHtml = [self stringByAddingNewlinesToTag: @" </h3>" inString: fixedHtml leading: NO trailing: YES ];
472- }
473462 }
474463
475464 return fixedHtml;
0 commit comments