diff --git a/ios/RCTMarkdownUtils.mm b/ios/RCTMarkdownUtils.mm index 06600099..213b426b 100644 --- a/ios/RCTMarkdownUtils.mm +++ b/ios/RCTMarkdownUtils.mm @@ -2,6 +2,7 @@ #import "react_native_assert.h" #import #import +#import #import @implementation RCTMarkdownUtils { @@ -47,13 +48,17 @@ - (NSAttributedString *)parseMarkdown:(nullable NSAttributedString *)input JSValue *result = [function callWithArguments:@[inputString]]; NSArray *ranges = [result toArray]; - NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:inputString attributes:_backedTextInputView.defaultTextAttributes]; + NSMutableAttributedString *attributedString = [input mutableCopy]; [attributedString beginEditing]; + NSMutableDictionary *attributes = [_backedTextInputView.defaultTextAttributes mutableCopy]; + [attributes removeObjectForKey:RCTTextAttributesTagAttributeName]; + [attributedString addAttributes:attributes range:NSMakeRange(0, attributedString.length)]; + // If the attributed string ends with underlined text, blurring the single-line input imprints the underline style across the whole string. // It looks like a bug in iOS, as there is no underline style to be found in the attributed string, especially after formatting. - // This is a workaround that applies the NSUnderlineStyleNone to the string before iterating over ranges which resolves this problem. - [attributedString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleNone] range:NSMakeRange(0, attributedString.length)]; + // The workaround is to remove NSUnderlineStyleAttributeName attribute for whole string before iterating over ranges. + [attributedString removeAttribute:NSUnderlineStyleAttributeName range:NSMakeRange(0, attributedString.length)]; _blockquoteRanges = [NSMutableArray new];