diff --git a/apple/MarkdownFormatter.mm b/apple/MarkdownFormatter.mm index d67e3f07..fdb4116f 100644 --- a/apple/MarkdownFormatter.mm +++ b/apple/MarkdownFormatter.mm @@ -28,7 +28,11 @@ - (nonnull NSAttributedString *)format:(nonnull NSString *)text defaultTextAttributes:defaultTextAttributes]; } - RCTApplyBaselineOffset(attributedString); + [attributedString.string enumerateSubstringsInRange:NSMakeRange(0, attributedString.length) + options:NSStringEnumerationByLines | NSStringEnumerationSubstringNotRequired + usingBlock:^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOL * _Nonnull stop) { + RCTApplyBaselineOffset(attributedString, enclosingRange); + }]; [attributedString endEditing]; @@ -116,12 +120,12 @@ - (void)applyRangeToAttributedString:(NSMutableAttributedString *)attributedStri } } -static void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText) +static void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText, NSRange attributedTextRange) { __block CGFloat maximumLineHeight = 0; [attributedText enumerateAttribute:NSParagraphStyleAttributeName - inRange:NSMakeRange(0, attributedText.length) + inRange:attributedTextRange options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired usingBlock:^(NSParagraphStyle *paragraphStyle, __unused NSRange range, __unused BOOL *stop) { if (!paragraphStyle) { @@ -139,7 +143,7 @@ static void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText) __block CGFloat maximumFontLineHeight = 0; [attributedText enumerateAttribute:NSFontAttributeName - inRange:NSMakeRange(0, attributedText.length) + inRange:attributedTextRange options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired usingBlock:^(UIFont *font, NSRange range, __unused BOOL *stop) { if (!font) { @@ -156,7 +160,7 @@ static void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText) CGFloat baseLineOffset = (maximumLineHeight - maximumFontLineHeight) / 2.0; [attributedText addAttribute:NSBaselineOffsetAttributeName value:@(baseLineOffset) - range:NSMakeRange(0, attributedText.length)]; + range:attributedTextRange]; } @end