From 0abe98f0497b667ef85ad4e078ea5c10b5b26ede Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Thu, 30 Jul 2015 22:31:53 -0700 Subject: Fix multi-line syntax highlighting HTML span elements only apply to a single line, and in the case of multi-line comments, the highlighting was dropped as a result. Ensure that each line has the proper styling to fix this. Closes #1577 --- lib/rouge/formatters/html_gitlab.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/rouge') diff --git a/lib/rouge/formatters/html_gitlab.rb b/lib/rouge/formatters/html_gitlab.rb index 485af6832d7..092a920a0c4 100644 --- a/lib/rouge/formatters/html_gitlab.rb +++ b/lib/rouge/formatters/html_gitlab.rb @@ -148,6 +148,12 @@ module Rouge end end + def wrap_values(val, element) + lines = val.split("\n") + lines = lines.map{ |x| "#{x}" } + lines.join("\n") + end + def span(tok, val) # http://stackoverflow.com/a/1600584/2587286 val = CGI.escapeHTML(val) @@ -155,11 +161,13 @@ module Rouge if tok.shortname.empty? val else + # In the case of multi-line values (e.g. comments), we need to apply + # styling to each line since span elements are inline. if @inline_theme rules = @inline_theme.style_for(tok).rendered_rules - "#{val}" + wrap_values(val, "style=\"#{rules.to_a.join(';')}\"") else - "#{val}" + wrap_values(val, "class=\"#{tok.shortname}\"") end end end -- cgit v1.2.3