html-pipeline 2.12.2 → 2.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/html/pipeline/syntax_highlight_filter.rb +15 -11
- data/lib/html/pipeline/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da71be14d105c41b4c841253adaf3646b5c8efad72172dbe3169e059c435ac34
|
4
|
+
data.tar.gz: f63b526c33f871f40e0144a783d02c598f75dabe15db4b4c37e98e1ca439550f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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/
|
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
|
8
|
-
#
|
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
|
-
|
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
|
-
|
27
|
-
|
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,
|
36
|
-
Rouge.highlight(text,
|
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
|
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.
|
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-
|
13
|
+
date: 2019-12-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|