Class: Middleman::Renderers::MiddlemanRedcarpetHTML

Inherits:
Redcarpet::Render::HTML
  • Object
show all
Defined in:
middleman-core/lib/middleman-core/renderers/redcarpet.rb

Overview

Custom Redcarpet renderer that uses our helpers for images and links

Instance Method Summary collapse

Constructor Details

#initialize(options_hash = ::Middleman::EMPTY_HASH) ⇒ MiddlemanRedcarpetHTML

Returns a new instance of MiddlemanRedcarpetHTML.


69
70
71
72
73
# File 'middleman-core/lib/middleman-core/renderers/redcarpet.rb', line 69

def initialize(options_hash = ::Middleman::EMPTY_HASH)
  @local_options = options_hash.dup

  super
end

Instance Method Details

#image(link, title, alt_text) ⇒ Object


75
76
77
78
79
80
81
82
83
# File 'middleman-core/lib/middleman-core/renderers/redcarpet.rb', line 75

def image(link, title, alt_text)
  if !@local_options[:no_images]
    scope.image_tag(link, title: title, alt: alt_text)
  else
    link_string = link.dup
    link_string = %(#{link_string}"#{title}") if title && !title.empty? && title != alt_text
    "![#{alt_text}](#{link_string})"
  end
end

85
86
87
88
89
90
91
92
93
94
95
96
# File 'middleman-core/lib/middleman-core/renderers/redcarpet.rb', line 85

def link(link, title, content)
  if !@local_options[:no_links]
    attributes = { title: title }
    attributes.merge!(@local_options[:link_attributes]) if @local_options[:link_attributes]

    scope.link_to(content, link, attributes)
  else
    link_string = link.dup
    link_string = %(#{link_string}"#{title}") if title && !title.empty? && title != alt_text
    "[#{content}](#{link_string})"
  end
end