Skip to content

fix(android): keep a code block's box inside a list item - #1065

Open
jnowakow wants to merge 1 commit into
mainfrom
fix/android-list-item-code-block
Open

jnowakow wants to merge 1 commit into
mainfrom
fix/android-list-item-code-block

Conversation

@jnowakow

@jnowakow jnowakow commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

What/Why?

Port of the code block part of the React Native fix for list items with block children (#478). Before, a code block inside a list item drew its box from the left edge, under the item's marker, and a code block that ended an item lost its bottom padding and rounded corners.

Testing

Before After

PR Checklist

  • Code compiles and runs on iOS
  • Code compiles and runs on Android
  • Updated documentation/README if applicable
  • Ran example app to verify changes
  • E2E tests are passing
  • Required E2E tests have been added (if applicable)

Port of the code block part of the React Native fix for list items with block
children (#478):

- The list item no longer trims the newlines its children leave, so a code
  block that ends an item keeps its bottom padding and rounded corners.
- The item's list spans are split around its code blocks, and the code block
  draws its box from the item's text column (CodeBlockSpan.leadingIndent)
  instead of the left edge. Only the first segment draws the marker.
- Task toggling flips every segment of a split item, and HTML and
  accessibility output stay consistent with the split spans.
- Copy-as-markdown nests a code block under its item (CodeBlockSpan.listItem):
  the fences and code lines are indented to the item's text column, an item
  that opens with a code block puts its marker on the opening fence, and text
  after the block continues the item instead of starting a new one.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved marker-rendering, right-to-left background, and HTML block-boundary regressions affect correctness.

3 open issues
What changed in this PR

Ports the code-block portion of #478 to standalone Android, aiming to keep code-block backgrounds inside list items and preserve bottom padding and rounded corners.

Changes:

  • Tracks list indentation and splits list styling around code blocks.
  • Updates task interaction, exports, and accessibility for split list items.
  • Adds rendering, export, and task-toggle regression tests.

Paths below are relative to packages/enriched-markdown-android/ui/src/.

File Description
test/​java/​com/​swmansion/​enriched/​markdown/​test/​MarkdownRenderTestSupport.kt Adds combined list and code-block style helpers.
test/​java/​com/​swmansion/​enriched/​markdown/​test/​ListMarkerCanvas.kt Filters non-marker rectangles from recordings.
test/​java/​com/​swmansion/​enriched/​markdown/​TaskListInteractionTest.kt Tests task toggling around code blocks.
test/​java/​com/​swmansion/​enriched/​markdown/​ListChildrenRenderingTest.kt Tests list-child geometry and decorations.
test/​java/​com/​swmansion/​enriched/​markdown/​ListChildrenExportTest.kt Tests Markdown, HTML, and accessibility output.
main/​java/​com/​swmansion/​enriched/​markdown/​utils/​text/​interaction/​TaskListTapUtils.kt Updates all segments of a task item.
main/​java/​com/​swmansion/​enriched/​markdown/​utils/​text/​conversion/​MarkdownExtractor.kt Preserves list indentation around code fences.
main/​java/​com/​swmansion/​enriched/​markdown/​utils/​text/​conversion/​HTMLGenerator.kt Skips empty bottom-margin paragraphs.
main/​java/​com/​swmansion/​enriched/​markdown/​spans/​UnorderedListSpan.kt Supports marker-free continuation spans.
main/​java/​com/​swmansion/​enriched/​markdown/​spans/​TaskListSpan.kt Supports checkbox-free continuation spans.
main/​java/​com/​swmansion/​enriched/​markdown/​spans/​OrderedListSpan.kt Supports number-free continuation spans.
main/​java/​com/​swmansion/​enriched/​markdown/​spans/​CodeBlockSpan.kt Adds list indentation and item metadata.
main/​java/​com/​swmansion/​enriched/​markdown/​spans/​BaseListSpan.kt Controls marker ownership.
main/​java/​com/​swmansion/​enriched/​markdown/​renderer/​ListItemRenderer.kt Splits list spans around code blocks.
main/​java/​com/​swmansion/​enriched/​markdown/​renderer/​HeadingRenderer.kt Ensures headings start on a new line.
main/​java/​com/​swmansion/​enriched/​markdown/​renderer/​CodeBlockRenderer.kt Applies accumulated indentation to code blocks.
main/​java/​com/​swmansion/​enriched/​markdown/​renderer/​BlockStyleContext.kt Tracks accumulated list indentation.
main/​java/​com/​swmansion/​enriched/​markdown/​renderer/​BlockquoteRenderer.kt Ensures quotes start on a new line.
main/​java/​com/​swmansion/​enriched/​markdown/​accessibility/​MarkdownAccessibilityHelper.kt Avoids announcing continuation segments as new items.

Review effort: Balanced

Comment on lines +141 to +144
if (segmentStart < itemEnd) {
builder.setSpan(
if (isFirstSegment) markerSpan else makeSpan(drawsMarker = false),
segmentStart,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed by #1066


rect.set(
left.toFloat() + inset,
left.toFloat() + leadingIndent + inset,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It will be handled in the follow-up

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

}

// A block's bottom-margin line inside a list item or a quote holds no content of its own.
if (paraText.isEmpty() && text.getSpans(para.start, para.start + 1, MarginBottomSpan::class.java).isNotEmpty()) return

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It will be handled in follow-up PR

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This branch has not been deployed

No deployments
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