Skip to content

Commit e042c3e

Browse files
author
Simeon F. Willbanks
committed
Merge upstream/master; activesupport is a full dependency
2 parents f9c6d06 + df26d88 commit e042c3e

File tree

8 files changed

+49
-7
lines changed

8 files changed

+49
-7
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# CHANGELOG
22

3+
## 0.3.1
4+
5+
* Guard against nil node replacement in SyntaxHighlightFilter #84 jbarnette
6+
7+
## 0.3.0
8+
9+
* Add support for manually specified default language in SyntaxHighlightFilter #81 jbarnette
10+
311
## 0.2.1
412

513
* Moves ActiveSupport as a development dependency #79

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ gem 'github-linguist'
121121

122122
_Note:_ See [Gemfile](https://github.com/jch/html-pipeline/blob/master/Gemfile) `:test` block for version requirements.
123123

124+
## 3rd Party Extensions
125+
126+
If you have an idea for a filter, propose it as
127+
[an issue](https://github.com/jch/html-pipeline/issues) first. This allows us discuss
128+
whether the filter is a common enough use case to belong in this gem, or should be
129+
built as an external gem.
130+
131+
* [html-pipeline-asciidoc_filter](https://github.com/asciidoctor/html-pipeline-asciidoc_filter) - asciidoc support
132+
124133
## Examples
125134

126135
We define different pipelines for different parts of our app. Here are a few

html-pipeline.gemspec

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ Gem::Specification.new do |gem|
1515
gem.test_files = gem.files.grep(%r{^test})
1616
gem.require_paths = ["lib"]
1717

18-
gem.add_dependency "nokogiri", RUBY_VERSION < "1.9.2" ? [">= 1.4", "< 1.6"] : "~> 1.4"
19-
20-
gem.add_development_dependency "activesupport", RUBY_VERSION < "1.9.3" ? [">= 2", "< 4"] : ">= 2"
18+
gem.add_dependency "nokogiri", RUBY_VERSION < "1.9.2" ? [">= 1.4", "< 1.6"] : "~> 1.4"
19+
gem.add_dependency "activesupport", RUBY_VERSION < "1.9.3" ? [">= 2", "< 4"] : ">= 2"
2120

2221
gem.post_install_message = <<msg
2322
-------------------------------------------------

lib/html/pipeline.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "nokogiri"
2+
require "active_support/xml_mini/nokogiri" # convert Documents to hashes
23

34
module HTML
45
# GitHub HTML processing filters and utilities. This module includes a small

lib/html/pipeline/syntax_highlight_filter.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@ class Pipeline
1212
class SyntaxHighlightFilter < Filter
1313
def call
1414
doc.search('pre').each do |node|
15-
next unless lang = node['lang']
15+
default = context[:highlight] && context[:highlight].to_s
16+
next unless lang = node['lang'] || default
1617
next unless lexer = Pygments::Lexer[lang]
1718
text = node.inner_text
1819

1920
html = highlight_with_timeout_handling(lexer, text)
2021
next if html.nil?
2122

22-
node.replace(html)
23+
if (node = node.replace(html).first)
24+
klass = node["class"]
25+
klass = [klass, "highlight-#{lang}"].compact.join " "
26+
27+
node["class"] = klass
28+
end
2329
end
2430
doc
2531
end

lib/html/pipeline/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module HTML
22
class Pipeline
3-
VERSION = "0.2.1"
3+
VERSION = "0.3.1"
44
end
55
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
require "test_helper"
22

3+
SyntaxHighlightFilter = HTML::Pipeline::SyntaxHighlightFilter
4+
35
class HTML::Pipeline::SyntaxHighlightFilterTest < Test::Unit::TestCase
46
def test_dependency_management
57
assert_dependency "syntax_highlight_filter", "github-linguist"
68
end
9+
10+
def test_highlight_default
11+
filter = SyntaxHighlightFilter.new \
12+
"<pre>hello</pre>", :highlight => "coffeescript"
13+
14+
doc = filter.call
15+
assert !doc.css(".highlight-coffeescript").empty?
16+
end
17+
18+
def test_highlight_default_will_not_override
19+
filter = SyntaxHighlightFilter.new \
20+
"<pre lang='c'>hello</pre>", :highlight => "coffeescript"
21+
22+
doc = filter.call
23+
assert doc.css(".highlight-coffeescript").empty?
24+
assert !doc.css(".highlight-c").empty?
25+
end
726
end

test/test_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
require "html/pipeline"
33
require "test/unit"
44

5+
require "active_support/core_ext/string"
56
require "active_support/core_ext/object/try"
6-
require "active_support/xml_mini/nokogiri" # convert Documents to hashes
77

88
module TestHelpers
99
# Asserts that `needle` is not a member of `haystack`, where

0 commit comments

Comments
 (0)