Module: Org::ToHtml

Defined in:
lib/org/to/html.rb

Instance Method Summary collapse

Instance Method Details

#html_headerObject

unify toc_id somwhere?



27
28
29
30
31
# File 'lib/org/to/html.rb', line 27

def html_header
  level, text = values[0].size, values[1]
  id = respond_to?(:toc_id) ? toc_id : text.gsub(/\W/, '-').squeeze('-').downcase
  Tag.new("h#{level}", text, :id => id)
end

#html_highlightObject

TODO: find a simple way of caching highlighted code from Uv,

gives us much more possibilities in highlighting compared
to coderay, but is also _really_ slow.


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/org/to/html.rb', line 40

def html_highlight
  language, code = *values
  require 'coderay'
  language = 'nitro_xhtml' if language == 'ezamar'

  case language
  when *%w[ruby c delphi html nitro_xhtml plaintext rhtml xml]
    tokens = CodeRay.scan(code, language)
    html = tokens.html(:wrap => :div)
  when *%w[diff]
    require 'uv'
    Uv.parse(code, output = 'xhtml', syntax_name = language, line_numbers = false, render_style = 'amy', headers = false)
  else
    code = language if not code or code.strip.empty?
    html = tag(:pre, code)
  end
end

#html_spaceObject



33
34
35
# File 'lib/org/to/html.rb', line 33

def html_space
  ' '
end

#html_textObject



22
23
24
# File 'lib/org/to/html.rb', line 22

def html_text
  Org.escape_html(values.join)
end

#tag(*args) ⇒ Object



58
59
60
# File 'lib/org/to/html.rb', line 58

def tag(*args)
  Tag.new(*args)
end

#to_htmlObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/org/to/html.rb', line 10

def to_html
  method = "html_#{@name}"

  if respond_to?(method)
    send(method)
  elsif @childs.empty?
    Tag.new(name, values)
  else
    Tag.new(name, values){ @childs.map{|c| c.to_html }.join }
  end
end