Module: MaRuKu::Out::HTML

Defined in:
lib/ramaze/contrib/maruku_uv.rb

Instance Method Summary collapse

Instance Method Details

#to_html_codeObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ramaze/contrib/maruku_uv.rb', line 34

def to_html_code
  source = self.raw_code
  use_syntax = get_setting(:html_use_syntax)
  uv_style = get_setting(:uv_style)

  lang = self.attributes[:lang] || @doc.attributes[:code_lang]
  lang ||= 'ruby' if attributes[:ruby]

  # we always use syntax highlighting, this is a doc wiki
  if lang and use_syntax
    element = uv_highlight(source, lang, uv_style)
  else
    element = to_html_code_using_pre(source)
  end

  color = get_setting(:code_background_color)

  if color != Globals[:code_background_color]
    element.attributes['style'] = "background-color: #{color};"
  end

  add_ws element
end

#uv_highlight(source, lang, style) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ramaze/contrib/maruku_uv.rb', line 13

def uv_highlight(source, lang, style)
  require 'uv'

  html = Uv.parse(source, 'xhtml', lang, lines = false, style)

  # Prepare <code> containing <pre>
  code = Document.new(html, :respect_whitespace => :all).root
  code.name = 'code'
  code.attributes['class'] = lang
  code.attributes['lang'] = lang

  # Prepare <pre>
  pre = Element.new('pre')
  pre << code
  pre.attributes['class'] = style
  pre
rescue => ex
  puts ex
  to_html_code_using_pre(source)
end