content-pipeline 2.0.3 → 2.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3919909e05e0f4cdbbcc88617f076a0f06c8127
4
- data.tar.gz: 67affc23cc0361c58801cd2248f683970c6a8275
3
+ metadata.gz: 0eeaf4fcd1d8905dcce06bf88638d3eefdb9d548
4
+ data.tar.gz: 489101c1a51014c37d462e86da69462bf1c06d79
5
5
  SHA512:
6
- metadata.gz: 0c497afd6bd12246459a045f2d1da2a6846a27fb454fbb8886743408762142619287e1522e5f0107a262c199d6566f200ef458995a1f60a64c906f2fd69f049b
7
- data.tar.gz: c3a3f38e8586bc23bae2e20e67ee688c9ca853f8ab715c31b4ecc32ea5361e4ea4953f2e415483df838301a3309083e32fd0285e29741d8fd3fe268ca079e819
6
+ metadata.gz: 32e5df69f9bba0c5031349775cd946b3b91beb531a7409fd0c1499a6519a0acbdb4755c3a127ec16c43adc0c2c207f78e959fb5a57fe5ff7d2e3959adf8d73d0
7
+ data.tar.gz: 3f112d569cd73a8f51a3ae0d74b5258713657ab5884c842607d2f1aaf67e7685934b442248d3bbac89acbcde987a6814b398a547d5fcd780be355b74456530eb
data/Readme.md CHANGED
@@ -95,3 +95,10 @@ The Gemoji filter allows you to convert `:gemoji:` into image tags, liquid asset
95
95
  * `:as_liquid_asset` - `nil`
96
96
  * `:tag` - `Proc` - 2args - path, name.
97
97
  * `:asset_path` - `/assets`
98
+
99
+ ### Content::Pipeline::Filters::Links
100
+
101
+ This filter will take all links and convert them to https and if they don't
102
+ match a host add `target=_blank`.
103
+
104
+ * `:host` - `nil` - Optional - Filter piece skipped if not supplied.
@@ -0,0 +1,39 @@
1
+ class Content::Pipeline::Filters::Blockquote < Content::Pipeline::Filter
2
+ XPaths = [
3
+ ".//blockquote/p[1][starts-with(text(), 'By ')]",
4
+ ".//blockquote/p[1][starts-with(text(), 'From ')]"
5
+ ]
6
+
7
+ add_filter({
8
+ :blockquotes => :nokogiri
9
+ })
10
+
11
+ def blockquotes
12
+ @str = @str.to_nokogiri_fragment
13
+ @str.xpath(XPaths.join(" | ")).each do |v|
14
+ v.replace(parse_blockquote(
15
+ v.inner_html
16
+ ))
17
+ end
18
+ end
19
+
20
+ def parse_blockquote(text)
21
+ text = text.each_line.to_a
22
+ text[0] = <<-HTML
23
+ <header class="cite">
24
+ #{text[0]}
25
+ </header>
26
+ #{
27
+ if text[1..-1].any?
28
+ <<-HTML
29
+ <p>
30
+ #{text[1..-1].join(
31
+ "\n"
32
+ )}
33
+ </p>
34
+ HTML
35
+ end
36
+ }
37
+ HTML
38
+ end
39
+ end
@@ -0,0 +1,30 @@
1
+ class Content::Pipeline::Filters::Links < Content::Pipeline::Filter
2
+ HttpRegexp = /\A(\/\/|http:\/\/)/
3
+ add_filter({
4
+ :wrapper => :nokogiri
5
+ })
6
+
7
+ def wrapper
8
+ @str = @str.to_nokogiri_fragment
9
+ @str.xpath(".//a").each do |v|
10
+ external(https(
11
+ v
12
+ ))
13
+ end
14
+ end
15
+
16
+ def external(val)
17
+ unless !@opts[:host] || val[:href] =~ \
18
+ %r!https?://#{Regexp.escape(@opts[:host])}(?:\Z|/)!
19
+ val[:target] = "_blank"
20
+ end
21
+ val
22
+ end
23
+
24
+ def https(val)
25
+ val[:href] = val[:href].gsub(
26
+ HttpRegexp, "https://"
27
+ )
28
+ val
29
+ end
30
+ end
@@ -2,20 +2,29 @@ require "content/pipeline"
2
2
 
3
3
  module Content::Pipeline::Jekyll
4
4
  class Converter < Jekyll::Converter
5
- require "content/pipeline/filters/https"
6
- require "content/pipeline/filters/gemoji"
5
+ require "content/pipeline/filters/markdown"
7
6
  require "content/pipeline/filters/code"
8
- Filters = [
7
+ require "content/pipeline/filters/gemoji"
8
+ require "content/pipeline/filters/blockquote"
9
+ require "content/pipeline/filters/links"
10
+
11
+ DefaultFilters = [
9
12
  Content::Pipeline::Filters::Markdown,
13
+
10
14
  Content::Pipeline::Filters::Code,
11
- Content::Pipeline::Filters::Https
15
+ Content::Pipeline::Filters::Gemoji,
16
+ Content::Pipeline::Filters::Blockquote,
17
+ Content::Pipeline::Filters::Links
12
18
  ]
13
19
 
14
20
  def convert(data)
15
- # Add your filters to Filters if you want them.
16
- return Content::Pipeline.new(Filters).filter(
17
- data
18
- )
21
+ return Content::Pipeline.new(DefaultFilters).filter(data, {
22
+ :links => {
23
+ :host => @config["url"].gsub(
24
+ %r!https?://!, ""
25
+ )
26
+ }
27
+ })
19
28
  end
20
29
 
21
30
  def matches(ext)
@@ -1,5 +1,5 @@
1
1
  module Content
2
2
  class Pipeline
3
- VERSION = "2.0.3"
3
+ VERSION = "2.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: content-pipeline
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordon Bedwell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-01 00:00:00.000000000 Z
11
+ date: 2015-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -94,9 +94,10 @@ files:
94
94
  - lib/content/pipeline/core_extensions/hash_ext.rb
95
95
  - lib/content/pipeline/core_extensions/object_ext.rb
96
96
  - lib/content/pipeline/filters.rb
97
+ - lib/content/pipeline/filters/blockquote.rb
97
98
  - lib/content/pipeline/filters/code.rb
98
99
  - lib/content/pipeline/filters/gemoji.rb
99
- - lib/content/pipeline/filters/https.rb
100
+ - lib/content/pipeline/filters/links.rb
100
101
  - lib/content/pipeline/filters/markdown.rb
101
102
  - lib/content/pipeline/jekyll/converter.rb
102
103
  - lib/content/pipeline/version.rb
@@ -1,15 +0,0 @@
1
- class Content::Pipeline::Filters::Https < Content::Pipeline::Filter
2
- HttpRegexp = /\A(\/\/|http:\/\/)/
3
- add_filter({
4
- :https => :nokogiri
5
- })
6
-
7
- def https
8
- @str = @str.to_nokogiri_fragment
9
- @str.xpath(".//a").select { |v| v[:href] =~ HttpRegexp }.each do |v|
10
- v[:href] = v[:href].gsub(
11
- HttpRegexp, "https://"
12
- )
13
- end
14
- end
15
- end