mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 08:11:13 +00:00
LibWebView: Properly handle new lines inside styled view-source elements
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-14, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-22.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-22.04, Linux, 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
Push notes / build (push) Waiting to run
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-14, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-22.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-22.04, Linux, 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
Push notes / build (push) Waiting to run
When we want to inject a CSS counter for a line, we need to be sure to handle if we had previously opened a styled span for the current source substring. For example, if we see a new line in the middle of a comment, we will have previously opened the following tag: <span class="comment"> So when injecting a new line and the <span class="line"> element (for CSS counters), we need to close the previous span and insert a newly opened tag to continue using the style.
This commit is contained in:
parent
79b57ef094
commit
f1395a2c38
Notes:
github-actions[bot]
2024-09-04 14:00:51 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/f1395a2c385 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1270
|
@ -79,27 +79,36 @@ String highlight_source(URL::URL const& url, StringView source)
|
|||
|
||||
auto segment = source.substring_view(previous_position, end_position - previous_position);
|
||||
|
||||
if (class_name.has_value())
|
||||
builder.appendff("<span class=\"{}\">"sv, *class_name);
|
||||
auto append_class_start = [&]() {
|
||||
if (class_name.has_value())
|
||||
builder.appendff("<span class=\"{}\">"sv, *class_name);
|
||||
};
|
||||
auto append_class_end = [&]() {
|
||||
if (class_name.has_value())
|
||||
builder.append("</span>"sv);
|
||||
};
|
||||
|
||||
append_class_start();
|
||||
|
||||
for (auto code_point : Utf8View { segment }) {
|
||||
if (code_point == '&')
|
||||
if (code_point == '&') {
|
||||
builder.append("&"sv);
|
||||
else if (code_point == 0xA0)
|
||||
} else if (code_point == 0xA0) {
|
||||
builder.append(" "sv);
|
||||
else if (code_point == '<')
|
||||
} else if (code_point == '<') {
|
||||
builder.append("<"sv);
|
||||
else if (code_point == '>')
|
||||
} else if (code_point == '>') {
|
||||
builder.append(">"sv);
|
||||
else if (code_point == '\n')
|
||||
} else if (code_point == '\n') {
|
||||
append_class_end();
|
||||
builder.append("</span>\n<span class=\"line\">"sv);
|
||||
else
|
||||
append_class_start();
|
||||
} else {
|
||||
builder.append_code_point(code_point);
|
||||
}
|
||||
}
|
||||
|
||||
if (class_name.has_value())
|
||||
builder.append("</span>"sv);
|
||||
|
||||
append_class_end();
|
||||
previous_position = end_position;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue