diff --git a/ios/RCTBaseTextInputView+Markdown.m b/ios/RCTBaseTextInputView+Markdown.m index 53521cf3..ad254869 100644 --- a/ios/RCTBaseTextInputView+Markdown.m +++ b/ios/RCTBaseTextInputView+Markdown.m @@ -29,7 +29,7 @@ - (void)markdown_updateLocalData if (markdownUtils != nil) { UITextRange *range = self.backedTextInputView.selectedTextRange; NSAttributedString *attributedText = [markdownUtils parseMarkdown:self.backedTextInputView.attributedText]; - // [self.backedTextInputView setAttributedText:attributedText]; + [self.backedTextInputView setAttributedText:attributedText]; [self.backedTextInputView setSelectedTextRange:range notifyDelegate:YES]; } diff --git a/ios/RCTMarkdownUtils.mm b/ios/RCTMarkdownUtils.mm index 06600099..982b9a78 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)]; + [attributedString removeAttribute:NSUnderlineStyleAttributeName range:NSMakeRange(0, attributedString.length)]; _blockquoteRanges = [NSMutableArray new]; diff --git a/ios/RCTUITextView+Markdown.mm b/ios/RCTUITextView+Markdown.mm index 7ff8057a..7c8bbb74 100644 --- a/ios/RCTUITextView+Markdown.mm +++ b/ios/RCTUITextView+Markdown.mm @@ -17,7 +17,7 @@ - (void)markdown_textDidChange RCTMarkdownUtils *markdownUtils = [self getMarkdownUtils]; if (markdownUtils != nil) { UITextRange *range = self.selectedTextRange; - // super.attributedText = [markdownUtils parseMarkdown:self.attributedText]; + super.attributedText = [markdownUtils parseMarkdown:self.attributedText]; [super setSelectedTextRange:range]; // prevents cursor from jumping at the end when typing in the middle of the text // self.typingAttributes = self.defaultTextAttributes; // removes indent in new line when typing after blockquote // NOTE: setting self.typingAttributes removes underline