mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 12:20:00 +01:00
LibWeb/HTML: Use unique offsets for nested highlighters' tokens
The code previously ensured that JS/CSS tokens did not share values with the HTML tokens, but still let them share values with each other. The numbers chosen (1000 and 2000) are somewhat arbitrary, but give us plenty of room to avoid overlaps.
This commit is contained in:
parent
2b961f145c
commit
07f0d9209a
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include <AK/Debug.h>
|
||||
#include <LibJS/SyntaxHighlighter.h>
|
||||
#include <LibJS/Token.h>
|
||||
#include <LibWeb/CSS/SyntaxHighlighter/SyntaxHighlighter.h>
|
||||
#include <LibWeb/HTML/Parser/HTMLTokenizer.h>
|
||||
#include <LibWeb/HTML/SyntaxHighlighter/SyntaxHighlighter.h>
|
||||
|
|
@ -88,10 +89,11 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
|
|||
} else if (token->is_end_tag()) {
|
||||
if (token->tag_name().is_one_of("script"sv, "style"sv)) {
|
||||
if (state == State::Javascript) {
|
||||
VERIFY(static_cast<u64>(AugmentedTokenKind::__Count) + first_free_token_kind_serial_value() < JS_TOKEN_START_VALUE);
|
||||
Syntax::ProxyHighlighterClient proxy_client {
|
||||
*m_client,
|
||||
substring_start_position,
|
||||
static_cast<u64>(AugmentedTokenKind::__Count) + first_free_token_kind_serial_value(),
|
||||
JS_TOKEN_START_VALUE,
|
||||
substring_builder.string_view()
|
||||
};
|
||||
{
|
||||
|
|
@ -106,10 +108,11 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
|
|||
folding_regions.extend(proxy_client.corrected_folding_regions());
|
||||
substring_builder.clear();
|
||||
} else if (state == State::CSS) {
|
||||
VERIFY(static_cast<u64>(AugmentedTokenKind::__Count) + first_free_token_kind_serial_value() + static_cast<u64>(JS::TokenType::_COUNT_OF_TOKENS) < CSS_TOKEN_START_VALUE);
|
||||
Syntax::ProxyHighlighterClient proxy_client {
|
||||
*m_client,
|
||||
substring_start_position,
|
||||
static_cast<u64>(AugmentedTokenKind::__Count) + first_free_token_kind_serial_value(),
|
||||
CSS_TOKEN_START_VALUE,
|
||||
substring_builder.string_view()
|
||||
};
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@ public:
|
|||
virtual Optional<StringView> comment_suffix() const override { return "-->"sv; }
|
||||
virtual void rehighlight(Palette const&) override;
|
||||
|
||||
static constexpr u64 JS_TOKEN_START_VALUE = 1000;
|
||||
static constexpr u64 CSS_TOKEN_START_VALUE = 2000;
|
||||
|
||||
protected:
|
||||
virtual Vector<MatchingTokenPair> matching_token_pairs_impl() const override;
|
||||
virtual bool token_types_equal(u64, u64) const override;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user