File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change 44
55module HTML
66 class Pipeline
7- # HTML Filter that syntax highlights code blocks wrapped
8- # in <pre lang="...">.
7+ # HTML Filter that syntax highlights text inside code blocks.
8+ #
9+ # Context options:
10+ #
11+ # :highlight => String represents the language to pick lexer. Defaults to empty string.
12+ # :scope => String represents the class attribute adds to pre element after.
13+ # Defaults to "highlight highlight-css" if highlights a css code block.
14+ #
15+ # This filter does not write any additional information to the context hash.
916 class SyntaxHighlightFilter < Filter
1017 def initialize ( *args )
1118 super ( *args )
@@ -23,11 +30,8 @@ def call
2330 next if html . nil?
2431
2532 node . inner_html = html
26- klass = node [ 'class' ]
27- scope = context [ :scope ] || "highlight-#{ lang } "
28- klass = [ klass , scope ] . compact . join ' '
29-
30- node [ 'class' ] = klass
33+ scope = context . fetch ( :scope ) { 'highlight' }
34+ node [ 'class' ] = "#{ scope } #{ scope } -#{ lang } "
3135 end
3236 doc
3337 end
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ def test_highlight_default
1111 '<pre>hello</pre>' , highlight : 'coffeescript'
1212
1313 doc = filter . call
14+ assert !doc . css ( '.highlight' ) . empty?
1415 assert !doc . css ( '.highlight-coffeescript' ) . empty?
1516 end
1617
You can’t perform that action at this time.
0 commit comments