Permalink
Browse files

No major mode is needed for blocks from now, block contents is accumu…

…lated much carefully.
  • Loading branch information...
1 parent 25bbe22 commit f596ca1bcb6e4f106021710bb171cfe9a0027315 @vonavi committed Jan 11, 2013
Showing with 36 additions and 42 deletions.
  1. +8 −12 lib/org-ruby/line.rb
  2. +27 −29 lib/org-ruby/output_buffer.rb
  3. +1 −1 lib/org-ruby/parser.rb
View
@@ -229,10 +229,14 @@ def determine_paragraph_type
:property_drawer_item
when metadata?
:metadata
- when begin_block?
- :begin_block
- when end_block?
- :end_block
+ when (block_type and block_type.casecmp("QUOTE") == 0)
+ :blockquote
+ when (block_type and block_type.casecmp("CENTER") == 0)
+ :center
+ when (block_type and block_type.casecmp("EXAMPLE") == 0)
+ :example
+ when (block_type and block_type.casecmp("SRC") == 0)
+ :src
when comment?
:comment
when table_separator?
@@ -260,14 +264,6 @@ def determine_major_mode
:unordered_list
when table?
:table
- when (block_type and block_type.casecmp("QUOTE") == 0)
- :blockquote
- when (block_type and block_type.casecmp("CENTER") == 0)
- :center
- when (block_type and block_type.casecmp("EXAMPLE") == 0)
- :example
- when (block_type and block_type.casecmp("SRC") == 0)
- :src
end
end
@@ -156,8 +156,7 @@ def boundary_of_block?(line)
return true if ((line.paragraph_type == :inline_example) ^
(@output_type == :inline_example))
# Boundary of begin...end block
- return true if (@output_type == :begin_block or
- @output_type == :end_block)
+ return true if mode_is_block? @output_type
end
def maintain_mode_stack(line)
@@ -166,44 +165,43 @@ def maintain_mode_stack(line)
current_mode == :paragraph or
current_mode == :inline_example)
+ # End-block line closes every mode within block
+ if line.end_block? and @mode_stack.include? line.paragraph_type
+ pop_mode until current_mode == line.paragraph_type
+ end
+
if ((not line.paragraph_type == :blank) or
@output_type == :blank)
# Close previous tags on demand. Two blank lines close all tags.
while ((not @list_indent_stack.empty?) and
- @list_indent_stack.last > line.indent)
- pop_mode
- end
- while ((not @list_indent_stack.empty?) and
- @list_indent_stack.last == line.indent and
- # item can't close its major mode
- line.major_mode != current_mode and
- # don't allow an arbitrary line to close block
+ @list_indent_stack.last >= line.indent and
+ # Don't allow an arbitrary line to close block
(not mode_is_block? current_mode))
- pop_mode
+ # Item can't close its major mode
+ if (@list_indent_stack.last == line.indent and
+ line.major_mode == current_mode)
+ break
+ else
+ pop_mode
+ end
end
end
+ # Special case: Only end-block line closes block
+ pop_mode if line.end_block? and line.paragraph_type == current_mode
+
unless line.paragraph_type == :blank
- # Opens the major mode of line if it exists.
- if line.major_mode
- if (@list_indent_stack.empty? or
- @list_indent_stack.last < line.indent)
- push_mode(line.major_mode, line.indent)
- end
- end
- # Open tag that precedes text immediately
if (@list_indent_stack.empty? or
- @list_indent_stack.last <= line.indent)
- # Don't push intrinsic mode of a block
- push_mode(line.paragraph_type, line.indent) unless line.block_type
+ @list_indent_stack.last <= line.indent or
+ mode_is_block? current_mode)
+ # Opens the major mode of line if it exists
+ if @list_indent_stack.last != line.indent or mode_is_block? current_mode
+ push_mode(line.major_mode, line.indent) if line.major_mode
+ end
+ # Opens tag that precedes text immediately
+ push_mode(line.paragraph_type, line.indent) unless line.end_block?
end
end
-
- # Special case: Only end-block line closes the block
- if mode_is_block? current_mode
- pop_mode if (line.end_block? and
- line.major_mode == current_mode)
- end
end
def output_footnotes!
@@ -219,7 +217,7 @@ def should_accumulate_output?(line)
# Special case: Handles accumulating block content and example lines
if mode_is_code? current_mode
return true unless (line.end_block? and
- line.major_mode == current_mode)
+ line.paragraph_type == current_mode)
end
return false if boundary_of_block?(line)
return true if current_mode == :inline_example
View
@@ -259,7 +259,7 @@ def self.translate(lines, output_buffer)
output_buffer << "\n" << line.output_text
else
case line.paragraph_type
- when :metadata, :table_separator, :blank, :comment, :property_drawer_item, :property_drawer_begin_block, :property_drawer_end_block, :begin_block, :end_block
+ when :metadata, :table_separator, :blank, :comment, :property_drawer_item, :property_drawer_begin_block, :property_drawer_end_block, :blockquote, :center, :example, :src
# Nothing
else
output_buffer << "\n" << line.output_text.strip

0 comments on commit f596ca1

Please sign in to comment.