From 99eb20bd19b4724da007c20bd9a29c478f2ca51d Mon Sep 17 00:00:00 2001 From: Tan Le Date: Tue, 11 Jun 2024 22:41:44 +1000 Subject: [PATCH] Support bold and italics at the same time (#2053) --- lib/rouge/lexers/markdown.rb | 3 ++- lib/rouge/themes/base16.rb | 4 ++++ lib/rouge/themes/bw.rb | 1 + lib/rouge/themes/colorful.rb | 1 + lib/rouge/themes/github.rb | 1 + lib/rouge/themes/gruvbox.rb | 5 ++++- lib/rouge/themes/igor_pro.rb | 3 +++ lib/rouge/themes/magritte.rb | 1 + lib/rouge/themes/molokai.rb | 3 ++- lib/rouge/themes/monokai.rb | 3 ++- lib/rouge/themes/monokai_sublime.rb | 7 ++++--- lib/rouge/themes/pastie.rb | 1 + lib/rouge/themes/thankful_eyes.rb | 1 + lib/rouge/themes/tulip.rb | 1 + lib/rouge/token.rb | 3 ++- spec/visual/samples/markdown | 8 ++++++++ 16 files changed, 38 insertions(+), 8 deletions(-) diff --git a/lib/rouge/lexers/markdown.rb b/lib/rouge/lexers/markdown.rb index d9e368a14e..7d0d2c49d9 100644 --- a/lib/rouge/lexers/markdown.rb +++ b/lib/rouge/lexers/markdown.rb @@ -107,7 +107,8 @@ def html push :link end - rule %r/[*][*]#{edot}*?[*][*]/, Generic::Strong + rule %r/[*]{2}[^* \n][^*\n]*[*]{2}/, Generic::Strong + rule %r/[*]{3}[^* \n][^*\n]*[*]{3}/, Generic::EmphStrong rule %r/__#{edot}*?__/, Generic::Strong rule %r/[*]#{edot}*?[*]/, Generic::Emph diff --git a/lib/rouge/themes/base16.rb b/lib/rouge/themes/base16.rb index 5470c4977f..6e77c6acfe 100644 --- a/lib/rouge/themes/base16.rb +++ b/lib/rouge/themes/base16.rb @@ -61,6 +61,10 @@ def self.make_light! style Generic::Deleted, :fg => :base08 style Generic::Heading, :fg => :base0D, :bg => :base00, :bold => true + style Generic::Emph, :italic => true + style Generic::EmphStrong, :italic => true, :bold => true + style Generic::Strong, :bold => true + style Keyword, :fg => :base0E style Keyword::Constant, Keyword::Type, :fg => :base09 diff --git a/lib/rouge/themes/bw.rb b/lib/rouge/themes/bw.rb index 0752ed5b5a..779359a1a3 100644 --- a/lib/rouge/themes/bw.rb +++ b/lib/rouge/themes/bw.rb @@ -33,6 +33,7 @@ class BlackWhiteTheme < CSSTheme style Generic::Heading, :bold => true style Generic::Subheading, :bold => true style Generic::Emph, :italic => true + style Generic::EmphStrong, :italic => true, :bold => true style Generic::Strong, :bold => true style Generic::Prompt, :bold => true diff --git a/lib/rouge/themes/colorful.rb b/lib/rouge/themes/colorful.rb index abdd6788ea..43acc90997 100644 --- a/lib/rouge/themes/colorful.rb +++ b/lib/rouge/themes/colorful.rb @@ -58,6 +58,7 @@ class Colorful < CSSTheme style Generic::Inserted, :fg => "#00A000" style Generic::Error, :fg => "#FF0000" style Generic::Emph, :italic => true + style Generic::EmphStrong, :italic => true, :bold => true style Generic::Strong, :bold => true style Generic::Prompt, :fg => "#c65d09", :bold => true style Generic::Output, :fg => "#888" diff --git a/lib/rouge/themes/github.rb b/lib/rouge/themes/github.rb index 53acefd931..27b8a5f925 100644 --- a/lib/rouge/themes/github.rb +++ b/lib/rouge/themes/github.rb @@ -111,6 +111,7 @@ def self.make_light! Name::Tag, :fg => :tag style Generic::Inserted, :fg => :fgInserted, :bg => :bgInserted + style Generic::EmphStrong, :italic => true, :bold => true style Keyword::Constant, Literal, diff --git a/lib/rouge/themes/gruvbox.rb b/lib/rouge/themes/gruvbox.rb index 116b136172..8faf4cc5f6 100644 --- a/lib/rouge/themes/gruvbox.rb +++ b/lib/rouge/themes/gruvbox.rb @@ -140,6 +140,10 @@ def self.make_light! style Generic::Deleted, :fg => :red, :bg => :bg0 style Generic::Heading, :fg => :green, :bold => true + style Generic::Emph, :italic => true + style Generic::EmphStrong, :italic => true, :bold => true + style Generic::Strong, :bold => true + style Keyword, :fg => :red style Keyword::Constant, :fg => :purple style Keyword::Type, :fg => :yellow @@ -164,7 +168,6 @@ def self.make_light! style Literal::Number, :fg => :purple style Literal::String::Symbol, :fg => :blue - end end end diff --git a/lib/rouge/themes/igor_pro.rb b/lib/rouge/themes/igor_pro.rb index 17c9dd3ef3..abcc758149 100644 --- a/lib/rouge/themes/igor_pro.rb +++ b/lib/rouge/themes/igor_pro.rb @@ -10,6 +10,9 @@ class IgorPro < CSSTheme style Comment::Preproc, :fg => '#CC00A3' style Comment::Special, :fg => '#CC00A3' style Comment, :fg => '#FF0000' + style Generic::Emph, :italic => true + style Generic::EmphStrong, :italic => true, :bold => true + style Generic::Strong, :bold => true style Keyword::Constant, :fg => '#C34E00' style Keyword::Declaration, :fg => '#0000FF' style Keyword::Reserved, :fg => '#007575' diff --git a/lib/rouge/themes/magritte.rb b/lib/rouge/themes/magritte.rb index 13a21a1f74..09fc1ecbd0 100644 --- a/lib/rouge/themes/magritte.rb +++ b/lib/rouge/themes/magritte.rb @@ -41,6 +41,7 @@ class Magritte < CSSTheme style Generic::Deleted, :fg => :cherry style Generic::Inserted, :fg => :forest style Generic::Emph, :italic => true + style Generic::EmphStrong, :italic => true, :bold => true style Generic::Strong, :bold => true style Generic::Traceback, :fg => :black, :bg => :lavender style Keyword::Constant, :fg => :forest, :bold => true diff --git a/lib/rouge/themes/molokai.rb b/lib/rouge/themes/molokai.rb index 119422f29c..33d039181e 100644 --- a/lib/rouge/themes/molokai.rb +++ b/lib/rouge/themes/molokai.rb @@ -25,7 +25,8 @@ class Molokai < CSSTheme style Error, :fg => :white, :bg => :grey style Generic::Inserted, :fg => :green style Generic::Deleted, :fg => :red - style Generic::Emph, :fg => :black, :italic => true + style Generic::Emph, :italic => true + style Generic::EmphStrong, :italic => true, :bold => true style Generic::Error, Generic::Traceback, :fg => :red style Generic::Heading, :fg => :grey diff --git a/lib/rouge/themes/monokai.rb b/lib/rouge/themes/monokai.rb index 5469c0e55a..412f860a49 100644 --- a/lib/rouge/themes/monokai.rb +++ b/lib/rouge/themes/monokai.rb @@ -35,7 +35,8 @@ class Monokai < CSSTheme style Error, :fg => :carmine, :bg => :very_dark style Generic::Inserted, :fg => :white, :bg => :dimgreen style Generic::Deleted, :fg => :white, :bg => :dimred - style Generic::Emph, :fg => :black, :italic => true + style Generic::Emph, :italic => true + style Generic::EmphStrong, :italic => true, :bold => true style Generic::Error, Generic::Traceback, :fg => :dark_red style Generic::Heading, :fg => :grey diff --git a/lib/rouge/themes/monokai_sublime.rb b/lib/rouge/themes/monokai_sublime.rb index 050150b689..b0f2cd6251 100644 --- a/lib/rouge/themes/monokai_sublime.rb +++ b/lib/rouge/themes/monokai_sublime.rb @@ -30,7 +30,9 @@ class MonokaiSublime < CSSTheme style Literal::String::Regex, :fg => :orange style Generic::Output, :fg => :dark_grey style Generic::Prompt, :fg => :emperor - style Generic::Strong, :bold => false + style Generic::Emph, :italic => true + style Generic::EmphStrong, :italic => true, :bold => true + style Generic::Strong, :bold => true style Generic::Subheading, :fg => :light_grey style Name::Builtin, :fg => :orange style Comment::Multiline, @@ -42,8 +44,7 @@ class MonokaiSublime < CSSTheme Generic::Error, Generic::Traceback, :fg => :carmine style Generic::Deleted, - Generic::Inserted, - Generic::Emph, :fg => :dark + Generic::Inserted, :fg => :dark style Keyword::Constant, Keyword::Declaration, Keyword::Reserved, diff --git a/lib/rouge/themes/pastie.rb b/lib/rouge/themes/pastie.rb index be1e48850d..f10c7b045d 100644 --- a/lib/rouge/themes/pastie.rb +++ b/lib/rouge/themes/pastie.rb @@ -22,6 +22,7 @@ class Pastie < CSSTheme style Generic::Inserted, :fg => '#000000', :bg => '#ddffdd' style Generic::Emph, :italic => true + style Generic::EmphStrong, :italic => true, :bold => true style Generic::Strong, :bold => true style Generic::Lineno, :fg => '#888888' diff --git a/lib/rouge/themes/thankful_eyes.rb b/lib/rouge/themes/thankful_eyes.rb index d13fae78a9..2f842096ff 100644 --- a/lib/rouge/themes/thankful_eyes.rb +++ b/lib/rouge/themes/thankful_eyes.rb @@ -38,6 +38,7 @@ class ThankfulEyes < CSSTheme style Generic::Deleted, :fg => :scarletred2 style Generic::Inserted, :fg => :go_get_it style Generic::Emph, :italic => true + style Generic::EmphStrong, :italic => true, :bold => true style Generic::Strong, :bold => true style Generic::Traceback, :fg => :eggshell_cloud, :bg => :slate_blue style Keyword::Constant, :fg => :pink_merengue, :bold => true diff --git a/lib/rouge/themes/tulip.rb b/lib/rouge/themes/tulip.rb index df3ad71433..5429a66202 100644 --- a/lib/rouge/themes/tulip.rb +++ b/lib/rouge/themes/tulip.rb @@ -33,6 +33,7 @@ class Tulip < CSSTheme style Generic::Deleted, :fg => :red style Generic::Inserted, :fg => :green style Generic::Emph, :italic => true + style Generic::EmphStrong, :italic => true, :bold => true style Generic::Strong, :bold => true style Generic::Traceback, Generic::Lineno, :fg => :white, :bg => :purple diff --git a/lib/rouge/token.rb b/lib/rouge/token.rb index c6de5313e0..9c3f867c85 100644 --- a/lib/rouge/token.rb +++ b/lib/rouge/token.rb @@ -172,15 +172,16 @@ def self.token(name, shortname, &b) token :Generic, 'g' do token :Deleted, 'gd' token :Emph, 'ge' + token :EmphStrong, 'ges' token :Error, 'gr' token :Heading, 'gh' token :Inserted, 'gi' + token :Lineno, 'gl' token :Output, 'go' token :Prompt, 'gp' token :Strong, 'gs' token :Subheading, 'gu' token :Traceback, 'gt' - token :Lineno, 'gl' end # convenience diff --git a/spec/visual/samples/markdown b/spec/visual/samples/markdown index be2a700002..7672ef0766 100644 --- a/spec/visual/samples/markdown +++ b/spec/visual/samples/markdown @@ -828,6 +828,8 @@ HTML `` tag; double `*`'s or `_`'s will be wrapped with an HTML **double asterisks** + ***triple asterisks*** + __double underscores__ will produce: @@ -1097,3 +1099,9 @@ has (parens too)](example.com), and text after it. [this is not a link] + +*single asterisks* +_single underscores_ +**double asterisks** +***triple asterisks*** +__double underscores__