html-pipeline 2.12.2 → 2.12.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 702de4fa9110f19e81455f55602814635b84571cd2843f3f5f7ff170bc7a82c6
4
- data.tar.gz: 52987477bd8fa61bbf987796a7e3807fdc8ee45ba302de48adaade489191cc47
3
+ metadata.gz: da71be14d105c41b4c841253adaf3646b5c8efad72172dbe3169e059c435ac34
4
+ data.tar.gz: f63b526c33f871f40e0144a783d02c598f75dabe15db4b4c37e98e1ca439550f
5
5
  SHA512:
6
- metadata.gz: b52aede2c77145988c986968629bcc0c3f58beae1f2c1e6592d5424bdde45d61398636e45e069096b847322042f1bd3ee77bf17c5c11ee8622866fcf5bdc45bf
7
- data.tar.gz: 03a09d389bed980a2de123008f9744f691c2d34925952a996c0881156a050448805d48af363c58efcb25444d68923fb3ddd5581fc0ee20054b9a4244335ad918
6
+ metadata.gz: cd26fc63cf7201a14ab72f91d273991348b9f330d68f81e3340b231f8256983233b7f377489bd9d3d1f5660814e0109c92a8c3799bb1e4bc26e0aa9ab338660b
7
+ data.tar.gz: 6cf11ee69a0dd68bb33886d7cc4003fb775b02e82072e208122d6787e9b9d1c487d2b17ab82af920b15688702374318733e07b05d23dd0dbc0904bc4462e8380
data/README.md CHANGED
@@ -82,7 +82,7 @@ Prints:
82
82
  </code></pre>
83
83
  ```
84
84
 
85
- To generate CSS for HTML formatted code, use the [Rouge CSS Theme](https://github.com/jneen/rouge#css-theme-options) `#css` method. `rouge` is a dependency of the `SyntaxHighlightFilter`.
85
+ To generate CSS for HTML formatted code, use the [Rouge CSS Theme](https://github.com/rouge-ruby/rouge#css-options) `#css` method. `rouge` is a dependency of the `SyntaxHighlightFilter`.
86
86
 
87
87
  Some filters take an optional **context** and/or **result** hash. These are
88
88
  used to pass around arguments and metadata between filters in a pipeline. For
@@ -4,8 +4,15 @@ HTML::Pipeline.require_dependency('rouge', 'SyntaxHighlightFilter')
4
4
 
5
5
  module HTML
6
6
  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.
9
16
  class SyntaxHighlightFilter < Filter
10
17
  def initialize(*args)
11
18
  super(*args)
@@ -17,23 +24,20 @@ module HTML
17
24
  default = context[:highlight] && context[:highlight].to_s
18
25
  next unless lang = node['lang'] || default
19
26
  next unless lexer = lexer_for(lang)
20
- text = node.inner_text
21
27
 
22
- html = highlight_with_timeout_handling(text, lang)
28
+ text = node.inner_text
29
+ html = highlight_with_timeout_handling(text, lexer)
23
30
  next if html.nil?
24
31
 
25
32
  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}"
31
35
  end
32
36
  doc
33
37
  end
34
38
 
35
- def highlight_with_timeout_handling(text, lang)
36
- Rouge.highlight(text, lang, @formatter)
39
+ def highlight_with_timeout_handling(text, lexer)
40
+ Rouge.highlight(text, lexer, @formatter)
37
41
  rescue Timeout::Error => _
38
42
  nil
39
43
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module HTML
4
4
  class Pipeline
5
- VERSION = '2.12.2'.freeze
5
+ VERSION = '2.12.3'.freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html-pipeline
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.2
4
+ version: 2.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Tomayko
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-11-14 00:00:00.000000000 Z
13
+ date: 2019-12-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport