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



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

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


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

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

#doc_headerObject



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

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

#wrap_svg(source) ⇒ Object

removes xml or doctype meta info



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

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

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