diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java b/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java index fdd9769832..96de9fb34b 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java @@ -3,6 +3,7 @@ import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextUtils; +import android.text.style.BulletSpan; import android.widget.TextView; import com.twitter.twittertext.Regex; @@ -15,11 +16,11 @@ import org.jsoup.nodes.Element; import org.jsoup.nodes.Node; import org.jsoup.nodes.TextNode; -import org.jsoup.safety.Cleaner; import org.jsoup.safety.Safelist; import org.jsoup.select.NodeVisitor; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.function.Function; @@ -29,6 +30,8 @@ import androidx.annotation.NonNull; +import me.grishka.appkit.utils.V; + public class HtmlParser{ private static final String TAG="HtmlParser"; private static final String VALID_URL_PATTERN_STRING = @@ -119,24 +122,30 @@ public void head(@NonNull Node node, int depth){ openSpans.add(new SpanInfo(new InvisibleSpan(), ssb.length(), el)); } } + case "li" -> openSpans.add(new SpanInfo(new BulletSpan(V.dp(6)), ssb.length(), el)); } } } + final static List blockElements = Arrays.asList("p", "ul", "ol", "blockquote", "h1", "h2", "h3", "h4", "h5", "h6"); + @Override public void tail(@NonNull Node node, int depth){ if(node instanceof Element el){ if("span".equals(el.nodeName()) && el.hasClass("ellipsis")){ ssb.append("…", new DeleteWhenCopiedSpan(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - }else if("p".equals(el.nodeName())){ - if(node.nextSibling()!=null) - ssb.append("\n\n"); - }else if(!openSpans.isEmpty()){ + }else if(blockElements.contains(el.nodeName()) && node.nextSibling()!=null){ + ssb.append("\n\n"); + } + if(!openSpans.isEmpty()){ SpanInfo si=openSpans.get(openSpans.size()-1); if(si.element==el){ ssb.setSpan(si.span, si.start, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); openSpans.remove(openSpans.size()-1); } + if("li".equals(el.nodeName()) && node.nextSibling()!=null) { + ssb.append('\n'); + } } } }