Repository navigation
fix(android): keep a code block's box inside a list item #1065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,9 +22,13 @@ class CodeBlockSpan( | |
| private val codeBlockStyle: CodeBlockStyle, | ||
| private val context: Context, | ||
| private val styleCache: SpanStyleCache, | ||
| private val leadingIndent: Int = 0, | ||
| ) : MetricAffectingSpan(), | ||
| LineBackgroundSpan, | ||
| LeadingMarginSpan { | ||
| /** The innermost list item holding this block, whose marker span this is; copy-as-markdown nests the block under it. */ | ||
| internal var listItem: BaseListSpan? = null | ||
|
|
||
| private val blockStyle = | ||
| BlockStyle( | ||
| fontSize = codeBlockStyle.fontSize, | ||
|
|
@@ -59,7 +63,7 @@ class CodeBlockSpan( | |
| color = codeBlockStyle.borderColor | ||
| } | ||
|
|
||
| override fun getLeadingMargin(first: Boolean): Int = codeBlockStyle.padding.toInt() | ||
| override fun getLeadingMargin(first: Boolean): Int = codeBlockStyle.padding.toInt() + leadingIndent | ||
|
|
||
| override fun drawLeadingMargin( | ||
| c: Canvas?, | ||
|
|
@@ -105,11 +109,12 @@ class CodeBlockSpan( | |
| val inset = codeBlockStyle.borderWidth / 2f | ||
|
|
||
| rect.set( | ||
| left.toFloat() + inset, | ||
| left.toFloat() + leadingIndent + inset, | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will be handled in the follow-up
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| top.toFloat() + (if (isFirstLine) inset else 0f), | ||
| right.toFloat() - inset, | ||
| bottom.toFloat() - (if (isLastLine) inset else 0f), | ||
| ) | ||
| if (rect.left >= rect.right) return | ||
|
|
||
| val radius = codeBlockStyle.borderRadius | ||
| val adjRadius = if (radius > inset) radius - inset else radius | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import com.swmansion.enriched.markdown.spans.HeadingSpan | |
| import com.swmansion.enriched.markdown.spans.HighlightSpan | ||
| import com.swmansion.enriched.markdown.spans.ImageSpan | ||
| import com.swmansion.enriched.markdown.spans.LinkSpan | ||
| import com.swmansion.enriched.markdown.spans.MarginBottomSpan | ||
| import com.swmansion.enriched.markdown.spans.OrderedListSpan | ||
| import com.swmansion.enriched.markdown.spans.StrongSpan | ||
| import com.swmansion.enriched.markdown.spans.TaskListSpan | ||
|
|
@@ -334,6 +335,9 @@ object HTMLGenerator { | |
| return | ||
| } | ||
|
|
||
| // 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 | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will be handled in follow-up PR
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| // Get content range (trim trailing newline) | ||
| val contentEnd = if (para.end > para.start && text[para.end - 1] == '\n') para.end - 1 else para.end | ||
| val isCodeBlock = para.type == TYPE_CODE_BLOCK | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by #1066