mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-19 14:40:18 +00:00
LibWeb: Extend logic for extraneous line breaks in block elements
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
While editing, we need to consider whether removing a <br> has any effect on layout to determine whether its extraneous. This new condition finds most cases for extraneous <br>s inside block elements.
This commit is contained in:
parent
f77f169824
commit
b9da7baac4
Notes:
github-actions[bot]
2025-09-16 10:58:28 +00:00
Author: https://github.com/gmta
Commit: b9da7baac4
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6203
Reviewed-by: https://github.com/trflynn89 ✅
5 changed files with 55 additions and 25 deletions
|
@ -1944,7 +1944,7 @@ bool is_collapsed_line_break(GC::Ref<DOM::Node> node)
|
|||
return false;
|
||||
|
||||
// that begins a line box which has nothing else in it, and therefore has zero height.
|
||||
// NOTE: We check this on the DOM-level by seeing if the next node is neither a non-empty text node nor a <br>.
|
||||
// AD-HOC: We check this on the DOM level by seeing if the next node is neither a non-empty text node nor a <br>.
|
||||
if (auto text_node = as_if<DOM::Text>(node->next_sibling()))
|
||||
return text_node->text_content().value_or({}).is_empty();
|
||||
return !is<HTML::HTMLBRElement>(node->next_sibling());
|
||||
|
@ -2088,8 +2088,18 @@ bool is_extraneous_line_break(GC::Ref<DOM::Node> node)
|
|||
if (is<HTML::HTMLLIElement>(parent.ptr()) && parent->child_count() == 1)
|
||||
return false;
|
||||
|
||||
// FIXME: ...that has no visual effect, in that removing it from the DOM
|
||||
// would not change layout,
|
||||
// ...that has no visual effect, in that removing it from the DOM would not change layout,
|
||||
|
||||
// AD-HOC: If node's parent is a block node, and node either has no next sibling or its next sibling is a block
|
||||
// node, and its previous sibling is a visible inline node but not a <br>, node is extraneous.
|
||||
if (parent && is_block_node(*parent) && node->previous_sibling()
|
||||
&& (!node->next_sibling() || is_block_node(*node->next_sibling()))
|
||||
&& is_visible_node(*node->previous_sibling()) && is_inline_node(*node->previous_sibling())
|
||||
&& !is<HTML::HTMLBRElement>(*node->previous_sibling())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// FIXME: implement more cases that would cause removing a <br> not to have any effect on the layout.
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue