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 accentNext = false
|
||||||
var currentIndent = 0
|
var currentIndent = 0
|
||||||
var mClosedPendingBreak = false
|
var mClosedPendingBreak = false
|
||||||
|
var lastAppended: Char? = null
|
||||||
val exampleStyle = SpanStyle(color = colorScheme.secondaryText)
|
val exampleStyle = SpanStyle(color = colorScheme.secondaryText)
|
||||||
val labelStyle = SpanStyle(color = colorScheme.labelText)
|
val labelStyle = SpanStyle(color = colorScheme.labelText)
|
||||||
val linkStyle = SpanStyle(color = colorScheme.linkText, textDecoration = TextDecoration.Underline)
|
val linkStyle = SpanStyle(color = colorScheme.linkText, textDecoration = TextDecoration.Underline)
|
||||||
@@ -108,20 +109,23 @@ object DslAnnotatedParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun flushBlock() {
|
fun flushBlock() {
|
||||||
if (builder.length > 0) {
|
val text = builder.toAnnotatedString()
|
||||||
|
if (text.any { !it.isWhitespace() }) {
|
||||||
result.add(DslBlock(
|
result.add(DslBlock(
|
||||||
text = builder.toAnnotatedString(),
|
text = text,
|
||||||
indent = currentIndent,
|
indent = currentIndent,
|
||||||
lazyRefs = lazyRefs.toList()
|
lazyRefs = lazyRefs.toList()
|
||||||
))
|
))
|
||||||
|
}
|
||||||
builder = AnnotatedString.Builder()
|
builder = AnnotatedString.Builder()
|
||||||
stack.forEach { builder.pushStyle(it) }
|
stack.forEach { builder.pushStyle(it) }
|
||||||
lazyRefs.clear()
|
lazyRefs.clear()
|
||||||
}
|
lastAppended = null
|
||||||
mClosedPendingBreak = false
|
mClosedPendingBreak = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun appendChar(char: Char) {
|
fun appendChar(char: Char) {
|
||||||
|
lastAppended = char
|
||||||
if (mClosedPendingBreak) {
|
if (mClosedPendingBreak) {
|
||||||
mClosedPendingBreak = false
|
mClosedPendingBreak = false
|
||||||
if (refStack.isEmpty() && !char.isWhitespace()) {
|
if (refStack.isEmpty() && !char.isWhitespace()) {
|
||||||
@@ -209,8 +213,8 @@ object DslAnnotatedParser {
|
|||||||
}
|
}
|
||||||
"b" -> push(SpanStyle(fontWeight = FontWeight.Bold))
|
"b" -> push(SpanStyle(fontWeight = FontWeight.Bold))
|
||||||
"m", "m0", "m1", "m2", "m3", "m4", "m5" -> {
|
"m", "m0", "m1", "m2", "m3", "m4", "m5" -> {
|
||||||
if (builder.length > 0) {
|
if (lastAppended != null && !lastAppended!!.isWhitespace()) {
|
||||||
if (refStack.isEmpty()) flushBlock() else builder.append("\n")
|
flushBlock()
|
||||||
}
|
}
|
||||||
currentIndent = marginIndent(tagName)
|
currentIndent = marginIndent(tagName)
|
||||||
push(exampleStyle)
|
push(exampleStyle)
|
||||||
@@ -243,6 +247,14 @@ object DslAnnotatedParser {
|
|||||||
appendChar(char)
|
appendChar(char)
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
'\n' -> {
|
||||||
|
if (refStack.isEmpty()) {
|
||||||
|
flushBlock()
|
||||||
|
} else {
|
||||||
|
appendChar(char)
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
}
|
||||||
else -> {
|
else -> {
|
||||||
appendChar(char)
|
appendChar(char)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user