lib/rouge/lexers/jinja.rb in rouge-3.20.0 vs lib/rouge/lexers/jinja.rb in rouge-3.21.0

- old
+ new

@@ -38,10 +38,21 @@ state :root do # Comments rule %r/{#/, Comment, :comment rule %r/##.*/, Comment + # Raw and verbatim + rule %r/({%-?)(\s*)(raw|verbatim)(\s*)(-?%})/ do |m| + groups Comment::Preproc, Text, Keyword, Text, Comment::Preproc + case m[3] + when "raw" + push :raw + when "verbatim" + push :verbatim + end + end + # Statements rule %r/\{\%/ do token Comment::Preproc push :statement end @@ -112,15 +123,10 @@ rule %r/%}|}}/, Comment::Preproc, :pop! end state :statement do - rule %r/(raw|verbatim)(\s+)(\%\})/ do - groups Keyword, Text, Comment::Preproc - goto :raw - end - rule %r/(\w+\.?)/ do |m| if self.class.keywords.include?(m[0]) groups Keyword elsif self.class.pseudo_keywords.include?(m[0]) groups Keyword::Pseudo @@ -140,15 +146,24 @@ rule %r/\%\}/, Comment::Preproc, :pop! end state :raw do - rule %r{(\{\%)(\s+)(endverbatim|endraw)(\s+)(\%\})} do + rule %r/({%-?)(\s*)(endraw)(\s*)(-?%})/ do groups Comment::Preproc, Text, Keyword, Text, Comment::Preproc pop! end + rule %r/[^{]+/, Text + rule %r/{/, Text + end - rule %r/(.+?)/m, Text + state :verbatim do + rule %r/({%-?)(\s*)(endverbatim)(\s*)(-?%})/ do + groups Comment::Preproc, Text, Keyword, Text, Comment::Preproc + pop! + end + rule %r/[^{]+/, Text + rule %r/{/, Text end end end end