From 46dc592626b4a1c713e65e3217eea95718deb729 Mon Sep 17 00:00:00 2001 From: Jonas Kalderstam Date: Fri, 1 Dec 2023 10:32:32 +0100 Subject: [PATCH] Fixed elements hidden by CSS being displayed --- .../feeder/ui/compose/text/HtmlToComposable.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/main/java/com/nononsenseapps/feeder/ui/compose/text/HtmlToComposable.kt b/app/src/main/java/com/nononsenseapps/feeder/ui/compose/text/HtmlToComposable.kt index 9e53c86f5..5430324a1 100644 --- a/app/src/main/java/com/nononsenseapps/feeder/ui/compose/text/HtmlToComposable.kt +++ b/app/src/main/java/com/nononsenseapps/feeder/ui/compose/text/HtmlToComposable.kt @@ -186,6 +186,11 @@ private fun LazyListScope.formatBody( composer.emitParagraph() } +fun isHiddenByCSS(element: Element): Boolean { + val style = element.attr("style") ?: "" + return style.contains("display:") && style.contains("none") +} + private fun HtmlComposer.appendTextChildren( nodes: List, preFormatted: Boolean = false, @@ -209,6 +214,13 @@ private fun HtmlComposer.appendTextChildren( is Element -> { val element = node + + if (isHiddenByCSS(element)) { + // Element is not supposed to be shown because javascript and/or tracking + node = node.nextSibling() + continue + } + when (element.tagName()) { "p" -> { // Readability4j inserts p-tags in divs for algorithmic purposes.