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 4976b59 commit 11b0396
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions apple/MarkdownFormatter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ - (nonnull NSAttributedString *)format:(nonnull NSString *)text
type:std::string([markdownRange.type UTF8String])
range:markdownRange.range
depth:markdownRange.depth
markdownStyle:markdownStyle];
markdownStyle:markdownStyle
defaultTextAttributes:defaultTextAttributes];
}

RCTApplyBaselineOffset(attributedString);
Expand All @@ -38,7 +39,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 @@ -99,7 +102,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
8 changes: 4 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ PODS:
- React-logger (= 0.75.3)
- React-perflogger (= 0.75.3)
- React-utils (= 0.75.3)
- RNLiveMarkdown (0.1.205):
- RNLiveMarkdown (0.1.208):
- DoubleConversion
- glog
- hermes-engine
Expand All @@ -1517,10 +1517,10 @@ PODS:
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- RNLiveMarkdown/newarch (= 0.1.205)
- RNLiveMarkdown/newarch (= 0.1.208)
- RNReanimated/worklets
- Yoga
- RNLiveMarkdown/newarch (0.1.205):
- RNLiveMarkdown/newarch (0.1.208):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1897,7 +1897,7 @@ SPEC CHECKSUMS:
React-utils: f2afa6acd905ca2ce7bb8ffb4a22f7f8a12534e8
ReactCodegen: e35c23cdd36922f6d2990c6c1f1b022ade7ad74d
ReactCommon: 289214026502e6a93484f4a46bcc0efa4f3f2864
RNLiveMarkdown: bf0f16b1e8c3320d600a5931d270e19afef9fa92
RNLiveMarkdown: e8b7f5cf8a0e8027850a781ffc86119e21fb406a
RNReanimated: 75df06d3a81fc147b83056ae469512f573365b1d
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
Yoga: 1354c027ab07c7736f99a3bef16172d6f1b12b47
Expand Down

0 comments on commit 11b0396

Please sign in to comment.