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

JSX: Allow dashes in attribute names #1650

Merged
merged 1 commit into from
Jan 26, 2022
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
2 changes: 1 addition & 1 deletion lib/rouge/lexers/jsx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class JSX < Javascript
push :interpol
push :expr_start
end
rule %r/\w+/, Name::Attribute
rule %r/\w[\w-]*/, Name::Attribute
rule %r/=/, Punctuation
rule %r/(["']).*?(\1)/, Str
end
Expand Down
15 changes: 15 additions & 0 deletions spec/lexers/jsx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,20 @@
assert_guess :mimetype => 'application/x-jsx'
end
end

describe 'lexing' do
include Support::Lexing

it 'parse attribute with dashes' do
assert_tokens_equal '<button aria-label="hello"/>',
['Punctuation', '<'],
['Name.Tag', 'button'],
['Text', ' '],
['Name.Attribute', 'aria-label'],
['Punctuation', '='],
['Literal.String', '"hello"'],
['Punctuation', '/>']
end
end
end