Skip to content

Commit

Permalink
Corrects Textile output.
Browse files Browse the repository at this point in the history
  • Loading branch information
vonavi committed Dec 20, 2012
1 parent 7d7a2d3 commit ffda755
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions lib/org-ruby/textile_output_buffer.rb
Expand Up @@ -6,21 +6,29 @@ class TextileOutputBuffer < OutputBuffer

def initialize(output)
super(output)
@add_paragraph = false
@add_paragraph = true
@support_definition_list = true # TODO this should be an option
@footnotes = {}
end

def push_mode(mode)
def push_mode(mode, indent)
@list_indent_stack.push(indent)
super(mode)
@output << "bc.. " if mode_is_code(mode)
@output << "\np=. " if mode == :center
@output << "bc.. " if mode_is_code? mode
if mode == :center or mode == :blockquote
@add_paragraph = false
@output << "\n"
end
true
end

def pop_mode(mode = nil)
m = super(mode)
@add_paragraph = (mode_is_code(m))
@output << "\n" if mode == :center
@list_indent_stack.pop
if m == :center or m == :blockquote
@add_paragraph = true
@output << "\n"
end
m
end

Expand Down Expand Up @@ -74,31 +82,31 @@ def output_footnotes!

# Flushes the current buffer
def flush!
@buffer = @buffer.rstrip
@logger.debug "FLUSH ==========> #{@output_type}"
if (@output_type == :blank) then
if @output_type == :blank and not preserve_whitespace?
@output << "\n"
elsif (@buffer.length > 0) then
if @add_paragraph then
@output << "p. " if @output_type == :paragraph
@add_paragraph = false
@output << "p. " if @add_paragraph and current_mode == :paragraph
if @mode_stack[0] and current_mode == :paragraph
@output << "p=. " if @mode_stack[0] == :center
@output << "bq. " if @mode_stack[0] == :blockquote
end
@output << "bq. " if current_mode == :blockquote
if @output_type == :definition_list and @support_definition_list then
@output << "-" * @list_indent_stack.length << " "
if current_mode == :definition_item and @support_definition_list
@output << "-" * @mode_stack.count(:definition_item) << " "
@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 << " "
elsif current_mode == :list_item
if @mode_stack[-2] == :ordered_list
@output << "#" * @mode_stack.count(:list_item) << " "
else # corresponds to unordered list
@output << "*" * @mode_stack.count(:list_item) << " "
end
end
if (@buffered_lines[0].kind_of?(Headline)) then
headline = @buffered_lines[0]
raise "Cannot be more than one headline!" if @buffered_lines.length > 1
@output << "h#{headline.level}. #{headline.headline_text}\n"
else
@output << inline_formatting(@buffer) << "\n"
@output << inline_formatting(@buffer)
end
end
clear_accumulation_buffer!
Expand Down

0 comments on commit ffda755

Please sign in to comment.