Class: Orgmode::TextileOutputBuffer
- Inherits:
-
OutputBuffer
- Object
- OutputBuffer
- Orgmode::TextileOutputBuffer
- Defined in:
- lib/org-ruby/textile_output_buffer.rb
Constant Summary collapse
- TextileMap =
Maps org markup to textile markup.
{ "*" => "*", "/" => "_", "_" => "_", "=" => "@", "~" => "@", "+" => "+" }
Constants inherited from OutputBuffer
Instance Attribute Summary
Attributes inherited from OutputBuffer
#buffer, #buffer_mode, #buffered_lines, #headline_number_stack, #output, #output_type
Instance Method Summary collapse
-
#flush! ⇒ Object
Flushes the current buffer.
-
#initialize(output) ⇒ TextileOutputBuffer
constructor
A new instance of TextileOutputBuffer.
-
#inline_formatting(input) ⇒ Object
Handles inline formatting for textile.
- #output_footnotes! ⇒ Object
- #pop_mode(mode = nil) ⇒ Object
- #push_mode(mode) ⇒ Object
Methods inherited from OutputBuffer
#<<, #clear_accumulation_buffer!, #current_mode, #current_mode_list?, #enter_table?, #exit_table?, #get_next_headline_number, #list_indent_level, #prepare, #preserve_whitespace?
Constructor Details
#initialize(output) ⇒ TextileOutputBuffer
Returns a new instance of TextileOutputBuffer.
7 8 9 10 11 12 |
# File 'lib/org-ruby/textile_output_buffer.rb', line 7 def initialize(output) super(output) @add_paragraph = false @support_definition_list = true # TODO this should be an option @footnotes = {} end |
Instance Method Details
#flush! ⇒ Object
Flushes the current buffer
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/org-ruby/textile_output_buffer.rb', line 76 def flush! @logger.debug "FLUSH ==========> #{@output_type}" if (@output_type == :blank) then @output << "\n" elsif (@buffer.length > 0) then if @add_paragraph then @output << "p. " if @output_type == :paragraph @add_paragraph = false end @output << "bq. " if current_mode == :blockquote if @output_type == :definition_list and @support_definition_list then @output << "-" * @list_indent_stack.length << " " @buffer.sub!("::", ":=") elsif @output_type == :ordered_list then @output << "#" * @list_indent_stack.length << " " elsif @output_type == :unordered_list or \ (@output_type == :definition_list and not @support_definition_list) then @output << "*" * @list_indent_stack.length << " " end @output << inline_formatting(@buffer) << "\n" end clear_accumulation_buffer! end |
#inline_formatting(input) ⇒ Object
Handles inline formatting for textile.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/org-ruby/textile_output_buffer.rb', line 38 def inline_formatting(input) input = @re_help.rewrite_emphasis(input) do |marker, body| m = TextileMap[marker] "#{m}#{body}#{m}" end input = @re_help.rewrite_subp(input) do |type, text| if type == "_" then "~#{text}~" elsif type == "^" then "^#{text}^" end end input = @re_help.rewrite_links(input) do |link, text| text ||= link link = link.gsub(/ /, "%20") "\"#{text}\":#{link}" end input = @re_help.rewrite_footnote(input) do |name, defi| # textile only support numerical names! Use hash as a workarround name = name.hash.to_s unless name.to_i.to_s == name # check if number @footnotes[name] = defi if defi "[#{name}]" end Orgmode.special_symbols_to_textile(input) input end |
#output_footnotes! ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/org-ruby/textile_output_buffer.rb', line 65 def output_footnotes! return false if @footnotes.empty? @footnotes.each do |name, defi| @output << "\nfn#{name}. #{defi}\n" end return true end |
#pop_mode(mode = nil) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/org-ruby/textile_output_buffer.rb', line 20 def pop_mode(mode = nil) m = super(mode) @add_paragraph = (mode_is_code(m)) @output << "\n" if mode == :center m end |
#push_mode(mode) ⇒ Object
14 15 16 17 18 |
# File 'lib/org-ruby/textile_output_buffer.rb', line 14 def push_mode(mode) super(mode) @output << "bc.. " if mode_is_code(mode) @output << "\np=. " if mode == :center end |