Class: Hologram::MarkdownRenderer

Inherits:
Redcarpet::Render::HTML
  • Object
show all
Defined in:
lib/hologram/markdown_renderer.rb

Direct Known Subclasses

HologramMarkdownRenderer

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ MarkdownRenderer

Returns a new instance of MarkdownRenderer.



7
8
9
10
# File 'lib/hologram/markdown_renderer.rb', line 7

def initialize(opts={})
  super(opts)
  @link_helper = opts[:link_helper]
end

Instance Method Details

#block_code(code, language) ⇒ Object



37
38
39
# File 'lib/hologram/markdown_renderer.rb', line 37

def block_code(code, language)
  BlockCodeRenderer.new(code, language).render
end

#codespan(code) ⇒ Object



29
30
31
# File 'lib/hologram/markdown_renderer.rb', line 29

def codespan(code)
  "<code class=\"#{css_class_name}\">#{html_escape(code)}</code>"
end

#css_class_nameObject



61
62
63
# File 'lib/hologram/markdown_renderer.rb', line 61

def css_class_name
  'styleguide'
end


33
34
35
# File 'lib/hologram/markdown_renderer.rb', line 33

def link(link, title, content)
  "<a class=\"#{css_class_name}\" href=\"#{link}\" title=\"#{title || link}\">#{content}</a>"
end

#list(contents, list_type) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/hologram/markdown_renderer.rb', line 12

def list(contents, list_type)
  case list_type
  when :ordered
    "<ol class=\"#{css_class_name}\">#{contents}</ol>"
  else
    "<ul class=\"#{css_class_name}\">#{contents}</ul>"
  end
end

#paragraph(text) ⇒ Object



21
22
23
# File 'lib/hologram/markdown_renderer.rb', line 21

def paragraph(text)
  "<p class=\"#{css_class_name}\">#{text}</p>"
end

#postprocess(full_document) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/hologram/markdown_renderer.rb', line 49

def postprocess(full_document)
  invalid_links = full_document.scan(/(?: \[ [\s\w]+ \]){2}/x)

  invalid_links.each do |invalid_link|
    component = /\[.+\]/.match(invalid_link)[1]
    DisplayMessage.warning("Invalid reference link - #{invalid_link}." +
                           "Presumably the component #{component} does not exist.")
  end

  full_document
end

#preprocess(full_document) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/hologram/markdown_renderer.rb', line 41

def preprocess(full_document)
  if link_helper
    link_defs + "\n" + full_document
  else
    full_document
  end
end

#table(header, body) ⇒ Object



25
26
27
# File 'lib/hologram/markdown_renderer.rb', line 25

def table(header, body)
  "<table class=\"#{css_class_name}\"> #{header} #{body} </table>"
end