jekyll-embed-urls 0.5.8 → 0.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll/embed/content.rb +16 -13
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28bf483423f9197271caae346deae52aa1d4b34c229dc723f58624c52f63e4d3
4
- data.tar.gz: bffb7fa7898714d8eee3284f35ead0819cecca5359fa0557ef1353c1fb322fe2
3
+ metadata.gz: e5ec0df3dfa0876c1bdd5288ee70e5c7466dddb1d4f592339ee8855ee8b0d680
4
+ data.tar.gz: 12936601d35523b31d85233c53c9663834012af1631f07155a550d89e9e99af4
5
5
  SHA512:
6
- metadata.gz: 143344abdd6ef63b5b8133a85697bf3aae0a64679773786a0e9fb96a26f77846abd202234169bed24f810eaf7018d96a6003897fc485d7a15f0af2ace773b589
7
- data.tar.gz: fd6f00caec463617d2ce6dc0298db823f324708a5c4770725cc6391e9879fefa65bfc6c585d400652ada0feea838038ffefe73982da7795f3218ed920a2a61bf
6
+ metadata.gz: 81cf85b599fbf906e97cdf613a72491b00201c3ee5146d5dc79b9905c653e0129ccfde210ba64575c9e354df8e9f4c52345e88771e6ef4b58d4255a01a140878
7
+ data.tar.gz: ccefa67e84ec9d2f24a3b1cba04dfb2cc285726b48528a486f468b50e335bd6902d07f3b2be016c4527a2f9e5d2cb69ebb9f60ff988974911e4da8989f60133a
@@ -1,27 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'cgi'
3
+ require 'nokogiri'
4
4
 
5
5
  module Jekyll
6
6
  class Embed
7
7
  class Content
8
- URL_RE = %r{(<p[^>]*>[\s\n]*(<a[^>]*>)?[\s\n]*(https?://[^<\s\n]+)[\s\n]*(</a>)?[\s\n]*</p>)}m.freeze
9
-
10
8
  class << self
11
9
  # Find URLs on paragraphs. We do it after rendering because
12
10
  # sometimes we use HTML instead of pure Markdown and this way we
13
11
  # catch both.
14
- def embed!(content)
15
- content.gsub!(URL_RE) do |match|
16
- url = CGI.unescapeHTML(Regexp.last_match(3))
17
- embed = Jekyll::Embed.embed url
12
+ #
13
+ # @param :content [String]
14
+ # @return [String]
15
+ def embed(content)
16
+ Nokogiri::HTML5.fragment(content).tap do |html|
17
+ html.css('p > a:first-of-type').each do |a|
18
+ next if a.parent.children.last == a
19
+
20
+ url = a['href']
21
+ embed = Jekyll::Embed.embed url
22
+
23
+ next if url == embed
18
24
 
19
- if embed == url
20
- match
21
- else
22
- embed
25
+ a.parent.replace embed
23
26
  end
24
- end
27
+ end.to_s
25
28
  end
26
29
  end
27
30
  end
@@ -29,5 +32,5 @@ module Jekyll
29
32
  end
30
33
 
31
34
  Jekyll::Hooks.register :posts, :post_convert do |post|
32
- Jekyll::Embed::Content.embed! post.content
35
+ post.content = Jekyll::Embed::Content.embed post.content
33
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-embed-urls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.8
4
+ version: 0.5.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - f