Skip to content

Commit

Permalink
Fixed so list items are not immediately given newlines if followed by…
Browse files Browse the repository at this point in the history
… paragraph
  • Loading branch information
spacecowboy committed Nov 14, 2023
1 parent 1882054 commit 07c1810
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ class AnnotatedParagraphStringBuilder {
return false
}

val endsWithNonBreakingSpace: Boolean
get() {
if (mLastTwoChars.isEmpty()) {
return false
}
mLastTwoChars.peekLatest()?.let { latest ->
if (latest.code == 160) {
return true
}
}

return false
}

fun pushVerbatimTtsAnnotation(verbatim: String) =
builder.pushTtsAnnotation(VerbatimTtsAnnotation(verbatim))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class AnnotatedStringComposer : HtmlParser() {
strings

override fun emitParagraph(): Boolean {
if (builder.isEmpty()) {
// List items emit dots and non-breaking space. Don't newline after that
if (builder.isEmpty() || builder.endsWithNonBreakingSpace) {
// Nothing to emit, and nothing to reset
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class EagerComposer(
}

override fun emitParagraph(): Boolean {
if (builder.isEmpty()) {
// List items emit dots and non-breaking space. Don't newline after that
if (builder.isEmpty() || builder.endsWithNonBreakingSpace) {
// Nothing to emit, and nothing to reset
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ private fun HtmlComposer.appendTextChildren(
.forEach { listItem ->
withParagraph {
// no break space
append(" ")
append("\u00A0")
appendTextChildren(
listItem.childNodes(),
baseUrl = baseUrl,
Expand All @@ -595,7 +595,7 @@ private fun HtmlComposer.appendTextChildren(
.forEachIndexed { i, listItem ->
withParagraph {
// no break space
append("${i + 1}. ")
append("${i + 1}.\u00A0")
appendTextChildren(
listItem.childNodes(),
baseUrl = baseUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class LazyListComposer(
) : HtmlComposer() {

override fun emitParagraph(): Boolean {
if (builder.isEmpty()) {
// List items emit dots and non-breaking space. Don't newline after that
if (builder.isEmpty() || builder.endsWithNonBreakingSpace) {
// Nothing to emit, and nothing to reset
return false
}
Expand Down

0 comments on commit 07c1810

Please sign in to comment.