Skip to content

Commit

Permalink
Fixed elements hidden by CSS being displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Dec 1, 2023
1 parent 12bd7cc commit 46dc592
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Node>,
preFormatted: Boolean = false,
Expand All @@ -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.
Expand Down

0 comments on commit 46dc592

Please sign in to comment.