summaryrefslogtreecommitdiff
path: root/lib/rouge/formatters
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2015-07-30 22:31:53 -0700
committerStan Hu <stanhu@gmail.com>2015-07-30 22:37:53 -0700
commit0abe98f0497b667ef85ad4e078ea5c10b5b26ede (patch)
tree4d7eeb19a0a8edaa622a9ae081879df8f3f435a1 /lib/rouge/formatters
parenta51a3fb8ed92a58b375125b19f75c3d4c545571a (diff)
downloadgitlab-ce-0abe98f0497b667ef85ad4e078ea5c10b5b26ede.tar.gz
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
Diffstat (limited to 'lib/rouge/formatters')
-rw-r--r--lib/rouge/formatters/html_gitlab.rb12
1 files changed, 10 insertions, 2 deletions
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| "<span #{element}>#{x}</span>" }
+ 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
- "<span style=\"#{rules.to_a.join(';')}\">#{val}</span>"
+ wrap_values(val, "style=\"#{rules.to_a.join(';')}\"")
else
- "<span class=\"#{tok.shortname}\">#{val}</span>"
+ wrap_values(val, "class=\"#{tok.shortname}\"")
end
end
end