Class: Markdoc::Renderer

Inherits:
Redcarpet::Render::HTML
  • Object
show all
Defined in:
lib/markdoc/renderer.rb

Instance Method Summary collapse

Instance Method Details

#block_code(code, language) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/markdoc/renderer.rb', line 7

def block_code(code, language)
  case language
  when 'pseudo', 'pseudocode'
    wrap_svg Pseudocode.draw(code)
  when 'seq', 'sequence'
    wrap_svg Sequence.draw(code)
  else
    Pygments.highlight(code, lexer: language)
  end
end


43
44
45
# File 'lib/markdoc/renderer.rb', line 43

def doc_footer
  "</body>\n</html>"
end

#doc_headerObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/markdoc/renderer.rb', line 28

def doc_header
  <<-END
<html>
<head>
  <title>Doc</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <style>
#{IO.read File.expand_path('../../../css/style.css', __FILE__)}
#{IO.read File.expand_path('../../../css/pygments.css', __FILE__)}
  </style>
</head>
<body>
END
end

#wrap_svg(source) ⇒ Object

removes xml or doctype meta info



19
20
21
22
23
24
25
26
# File 'lib/markdoc/renderer.rb', line 19

def wrap_svg(source)
  stripped = source.
             sub(/<\?xml[^>]+>/i, '').
             sub(/<!DOCTYPE[^>]+>/im, '').
             gsub(/<!\-\-[^>]+\-\->/, '')

  %Q(<div class="svg-holder">\n#{stripped}\n</div>)
end