Class: Orgmode::HtmlOutputBuffer

Inherits:
OutputBuffer show all
Defined in:
lib/org-ruby/html_output_buffer.rb

Constant Summary collapse

HtmlBlockTag =
{
  :paragraph => "p",
  :ordered_list => "li",
  :unordered_list => "li",
  :table_row => "tr"
}
ModeTag =
{
  :unordered_list => "ul",
  :ordered_list => "ol",
  :table => "table",
  :blockquote => "blockquote",
  :code => "pre"
}

Constants inherited from OutputBuffer

OutputBuffer::Modes

Instance Attribute Summary

Attributes inherited from OutputBuffer

#buffer, #buffer_mode, #output, #output_type

Instance Method Summary collapse

Methods inherited from OutputBuffer

#<<, #current_mode, #current_mode_list?, #enter_table?, #exit_table?, #list_indent_level, #prepare, #preserve_whitespace?

Constructor Details

#initialize(output, opts = {}) ⇒ HtmlOutputBuffer

Returns a new instance of HtmlOutputBuffer.



22
23
24
25
26
27
28
29
# File 'lib/org-ruby/html_output_buffer.rb', line 22

def initialize(output, opts = {})
  super(output)
  if opts[:decorate_title] then
    @title_decoration = " class=\"title\""
  else
    @title_decoration = ""
  end
end

Instance Method Details

#flush!Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/org-ruby/html_output_buffer.rb', line 51

def flush!
  escape_buffer!
  if @buffer_mode == :code then
    # Whitespace is significant in :code mode. Always output the buffer
    # and do not do any additional translation.
    # 
    # FIXME 2009-12-29 bdewey: It looks like I'll always get an extraneous
    # newline at the start of code blocks. Find a way to fix this.
    @logger.debug "FLUSH CODE ==========> #{@buffer.inspect}"
    @output << @buffer << "\n"
  else
    if (@buffer.length > 0) then
      @logger.debug "FLUSH      ==========> #{@output_type}"
      output_indentation
      @output << "<#{HtmlBlockTag[@output_type]}#{@title_decoration}>" \
        << inline_formatting(@buffer) \
        << "</#{HtmlBlockTag[@output_type]}>\n"
      @title_decoration = ""
    end
  end
  @buffer = ""
  @buffer_mode = nil
end

#pop_mode(mode = nil) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/org-ruby/html_output_buffer.rb', line 42

def pop_mode(mode = nil)
  m = super(mode)
  if ModeTag[m] then
    output_indentation
    @logger.debug "</#{ModeTag[m]}>\n"
    @output << "</#{ModeTag[m]}>\n"
  end
end

#push_mode(mode) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/org-ruby/html_output_buffer.rb', line 31

def push_mode(mode)
  if ModeTag[mode] then
    output_indentation
    @logger.debug "<#{ModeTag[mode]}>\n" 
    @output << "<#{ModeTag[mode]}>\n" 
    # Entering a new mode obliterates the title decoration
    @title_decoration = ""
  end
  super(mode)
end