Skip to content

Commit bdd1876

Browse files
committed
feat: make <a> tags with no href or empty href not treated as links
1 parent 6996dfd commit bdd1876

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

ios/inputParser/InputParser.mm

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,20 @@ - (NSArray *)getTextAndStylesFromHtml:(NSString *)fixedHtml {
610610
} else if([tagName isEqualToString:@"code"]) {
611611
[styleArr addObject:@([InlineCodeStyle getStyleType])];
612612
} else if([tagName isEqualToString:@"a"]) {
613+
NSRegularExpression *hrefRegex = [NSRegularExpression regularExpressionWithPattern:@"href=\".+\""
614+
options:0
615+
error:nullptr
616+
];
617+
NSTextCheckingResult* match = [hrefRegex firstMatchInString:params options:0 range: NSMakeRange(0, params.length)];
618+
619+
if(match == nullptr) {
620+
// same as on Android, no href (or empty href) equals no link style
621+
continue;
622+
}
623+
624+
NSRange hrefRange = match.range;
613625
[styleArr addObject:@([LinkStyle getStyleType])];
614-
// cut only the url from the href="..." string
615-
NSString *url = [params substringWithRange:NSMakeRange(6, params.length - 7)];
626+
NSString *url = [params substringWithRange:NSMakeRange(hrefRange.location + 6, hrefRange.length - 7)];
616627
stylePair.styleValue = url;
617628
} else if([tagName isEqualToString:@"mention"]) {
618629
[styleArr addObject:@([MentionStyle getStyleType])];
@@ -657,7 +668,7 @@ - (NSArray *)getTextAndStylesFromHtml:(NSString *)fixedHtml {
657668
} else if([tagName isEqualToString:@"blockquote"]) {
658669
[styleArr addObject:@([BlockQuoteStyle getStyleType])];
659670
} else {
660-
// some other external tags like span just don't get put into the processed styles
671+
// some other external tags like span just don't get put into the processed styles
661672
continue;
662673
}
663674

0 commit comments

Comments
 (0)