Skip to content

fix(ios): preserve code block styles inside list items#174

Merged
hryhoriiK97 merged 2 commits intosoftware-mansion-labs:mainfrom
Mile-Away:fix/ios-list-item-codeblock-style
Mar 28, 2026
Merged

fix(ios): preserve code block styles inside list items#174
hryhoriiK97 merged 2 commits intosoftware-mansion-labs:mainfrom
Mile-Away:fix/ios-list-item-codeblock-style

Conversation

@Mile-Away
Copy link
Copy Markdown
Contributor

Summary

When a fenced code block appears inside a list item (e.g. ```text inside an ordered list), ListItemRenderer's paragraph style enumeration overwrites the code block's own styles with list item styles. This causes:

  • List markers (e.g. "2.") appearing on every line inside the code block
  • Code block padding and LTR indentation being replaced by list indentation

Root cause: ListItemRenderer.m enumerates ListDepthAttribute over the entire item range and applies list paragraph styles to all segments that don't belong to a nested sub-list. Code block ranges (which have CodeBlockAttributeName set by CodeBlockRenderer) were not excluded.

Fix: Check for CodeBlockAttributeName in the enumeration callback and skip those ranges, preserving the paragraph style already applied by CodeBlockRenderer.

Reproduction

1. First item
2. Second item:

\`\`\`text
Line A
Line B
Line C
\`\`\`

3. Third item

Before this fix, lines inside the code block render with "2." list markers on iOS.

Test plan

  • Verify fenced code blocks inside ordered/unordered list items render without list markers
  • Verify code block background, padding, and LTR alignment are preserved
  • Verify nested lists still render correctly (no regression)
  • Verify task list items with code blocks render correctly

🤖 Generated with Claude Code

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>
Copy link
Copy Markdown
Collaborator

@hryhoriiK97 hryhoriiK97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mile-Away thank you for the PR with fix! One thing which should be covered - he same pattern exists in applyCheckedDecorationsTo:range:nestingLevel.

Please add the same guard there as well:

  [output enumerateAttribute:ListDepthAttribute
                     inRange:range
                     options:0
                  usingBlock:^(NSNumber *depth, NSRange segmentRange, BOOL *stop) {
                    BOOL isNestedSubItem = (depth && [depth integerValue] > nestingLevel);
                    if (isNestedSubItem) {
                      return;
                    }

                    NSNumber *isCodeBlock = [output attribute:CodeBlockAttributeName
                                                     atIndex:segmentRange.location
                                              effectiveRange:nil];
                    if ([isCodeBlock boolValue]) {
                      return;
                    }

                    [output addAttributes:checkedAttrs range:segmentRange];
                  }];

Comment thread ios/renderer/ListItemRenderer.m
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>
@hryhoriiK97 hryhoriiK97 merged commit 9820818 into software-mansion-labs:main Mar 28, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants