From d87381d003d0955cdfa356f3e5c219120b0a21fc Mon Sep 17 00:00:00 2001 From: ialokim <ialokim@mailbox.org> Date: Thu, 31 Aug 2023 01:01:42 +0200 Subject: [PATCH] use pushStringAnnotation and pop for links instead of manual calculation --- .../briar/desktop/blog/HtmlText.kt | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) 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 3fb7b448e6..6ecc6d3072 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 @@ -195,21 +195,18 @@ fun HtmlText( if (!withinPre) pop() } - // todo: this should be changed to start/endLink for consistent length - fun addLink(node: Element) { - val start = cursorPosition - val end = start + node.text().length + fun startLink(node: Element) { val href = node.attr("href") - addStringAnnotation( - tag = "link", - start = start, - end = end, - annotation = href - ) + pushStringAnnotation("link", href) pushStyle(link) } + fun endLink() { + pop() + pop() + } + fun startBlockQuote() { pushIndent(20.sp) pushStringAnnotation("quote", "") @@ -311,7 +308,7 @@ fun HtmlText( "small" -> pushStyle(small) "code" -> startCode() "q" -> startInlineQuote() - "a" -> addLink(node) + "a" -> startLink(node) // lists "ul" -> startUnorderedList() @@ -342,12 +339,11 @@ fun HtmlText( } "b", "strong", "i", "em", "cite", "u", "strike", "sub", "sup", "small", - "a", -> pop() "code" -> endCode() - "q" -> endInlineQuote() + "a" -> endLink() "ul" -> endUnorderedList() "ol" -> endOrderedList() -- GitLab