Skip to content

Commit 02bf963

Browse files
jneenjneen
andauthored
HTMLDebug formatter with title tags showing the token type and value. (#2261)
* add Rouge::Formatters::HTMLDebug * use HTMLDebug formatter in the visual spec --------- Co-authored-by: jneen <[email protected]>
1 parent b8b0632 commit 02bf963

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

lib/rouge.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def eager_load!
9494
require_relative 'rouge/formatters/html_line_highlighter'
9595
require_relative 'rouge/formatters/html_line_table'
9696
require_relative 'rouge/formatters/html_inline'
97+
require_relative 'rouge/formatters/html_debug'
9798
require_relative 'rouge/formatters/terminal256'
9899
require_relative 'rouge/formatters/terminal_truecolor'
99100
require_relative 'rouge/formatters/tex'

lib/rouge/formatters/html_debug.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Rouge
2+
module Formatters
3+
class HTMLDebug < HTML
4+
tag 'html_debug'
5+
6+
def safe_span(tok, safe_val)
7+
safer_val = safe_val.gsub('"', '&quot;')
8+
9+
title = "#{tok.qualname}(#{safer_val})"
10+
shortname = tok.shortname
11+
12+
%(<span title="#{title}" class="#{shortname}">#{safe_val}</span>)
13+
end
14+
end
15+
end
16+
end

spec/visual/app.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def setup_formatter(params)
3737
# base HTML formatter
3838
formatter = inline ?
3939
Rouge::Formatters::HTMLInline.new(@theme) :
40-
Rouge::Formatters::HTML.new
40+
Rouge::Formatters::HTMLDebug.new
4141

4242
if line_numbers
4343
formatter = line_table ?

0 commit comments

Comments
 (0)