Skip to content

Commit

Permalink
Fixing bullet point issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Agustin Larghi committed Jan 15, 2025
1 parent 65731a3 commit 56a865c
Show file tree
Hide file tree
Showing 6 changed files with 264 additions and 335 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.text.Spanned
import android.widget.TextView
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.text.TextStyle
import coil.ImageLoader
import coil.decode.GifDecoder
import coil.decode.ImageDecoderDecoder
Expand Down Expand Up @@ -37,6 +38,7 @@ internal object MarkdownRender {
beforeSetMarkdown: ((TextView, Spanned) -> Unit)? = null,
afterSetMarkdown: ((TextView) -> Unit)? = null,
onLinkClicked: ((String) -> Unit)? = null,
style: TextStyle
): Markwon {
val coilImageLoader = imageLoader ?: ImageLoader.Builder(context)
.components {
Expand Down Expand Up @@ -84,6 +86,7 @@ internal object MarkdownRender {
} else {
builder.headingBreakColor(headingBreakColor.toArgb())
}
builder.bulletWidth(style.fontSize.value.toInt())
}

override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ fun MarkdownText(
beforeSetMarkdown,
afterSetMarkdown,
onLinkClicked,
style
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,25 +267,26 @@ class MardownCorePlugin(
ListItem::class.java
) { visitor, listItem ->
val length = visitor.length()
// it's important to visit children before applying render props (
// we can have nested children, who are list items also, thus they will
// override out props (if we set them before visiting children)
visitor.visitChildren(listItem)

val parent: Node = listItem.parent
if (parent is OrderedList) {
val start = parent.startNumber

CoreProps.LIST_ITEM_TYPE[visitor.renderProps()] = CoreProps.ListItemType.ORDERED
CoreProps.ORDERED_LIST_ITEM_NUMBER[visitor.renderProps()] = start
parent.startNumber += 1

// after we have visited the children increment start number
val orderedList = parent
orderedList.startNumber += 1
} else {
CoreProps.LIST_ITEM_TYPE[visitor.renderProps()] = CoreProps.ListItemType.BULLET
CoreProps.BULLET_LIST_ITEM_LEVEL[visitor.renderProps()] = listLevel(listItem)
}

// Apply font size to bullet points
val bulletSpan = AbsoluteSizeSpan(fontSize.spValue, true)
val span = visitor.factory.spansForProps(visitor.renderProps(), length)
span.add(bulletSpan)
visitor.builder().setSpan(bulletSpan, length, length + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)


visitor.setSpansForNodeOptional(listItem, length)
if (visitor.hasNext(listItem)) {
visitor.ensureNewLine()
Expand Down
Loading

0 comments on commit 56a865c

Please sign in to comment.