From e481980480bc5666edd671a06a71078525824bac Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Thu, 25 Nov 2021 19:22:32 +0300 Subject: Check if spoiler was found before setting markdown --- .../infinityforreddit/markdown/SpoilerParserPlugin.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java index 2fd243ac..a83df76a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java @@ -14,6 +14,7 @@ import org.commonmark.node.HtmlInline; import org.commonmark.parser.Parser; import java.util.LinkedHashMap; +import java.util.Map; import java.util.Set; import java.util.Stack; @@ -55,7 +56,7 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin { LinkedHashMap spoilers = parse(markdownStringBuilder); int offset = 2; - for (var entry : spoilers.entrySet()) { + for (Map.Entry entry : spoilers.entrySet()) { int spoilerStart = entry.getKey() - offset; int spoilerEnd = entry.getValue() - offset; @@ -69,7 +70,7 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin { markdownStringBuilder.setSpan(spoilerSpan, spoilerStart, spoilerEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); offset += 4; } - + for (CodeSpan codeSpan : codeSpans) { int spanBeginning = markdownStringBuilder.getSpanStart(codeSpan); int spanEnd = markdownStringBuilder.getSpanEnd(codeSpan); @@ -98,8 +99,9 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin { } } } - - textView.setText(markdownStringBuilder); + if(offset > 2) { + textView.setText(markdownStringBuilder); + } } // Very naive implementation, needs to be improved for efficiency and edge cases -- cgit v1.2.3