Class: Middleman::Renderers::MiddlemanKramdownHTML

Inherits:
Kramdown::Converter::Html
  • Object
show all
Defined in:
middleman-core/lib/middleman-core/renderers/kramdown.rb

Overview

Custom Kramdown renderer that uses our helpers for images and links

Instance Method Summary collapse

Instance Method Details

#convert_a(el, indent) ⇒ Object


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'middleman-core/lib/middleman-core/renderers/kramdown.rb', line 37

def convert_a(el, indent)
  content = inner(el, indent)

  if el.attr['href'].start_with?('mailto:')
    mail_addr = el.attr['href'].delete_prefix('mailto:')
    href = "#{obfuscate('mailto')}:#{obfuscate(mail_addr)}"
    content = obfuscate(content) if content == mail_addr
    return %(<a href="#{href}">#{content}</a>)
  end

  attr = el.attr.dup
  link = attr.delete('href')
  attr.transform_keys!(&:to_sym)

  scope.link_to(content, link, attr)
end

#convert_img(el, _) ⇒ Object


30
31
32
33
34
35
# File 'middleman-core/lib/middleman-core/renderers/kramdown.rb', line 30

def convert_img(el, _)
  attrs = el.attr.dup

  link = attrs.delete('src')
  scope.image_tag(link, attrs)
end