summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML/SyntaxHighlighter/SyntaxHighlighter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML/SyntaxHighlighter/SyntaxHighlighter.cpp')
-rw-r--r--Userland/Libraries/LibWeb/HTML/SyntaxHighlighter/SyntaxHighlighter.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/SyntaxHighlighter/SyntaxHighlighter.cpp b/Userland/Libraries/LibWeb/HTML/SyntaxHighlighter/SyntaxHighlighter.cpp
index 48759ff842..df66bede63 100644
--- a/Userland/Libraries/LibWeb/HTML/SyntaxHighlighter/SyntaxHighlighter.cpp
+++ b/Userland/Libraries/LibWeb/HTML/SyntaxHighlighter/SyntaxHighlighter.cpp
@@ -40,6 +40,10 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
Vector<GUI::TextDocumentSpan> spans;
auto highlight = [&](auto start_line, auto start_column, auto end_line, auto end_column, Gfx::TextAttributes attributes, AugmentedTokenKind kind) {
+ if (start_line > end_line || (start_line == end_line && start_column >= end_column)) {
+ dbgln_if(SYNTAX_HIGHLIGHTING_DEBUG, "(HTML::SyntaxHighlighter) discarding ({}-{}) to ({}-{}) because it has zero or negative length", start_line, start_column, end_line, end_column);
+ return;
+ }
dbgln_if(SYNTAX_HIGHLIGHTING_DEBUG, "(HTML::SyntaxHighlighter) highlighting ({}-{}) to ({}-{}) with color {}", start_line, start_column, end_line, end_column, attributes.color);
spans.empend(
GUI::TextRange {
@@ -59,7 +63,7 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
} state { State::HTML };
for (;;) {
auto token = tokenizer.next_token();
- if (!token.has_value())
+ if (!token.has_value() || token.value().is_end_of_file())
break;
dbgln_if(SYNTAX_HIGHLIGHTING_DEBUG, "(HTML::SyntaxHighlighter) got token of type {}", token->to_string());
@@ -88,17 +92,16 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
highlight(
token->start_position().line,
token->start_position().column,
- token->start_position().line,
- token->start_position().column,
+ token->end_position().line,
+ token->end_position().column,
{ palette.syntax_comment(), {} },
AugmentedTokenKind::Comment);
} else if (token->is_start_tag() || token->is_end_tag()) {
- // FIXME: This breaks with single-character tag names.
highlight(
token->start_position().line,
token->start_position().column + token_start_offset,
token->start_position().line,
- token->start_position().column + token->tag_name().length() + token_start_offset - 1,
+ token->start_position().column + token_start_offset + token->tag_name().length(),
{ palette.syntax_keyword(), {}, false, true },
token->is_start_tag() ? AugmentedTokenKind::OpenTag : AugmentedTokenKind::CloseTag);