Skip to content

Commit

Permalink
JSX: Allow dashes in attribute names (#1650)
Browse files Browse the repository at this point in the history
Support attributes with names that contain dashes, e.g. ARIA attributes.
  • Loading branch information
bpl authored Jan 26, 2022
1 parent c91b3a7 commit 8229933
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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

0 comments on commit 8229933

Please sign in to comment.