Class: Jekyll::Embed::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/embed/content.rb

Class Method Summary collapse

Class Method Details

.embed(content) ⇒ String

Find URLs on paragraphs. We do it after rendering because sometimes we use HTML instead of pure Markdown and this way we catch both.

Parameters:

  • :content (String)

Returns:

  • (String)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jekyll/embed/content.rb', line 15

def embed(content)
  Nokogiri::HTML5.fragment(content).tap do |html|
    html.css('p > a').each do |a|
      next unless a.parent.children.size == 1
      next unless a['href'] == a.text.strip

      embed = Jekyll::Embed.embed a['href']

      next if a['href'] == embed

      a.parent.replace embed
    end
  end.to_s
end