From 7061d11c548542590532958e50384ffa3e971837 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Tue, 1 Apr 2014 13:18:40 -0700 Subject: [PATCH 1/3] Allow for custom filters --- lib/jekyll-html-pipeline.rb | 7 ++++++- test/support/new_pipeline.rb | 15 +++++++++++++++ test/test_jekyll_html_pipeline.rb | 9 +++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/support/new_pipeline.rb diff --git a/lib/jekyll-html-pipeline.rb b/lib/jekyll-html-pipeline.rb index 8b357dc..23f0d1d 100644 --- a/lib/jekyll-html-pipeline.rb +++ b/lib/jekyll-html-pipeline.rb @@ -35,7 +35,12 @@ def setup key = filter_key(f) begin filter = HTML::Pipeline.constants.find { |c| c.downcase == key } - HTML::Pipeline.const_get(filter) + # probably a custom filter + if filter.nil? + Jekyll::Converters.const_get(f) + else + HTML::Pipeline.const_get(filter) + end rescue Exception => e raise LoadError.new(e) end diff --git a/test/support/new_pipeline.rb b/test/support/new_pipeline.rb new file mode 100644 index 0000000..ddc9a42 --- /dev/null +++ b/test/support/new_pipeline.rb @@ -0,0 +1,15 @@ +require "html/pipeline" + +class HelpMarkdownFilter < HTML::Pipeline::MarkdownFilter + + def call + html = super + + format_callout!(html) + end + + def format_callout!(html) + html.gsub!(/(?:

)?{{#(tip|warning|error)}}(?:<\/p>)?/, '

') + html.gsub!(/(?:

)?{{\/(tip|warning|error)}}(?:<\/p>)?/, '

') + end +end diff --git a/test/test_jekyll_html_pipeline.rb b/test/test_jekyll_html_pipeline.rb index 8bc493a..9ae8f28 100644 --- a/test/test_jekyll_html_pipeline.rb +++ b/test/test_jekyll_html_pipeline.rb @@ -37,5 +37,14 @@ class HTMLPipeline < Test::Unit::TestCase markdown = Jekyll::Converters::Markdown.new override assert_raise(ArgumentError) { markdown.convert(':trollface:') } end + + should "work for custom filters" do + require 'support/new_pipeline' + override = @config.dup + override['html_pipeline']['filters'] = ['HelpMarkdownFilter'] + markdown = Jekyll::Converters::Markdown.new override + text = "\n {{#tip}}\n **Tip**: Wow! \n {{/tip}}" + assert_equal "

\n Tip: Wow!
\n
", markdown.convert(text) + end end end From 01edfa2dbbf395d5f646d10e15d4b1c7d86bc0ba Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Tue, 1 Apr 2014 13:19:43 -0700 Subject: [PATCH 2/3] Update README on custom filters --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 4bb492a..015956a 100644 --- a/README.md +++ b/README.md @@ -54,3 +54,9 @@ html_pipeline: Keep in mind that [filter dependencies are not bundled](https://github.com/jch/html-pipeline#dependencies), so you'll need to add these in yourself. + +## Custom filters + +Custom filters can be designed [the same as in HTML::Pipeline](https://github.com/jch/html-pipeline#extending). + +Check out [the test filter](./support/new_pipeline.rb) for an example. From bff5c450e4b4193e1a13b2167758d530d938cf27 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Tue, 1 Apr 2014 13:20:31 -0700 Subject: [PATCH 3/3] Update broken link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 015956a..ddd0e72 100644 --- a/README.md +++ b/README.md @@ -59,4 +59,4 @@ so you'll need to add these in yourself. Custom filters can be designed [the same as in HTML::Pipeline](https://github.com/jch/html-pipeline#extending). -Check out [the test filter](./support/new_pipeline.rb) for an example. +Check out [the test filter](./test/support/new_pipeline.rb) for an example.