From 6239a367a47aa2e5ceb8c58994b8a79b622c231f Mon Sep 17 00:00:00 2001 From: Aapo Laitinen Date: Mon, 14 Dec 2020 16:45:13 +0900 Subject: [PATCH] JSX: Allow dashes in attribute names Support attributes with names that contain dashes, e.g. ARIA attributes. --- lib/rouge/lexers/jsx.rb | 2 +- spec/lexers/jsx_spec.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/rouge/lexers/jsx.rb b/lib/rouge/lexers/jsx.rb index 90f3cc69cc..b0fac6e581 100644 --- a/lib/rouge/lexers/jsx.rb +++ b/lib/rouge/lexers/jsx.rb @@ -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 diff --git a/spec/lexers/jsx_spec.rb b/spec/lexers/jsx_spec.rb index fd6d583019..358ebfa1f5 100644 --- a/spec/lexers/jsx_spec.rb +++ b/spec/lexers/jsx_spec.rb @@ -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 '