fix(dsl): render each margin on its own line
Each [m] block occupies its own line in the article. Blank paragraphs and whitespace-only lines are dropped.
This commit is contained in:
1 parent
f5880d72ad
commit
c0c9211b82
1 file changed
+17
-5
@@ -91,6 +91,7 @@ object DslAnnotatedParser {
|
||||
var accentNext = false
|
||||
var currentIndent = 0
|
||||
var mClosedPendingBreak = false
|
||||
var lastAppended: Char? = null
|
||||
val exampleStyle = SpanStyle(color = colorScheme.secondaryText)
|
||||
val labelStyle = SpanStyle(color = colorScheme.labelText)
|
||||
val linkStyle = SpanStyle(color = colorScheme.linkText, textDecoration = TextDecoration.Underline)
|
||||
@@ -108,20 +109,23 @@ object DslAnnotatedParser {
|
||||
}
|
||||
|
||||
fun flushBlock() {
|
||||
if (builder.length > 0) {
|
||||
val text = builder.toAnnotatedString()
|
||||
if (text.any { !it.isWhitespace() }) {
|
||||
result.add(DslBlock(
|
||||
text = builder.toAnnotatedString(),
|
||||
text = text,
|
||||
indent = currentIndent,
|
||||
lazyRefs = lazyRefs.toList()
|
||||
))
|
||||
}
|
||||
builder = AnnotatedString.Builder()
|
||||
stack.forEach { builder.pushStyle(it) }
|
||||
lazyRefs.clear()
|
||||
}
|
||||
lastAppended = null
|
||||
mClosedPendingBreak = false
|
||||
}
|
||||
|
||||
fun appendChar(char: Char) {
|
||||
lastAppended = char
|
||||
if (mClosedPendingBreak) {
|
||||
mClosedPendingBreak = false
|
||||
if (refStack.isEmpty() && !char.isWhitespace()) {
|
||||
@@ -209,8 +213,8 @@ object DslAnnotatedParser {
|
||||
}
|
||||
"b" -> push(SpanStyle(fontWeight = FontWeight.Bold))
|
||||
"m", "m0", "m1", "m2", "m3", "m4", "m5" -> {
|
||||
if (builder.length > 0) {
|
||||
if (refStack.isEmpty()) flushBlock() else builder.append("\n")
|
||||
if (lastAppended != null && !lastAppended!!.isWhitespace()) {
|
||||
flushBlock()
|
||||
}
|
||||
currentIndent = marginIndent(tagName)
|
||||
push(exampleStyle)
|
||||
@@ -243,6 +247,14 @@ object DslAnnotatedParser {
|
||||
appendChar(char)
|
||||
i++
|
||||
}
|
||||
'\n' -> {
|
||||
if (refStack.isEmpty()) {
|
||||
flushBlock()
|
||||
} else {
|
||||
appendChar(char)
|
||||
}
|
||||
i++
|
||||
}
|
||||
else -> {
|
||||
appendChar(char)
|
||||
|
||||
|
||||
Reference in new issue
Block a user