diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/blog/HtmlText.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/blog/HtmlText.kt index 47e1cff14ad13f7973b79db0314bd442fd4504ae..4bb077b1b03e151e942b27741b69033aced76037 100644 --- a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/blog/HtmlText.kt +++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/blog/HtmlText.kt @@ -317,7 +317,8 @@ fun HtmlText( val listType = listNesting.top() listNumbering.incrementCurrent() if (listType == UNORDERED) { - appendAndUpdateCursor(listBullets[listNesting.size]) + val bulletType = listNesting.size - 1 + appendAndUpdateCursor(listBullets[bulletType % listBullets.size]) appendAndUpdateCursor(" ") pushStringAnnotation("bullet", listNesting.size.toString()) } else if (listType == ORDERED) { diff --git a/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/blog/TestHtml.kt b/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/blog/TestHtml.kt new file mode 100644 index 0000000000000000000000000000000000000000..aa77f37578086d0f9a15c0bbb746d6ff14bc64d2 --- /dev/null +++ b/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/blog/TestHtml.kt @@ -0,0 +1,54 @@ +/* + * Briar Desktop + * Copyright (C) 2023 The Briar Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package org.briarproject.briar.desktop.blog + +import androidx.compose.foundation.VerticalScrollbar +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.rememberScrollbarAdapter +import androidx.compose.foundation.text.selection.SelectionContainer +import androidx.compose.foundation.verticalScroll +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import org.briarproject.briar.desktop.utils.PreviewUtils.preview + +fun testHtml(testHtml: String) = preview { + Box( + contentAlignment = Alignment.Center, + modifier = Modifier.fillMaxSize(), + ) { + val scrollState = rememberScrollState() + VerticalScrollbar( + adapter = rememberScrollbarAdapter(scrollState), + modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(), + ) + SelectionContainer( + modifier = Modifier.fillMaxWidth().verticalScroll(scrollState).padding(16.dp), + ) { + HtmlText(testHtml) { + println(it) + } + } + } +} diff --git a/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/blog/TestOrderedLists.kt b/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/blog/TestOrderedLists.kt new file mode 100644 index 0000000000000000000000000000000000000000..cf6e99739b803308e8f17ba42a98b9f52d7ce81d --- /dev/null +++ b/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/blog/TestOrderedLists.kt @@ -0,0 +1,56 @@ +/* + * Briar Desktop + * Copyright (C) 2023 The Briar Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package org.briarproject.briar.desktop.blog + +import org.intellij.lang.annotations.Language +import org.jetbrains.annotations.NonNls + +fun main() = testHtml(testHtml) + +@NonNls +@Language("HTML") +private val testHtml = """ + <h1>Ordered lists</h1> + <ol> + <li>foo + <li>direct children + <ol> + <li>child1 + <li>child2 + </ol> + </li> + <ol> + <li>bar1</li> + <li>bar2</li> + </ol> + <li> more direct children + <ol> + <li>foo + <li>bar + <ol> + <li>child1 + <li>child2 + </ol> + </li> + <li>cat + </ol> + </li> + <li>baz + </ol> +""".trimIndent() diff --git a/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/blog/TestUnorderedLists.kt b/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/blog/TestUnorderedLists.kt new file mode 100644 index 0000000000000000000000000000000000000000..37c6f32246637d6e6c6c4b93235b7002f06cd5c0 --- /dev/null +++ b/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/blog/TestUnorderedLists.kt @@ -0,0 +1,59 @@ +/* + * Briar Desktop + * Copyright (C) 2023 The Briar Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package org.briarproject.briar.desktop.blog + +import org.intellij.lang.annotations.Language +import org.jetbrains.annotations.NonNls + +fun main() = testHtml(testHtml) + +@NonNls +@Language("HTML") +private val testHtml = """ + <h1>Unordered lists</h1> + <ul> + <li>foo + <li>direct children + <ul> + <li>child1 + <li>child2 + </ul> + </li> + <ul> + <li>bar1</li> + <li>bar2</li> + </ul> + <li> more direct children + <ul> + <li>foo + <li>bar + <ul> + <li>child1 + <li>child2 + <ul> + <li>4th level</li> + <li>same bullet as first level</li> + </ul> + </ul> + </li> + </ul> + </li> + <li>first level again + </ul> +""".trimIndent()