summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.idea/dictionaries/user.xml3
-rw-r--r--wallet/src/main/java/net/taler/wallet/withdraw/TosSection.kt26
2 files changed, 20 insertions, 9 deletions
diff --git a/.idea/dictionaries/user.xml b/.idea/dictionaries/user.xml
index 4693d75..a29450d 100644
--- a/.idea/dictionaries/user.xml
+++ b/.idea/dictionaries/user.xml
@@ -5,10 +5,11 @@
<w>aiddescription</w>
<w>akono</w>
<w>apdu</w>
+ <w>markwon</w>
<w>servicedesc</w>
<w>snackbar</w>
<w>taler</w>
<w>testkudos</w>
</words>
</dictionary>
-</component>
+</component> \ No newline at end of file
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
+}