From b50312182c3a4b1c8f96d1db5e1a319ad7acf800 Mon Sep 17 00:00:00 2001 From: Tomek Zawadzki Date: Mon, 16 Dec 2024 12:13:47 +0100 Subject: [PATCH] Fix blockquote line height on iOS --- apple/MarkdownFormatter.mm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apple/MarkdownFormatter.mm b/apple/MarkdownFormatter.mm index 9020978d..4225a90b 100644 --- a/apple/MarkdownFormatter.mm +++ b/apple/MarkdownFormatter.mm @@ -25,7 +25,8 @@ - (void)formatAttributedString:(nonnull NSMutableAttributedString *)attributedSt type:std::string([markdownRange.type UTF8String]) range:markdownRange.range depth:markdownRange.depth - markdownStyle:markdownStyle]; + markdownStyle:markdownStyle + defaultTextAttributes:defaultTextAttributes]; } RCTApplyBaselineOffset(attributedString); @@ -55,7 +56,9 @@ - (void)applyRangeToAttributedString:(NSMutableAttributedString *)attributedStri type:(const std::string)type range:(const NSRange)range depth:(const int)depth - markdownStyle:(nonnull RCTMarkdownStyle *)markdownStyle { + markdownStyle:(nonnull RCTMarkdownStyle *)markdownStyle + defaultTextAttributes:(nonnull NSDictionary *)defaultTextAttributes +{ if (type == "bold" || type == "italic" || type == "code" || type == "pre" || type == "h1" || type == "emoji") { UIFont *font = [attributedString attribute:NSFontAttributeName atIndex:range.location effectiveRange:NULL]; if (type == "bold") { @@ -116,7 +119,8 @@ - (void)applyRangeToAttributedString:(NSMutableAttributedString *)attributedStri [attributedString addAttribute:NSForegroundColorAttributeName value:markdownStyle.linkColor range:range]; } else if (type == "blockquote") { CGFloat indent = (markdownStyle.blockquoteMarginLeft + markdownStyle.blockquoteBorderWidth + markdownStyle.blockquotePaddingLeft) * depth; - NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new]; + NSParagraphStyle *defaultParagraphStyle = defaultTextAttributes[NSParagraphStyleAttributeName]; + NSMutableParagraphStyle *paragraphStyle = defaultParagraphStyle != nil ? [defaultParagraphStyle mutableCopy] : [NSMutableParagraphStyle new]; paragraphStyle.firstLineHeadIndent = indent; paragraphStyle.headIndent = indent; [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range];