Hi! I tried styling some inline code, and while it looks somewhat decent, I'm wondering if there's a better way to achieve the same result?
There are two types of inline code in my content/text: one within a paragraph, and another immediately after a "ListaBlock" element. That's why the condition is there.
This is the example content I'm using:
| Content |
Preview |
# apt
> Package manager for Debian-based distributions.
> Intended as a user-friendly alternative to `apt-get` for interactive use.
> More information: <https://manned.org/apt.8>.
- Update the list of available packages and versions:
`sudo apt update`
- Search packages by name or description:
`apt search {{package}}`
- Search packages by name only (supports wildcards like `*`):
`apt list {{package}}`
|
 |
And so I did:
Markwon.builder(ctx).usePlugin(object : AbstractMarkwonPlugin() {
override fun configureVisitor(builder: MarkwonVisitor.Builder) {
super.configureVisitor(builder)
builder.on(Code::class .java) {
visitor, node - >
val length: Int = visitor.length()
val code: Node = node.parent
val previousIsList: Boolean = code.previous is ListBlock
val whiteSpace: String = " ".repeat(node.literal.length)
val padding: String = " "
if (previousIsList) {
visitor.builder().append("$padding$whiteSpace$padding\n$padding")
visitor.builder().append(node.literal)
visitor.builder().append("$padding\n$padding$whiteSpace$padding\n")
} else {
visitor.builder().append(padding)
visitor.builder().append(node.literal)
visitor.builder().append(padding)
}
visitor.setSpansForNodeOptional (node, length)
}
}
})
Another way to make it cleaner?
Thank you in advance for reviewing.
Hi! I tried styling some inline code, and while it looks somewhat decent, I'm wondering if there's a better way to achieve the same result?
There are two types of inline code in my content/text: one within a paragraph, and another immediately after a "ListaBlock" element. That's why the condition is there.
This is the example content I'm using:
And so I did:
Another way to make it cleaner?
Thank you in advance for reviewing.