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.
- checksums.yaml +4 -4
- data/lib/jekyll/embed/content.rb +16 -13
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5ec0df3dfa0876c1bdd5288ee70e5c7466dddb1d4f592339ee8855ee8b0d680
|
4
|
+
data.tar.gz: 12936601d35523b31d85233c53c9663834012af1631f07155a550d89e9e99af4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81cf85b599fbf906e97cdf613a72491b00201c3ee5146d5dc79b9905c653e0129ccfde210ba64575c9e354df8e9f4c52345e88771e6ef4b58d4255a01a140878
|
7
|
+
data.tar.gz: ccefa67e84ec9d2f24a3b1cba04dfb2cc285726b48528a486f468b50e335bd6902d07f3b2be016c4527a2f9e5d2cb69ebb9f60ff988974911e4da8989f60133a
|
data/lib/jekyll/embed/content.rb
CHANGED
@@ -1,27 +1,30 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
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
|
35
|
+
post.content = Jekyll::Embed::Content.embed post.content
|
33
36
|
end
|