Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

Commit

Permalink
Use String::Affix token for string prefixes in Python lexer (rouge-ru…
Browse files Browse the repository at this point in the history
…by#1635)

String prefixes were given the same token (`Str`) at the string itself.
This commit uses the `String::Affix` token for the prefix character.
This is consistent with the tokens used by Pygments. New styles for
`String::Affix` are also added.
  • Loading branch information
tancnle authored and mattt committed May 19, 2021
1 parent c36a912 commit 17015d7
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rouge/lexers/python.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def current_string
# TODO: not in python 3
rule %r/`.*?`/, Str::Backtick
rule %r/([rfbu]{0,2})('''|"""|['"])/i do |m|
token Str
groups Str::Affix, Str
current_string.register type: m[1].downcase, delim: m[2]
push :generic_string
end
Expand Down
1 change: 1 addition & 0 deletions lib/rouge/themes/base16.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def self.make_light!
style Keyword::Declaration, :fg => :base09

style Literal::String, :fg => :base0B
style Literal::String::Affix, :fg => :base0E
style Literal::String::Regex, :fg => :base0C

style Literal::String::Interpol,
Expand Down
1 change: 1 addition & 0 deletions lib/rouge/themes/bw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class BlackWhiteTheme < CSSTheme
style Name::Tag, :bold => true

style Literal::String, :italic => true
style Literal::String::Affix, :bold => true
style Literal::String::Interpol, :bold => true
style Literal::String::Escape, :bold => true

Expand Down
1 change: 1 addition & 0 deletions lib/rouge/themes/colorful.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Colorful < CSSTheme
style Name::Decorator, :fg => "#555", :bold => true

style Literal::String, :bg => "#fff0f0"
style Literal::String::Affix, :fg => "#080", :bold => true
style Literal::String::Char, :fg => "#04D"
style Literal::String::Doc, :fg => "#D42"
style Literal::String::Interpol, :bg => "#eee"
Expand Down
1 change: 1 addition & 0 deletions lib/rouge/themes/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Github < CSSTheme
style Literal::Number::Integer, :fg => '#009999'
style Literal::Number::Oct, :fg => '#009999'
style Literal::Number, :fg => '#009999'
style Literal::String::Affix, :fg => '#000000', :bold => true
style Literal::String::Backtick, :fg => '#d14'
style Literal::String::Char, :fg => '#d14'
style Literal::String::Doc, :fg => '#d14'
Expand Down
2 changes: 2 additions & 0 deletions lib/rouge/themes/gruvbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ def self.make_light!
Literal::String::Interpol,
Literal::String::Regex, :fg => :green, :italic => true

style Literal::String::Affix, :fg => :red

style Literal::String::Escape, :fg => :orange

style Name::Namespace,
Expand Down
1 change: 1 addition & 0 deletions lib/rouge/themes/igor_pro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class IgorPro < CSSTheme
style Keyword::Reserved, :fg => '#007575'
style Keyword, :fg => '#0000FF'
style Literal::String, :fg => '#009C00'
style Literal::String::Affix, :fg => '#0000FF'
style Name::Builtin, :fg => '#C34E00'
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/rouge/themes/magritte.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Magritte < CSSTheme
Literal::Date, :fg => :forest, :bold => true
style Literal::String::Symbol, :fg => :forest
style Literal::String, :fg => :wine, :bold => true
style Literal::String::Affix, :fg => :royal, :bold => true
style Literal::String::Escape,
Literal::String::Char,
Literal::String::Interpol, :fg => :purple, :bold => true
Expand Down
1 change: 1 addition & 0 deletions lib/rouge/themes/monokai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Monokai < CSSTheme
Literal::Number::Oct,
Literal::Number,
Literal::String::Escape, :fg => :light_violet
style Literal::String::Affix, :fg => :soft_cyan, :bold => true
style Literal::String::Backtick,
Literal::String::Char,
Literal::String::Doc,
Expand Down
1 change: 1 addition & 0 deletions lib/rouge/themes/pastie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Pastie < CSSTheme
style Num, :fg => '#0000dd', :bold => true

style Str, :fg => '#dd2200', :bg => '#fff0f0'
style Str::Affix, :fg => '#008800', :bold => true
style Str::Escape, :fg => '#0044dd', :bg => '#fff0f0'
style Str::Interpol, :fg => '#3333bb', :bg => '#fff0f0'
style Str::Other, :fg => '#22bb22', :bg => '#f0fff0'
Expand Down
1 change: 1 addition & 0 deletions lib/rouge/themes/thankful_eyes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ThankfulEyes < CSSTheme
Literal::Date,
Literal::String::Symbol, :fg => :pink_merengue, :bold => true
style Literal::String, :fg => :dune, :bold => true
style Literal::String::Affix, :fg => :sandy, :bold => true
style Literal::String::Escape,
Literal::String::Char,
Literal::String::Interpol, :fg => :backlit, :bold => true
Expand Down
1 change: 1 addition & 0 deletions lib/rouge/themes/tulip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Tulip < CSSTheme
Literal::Date,
Literal::String::Symbol, :fg => :lpurple, :bold => true
style Literal::String, :fg => :dune, :bold => true
style Literal::String::Affix, :fg => :yellow, :bold => true
style Literal::String::Escape,
Literal::String::Char,
Literal::String::Interpol, :fg => :orange, :bold => true
Expand Down

0 comments on commit 17015d7

Please sign in to comment.