Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Twig/Jinja: incorrect recognition of some special tokens like keywords #1949

Merged
merged 1 commit into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/rouge/lexers/jinja.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ class Jinja < TemplateLexer
'text/html+django', 'text/html+jinja'

def self.keywords
@@keywords ||= %w(as context do else extends from ignore missing
import include reversed recursive scoped
autoescape endautoescape block endblock call endcall
filter endfilter for endfor if endif macro endmacro
set endset trans endtrans with endwith without)
@keywords ||= %w(as context do else extends from ignore missing
import include reversed recursive scoped
autoescape endautoescape block endblock call endcall
filter endfilter for endfor if endif macro endmacro
set endset trans endtrans with endwith without)
end

def self.tests
@@tests ||= %w(callable defined divisibleby equalto escaped even iterable
lower mapping none number odd sameas sequence string
undefined upper)
@tests ||= %w(callable defined divisibleby equalto escaped even iterable
lower mapping none number odd sameas sequence string
undefined upper)
end

def self.pseudo_keywords
@@pseudo_keywords ||= %w(true false none True False None)
@pseudo_keywords ||= %w(true false none True False None)
end

def self.word_operators
@@word_operators ||= %w(is in and or not)
@word_operators ||= %w(is in and or not)
end

state :root do
Expand Down
18 changes: 9 additions & 9 deletions lib/rouge/lexers/twig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ class Twig < Jinja
mimetypes 'application/x-twig', 'text/html+twig'

def self.keywords
@@keywords ||= %w(as do extends flush from import include use else starts
ends with without autoescape endautoescape block
endblock embed endembed filter endfilter for endfor
if endif macro endmacro sandbox endsandbox set endset
spaceless endspaceless)
@keywords ||= %w(as do extends flush from import include use else starts
ends with without autoescape endautoescape block
endblock embed endembed filter endfilter for endfor
if endif macro endmacro sandbox endsandbox set endset
spaceless endspaceless)
end

def self.tests
@@tests ||= %w(constant defined divisibleby empty even iterable null odd
sameas)
@tests ||= %w(constant defined divisibleby empty even iterable null odd
sameas)
end

def self.pseudo_keywords
@@pseudo_keywords ||= %w(true false none)
@pseudo_keywords ||= %w(true false none)
end

def self.word_operators
@@word_operators ||= %w(b-and b-or b-xor is in and or not)
@word_operators ||= %w(b-and b-or b-xor is in and or not)
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/lexers/twig_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,14 @@
assert_guess mimetype: 'text/html+twig'
end
end

describe 'regression: PR #1949' do
it 'has different keyword set than its superclass' do
refute_equal Rouge::Lexers::Twig.keywords, Rouge::Lexers::Jinja.keywords
end

it 'has different operator set than its superclass' do
refute_equal Rouge::Lexers::Twig.word_operators, Rouge::Lexers::Jinja.word_operators
end
end
end