Skip to content

Commit 9820818

Browse files
Mile-Awayclaude
andauthored
fix(ios): preserve code block styles inside list items (#174)
* fix(ios): preserve code block styles inside list items When a fenced code block appears inside a list item, ListItemRenderer's paragraph style enumeration was overwriting the code block's own styles (padding, LTR indent) with list item styles. This caused code block content to display list markers (e.g. "2.") on every line. Skip ranges that have the CodeBlockAttributeName attribute, since CodeBlockRenderer has already applied the correct paragraph style. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(ios): also guard code blocks in checked task list decorations Add the same CodeBlockAttributeName check to applyCheckedDecorationsTo so that checked task list strikethrough/color styles don't bleed into code block ranges inside list items. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 118f5e2 commit 9820818

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

ios/renderer/ListItemRenderer.m

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#import "ListItemRenderer.h"
22
#import "ENRMUIKit.h"
3+
#import "LastElementUtils.h"
34
#import "MarkdownASTNode.h"
45
#import "ParagraphStyleUtils.h"
56
#import "RenderContext.h"
@@ -95,7 +96,7 @@ - (void)renderNode:(MarkdownASTNode *)node into:(NSMutableAttributedString *)out
9596
}
9697

9798
// We enumerate to ensure we don't overwrite styles of nested sub-lists
98-
// that may have already been rendered inside this item.
99+
// or code blocks that may have already been rendered inside this item.
99100
[output enumerateAttribute:ListDepthAttribute
100101
inRange:itemRange
101102
options:0
@@ -106,6 +107,16 @@ - (void)renderNode:(MarkdownASTNode *)node into:(NSMutableAttributedString *)out
106107
return;
107108
}
108109

110+
// Skip code block ranges — CodeBlockRenderer already applied its own
111+
// paragraph style (padding, LTR indent). Overwriting would add list
112+
// markers ("2.") inside the code block.
113+
NSNumber *isCodeBlock = [output attribute:CodeBlockAttributeName
114+
atIndex:range.location
115+
effectiveRange:nil];
116+
if ([isCodeBlock boolValue]) {
117+
return;
118+
}
119+
109120
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
110121
style.baseWritingDirection = currentWritingDirection();
111122
style.firstLineHeadIndent = totalIndent;
@@ -158,10 +169,19 @@ - (void)applyCheckedDecorationsTo:(NSMutableAttributedString *)output
158169
options:0
159170
usingBlock:^(NSNumber *depth, NSRange segmentRange, BOOL *stop) {
160171
BOOL isNestedSubItem = (depth && [depth integerValue] > nestingLevel);
172+
if (isNestedSubItem) {
173+
return;
174+
}
161175

162-
if (!isNestedSubItem) {
163-
[output addAttributes:checkedAttrs range:segmentRange];
176+
// Skip code block ranges — preserve CodeBlockRenderer styles.
177+
NSNumber *isCodeBlock = [output attribute:CodeBlockAttributeName
178+
atIndex:segmentRange.location
179+
effectiveRange:nil];
180+
if ([isCodeBlock boolValue]) {
181+
return;
164182
}
183+
184+
[output addAttributes:checkedAttrs range:segmentRange];
165185
}];
166186
}
167187

0 commit comments

Comments
 (0)