summaryrefslogtreecommitdiff
path: root/wallet/src/main/java/net
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-04-30 15:48:01 -0300
committerTorsten Grote <t@grobox.de>2020-04-30 15:48:01 -0300
commit724f9fa491638ae7fcfed07eefa376bacd34d29f (patch)
tree0a03679b98a555524fb580822553cc182103affe /wallet/src/main/java/net
parentd118436966331f23acb872d9c13e1ab6403072c0 (diff)
downloadtaler-android-724f9fa491638ae7fcfed07eefa376bacd34d29f.tar.gz
taler-android-724f9fa491638ae7fcfed07eefa376bacd34d29f.tar.bz2
taler-android-724f9fa491638ae7fcfed07eefa376bacd34d29f.zip
[wallet] accept but strip markup in ToS markdown headings
Diffstat (limited to 'wallet/src/main/java/net')
-rw-r--r--wallet/src/main/java/net/taler/wallet/withdraw/TosSection.kt26
1 files changed, 18 insertions, 8 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/TosSection.kt b/wallet/src/main/java/net/taler/wallet/withdraw/TosSection.kt
index 72a9e34..b27de42 100644
--- a/wallet/src/main/java/net/taler/wallet/withdraw/TosSection.kt
+++ b/wallet/src/main/java/net/taler/wallet/withdraw/TosSection.kt
@@ -17,6 +17,7 @@
package net.taler.wallet.withdraw
import io.noties.markwon.Markwon
+import org.commonmark.node.Code
import org.commonmark.node.Document
import org.commonmark.node.Heading
import org.commonmark.node.Node
@@ -44,14 +45,9 @@ internal fun parseTos(markwon: Markwon, text: String): List<TosSection> {
sections.add(TosSection(lastHeading, section))
section = Document()
}
- // check that this is a plain heading
- if (node.firstChild !is Text || node.firstChild.next != null) {
- throw ParseException(
- "Primary heading includes more than just text", sections.size
- )
- }
- // start new section
- lastHeading = (node.firstChild as Text).literal
+ // start new section with new heading (stripped of markup)
+ lastHeading = getNodeText(node)
+ if (lastHeading.isBlank()) throw ParseException("Empty heading", 0)
} else if (lastHeading == null) {
throw ParseException("Found text before first primary heading", 0)
} else {
@@ -63,3 +59,17 @@ internal fun parseTos(markwon: Markwon, text: String): List<TosSection> {
sections.add(TosSection(lastHeading, section))
return sections
}
+
+private fun getNodeText(rootNode: Node): String {
+ var node: Node? = rootNode.firstChild
+ var text = ""
+ while (node != null) {
+ text += when (node) {
+ is Text -> node.literal
+ is Code -> node.literal
+ else -> getNodeText(node)
+ }
+ node = node.next
+ }
+ return text
+}