Skip to content

Commit

Permalink
Fix blockquote line height on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekzaw committed Dec 16, 2024
1 parent 4c70fba commit b503121
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions apple/MarkdownFormatter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<NSAttributedStringKey, id> *)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") {
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit b503121

Please sign in to comment.