Skip to content
Browse files

Slight code refactoring was done, which improves accumulating block c…

…ontents.
  • Loading branch information...
1 parent f4d593f commit 3922887bc1db3b06cbb998380d7cefa39afbc989 @vonavi committed Jan 4, 2013
Showing with 31 additions and 28 deletions.
  1. +4 −4 lib/org-ruby/line.rb
  2. +27 −24 lib/org-ruby/output_buffer.rb
View
8 lib/org-ruby/line.rb
@@ -262,13 +262,13 @@ def determine_major_mode
:table
when inline_example?
:inline_example
- when (begin_block? and block_type.casecmp("QUOTE") == 0)
+ when (block_type and block_type.casecmp("QUOTE") == 0)
:blockquote
- when (begin_block? and block_type.casecmp("CENTER") == 0)
+ when (block_type and block_type.casecmp("CENTER") == 0)
:center
- when (begin_block? and block_type.casecmp("EXAMPLE") == 0)
+ when (block_type and block_type.casecmp("EXAMPLE") == 0)
:example
- when (begin_block? and block_type.casecmp("SRC") == 0)
+ when (block_type and block_type.casecmp("SRC") == 0)
:src
end
end
View
51 lib/org-ruby/output_buffer.rb
@@ -77,7 +77,7 @@ def prepare(line)
@logger.debug "Looking at #{line.paragraph_type}(#{current_mode}) : #{line.to_s}"
# We try to get the lang from #+BEGIN_SRC blocks
@block_lang = line.block_lang if line.begin_block?
- if not should_accumulate_output?(line)
+ unless should_accumulate_output?(line)
flush!
maintain_mode_stack(line)
end
@@ -156,16 +156,15 @@ def boundary_of_block?(line)
return true if ((line.paragraph_type == :example_line) ^
(@output_type == :example_line))
# Boundary of begin...end block
- return true if (@output_type == :begin_block and
- not mode_is_code?(current_mode))
- return true if @output_type == :end_block
+ return true if (@output_type == :begin_block or
+ @output_type == :end_block)
end
def maintain_mode_stack(line)
- # Always close heading line
- pop_mode if mode_is_heading? current_mode
- # Always close paragraph mode
- pop_mode if current_mode == :paragraph
+ # Always close a heading line, paragraph and inline example
+ pop_mode if (mode_is_heading? current_mode or
+ current_mode == :paragraph or
+ current_mode == :inline_example)
if ((not line.paragraph_type == :blank) or
@output_type == :blank)
@@ -175,17 +174,14 @@ def maintain_mode_stack(line)
pop_mode
end
while ((not @list_indent_stack.empty?) and
- @list_indent_stack.last == line.indent)
- if mode_is_block? current_mode
- # Special case: Only end-block line closes the block
- pop_mode if line.end_block?
- break
- elsif current_mode != line.major_mode # item can't close its major mode
- pop_mode
- else
- break
- end
+ @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
+ (not mode_is_block? current_mode))
+ pop_mode
end
+
# Opens the major mode of line if it exists.
if line.major_mode
if (@list_indent_stack.empty? or
@@ -196,10 +192,14 @@ def maintain_mode_stack(line)
# Open tag that precedes text immediately
if (@list_indent_stack.empty? or
@list_indent_stack.last <= line.indent)
- push_mode(line.paragraph_type, line.indent) unless line.begin_block?
+ push_mode(line.paragraph_type, line.indent) unless line.block_type
+ 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
- else # If blank line, close preceding paragraph or inline example
- pop_mode if current_mode == :paragraph or current_mode == :inline_example
end
end
@@ -211,11 +211,14 @@ def output_footnotes!
# output buffer.
def should_accumulate_output?(line)
# Special case: Assign mode if not yet done.
- return false if not current_mode
+ return false unless current_mode
# Special case: Handles accumulating block content
+ if mode_is_code? current_mode
+ return true unless (line.end_block? and
+ line.major_mode == current_mode)
+ end
return false if boundary_of_block?(line)
- return true if mode_is_code?(current_mode) and not line.end_block?
# Special case: Don't accumulate headings, comments and horizontal rules.
return false if (mode_is_heading?(@output_type) or
@@ -228,7 +231,7 @@ def should_accumulate_output?(line)
if line.paragraph_type == :paragraph
# Paragraph gets accumulated only if its indent level is
# greater than the indent level of the previous mode.
- if (@mode_stack[-2] and not mode_is_block? @mode_stack[-2])
+ if @mode_stack[-2] and not mode_is_block? @mode_stack[-2]
return false if line.indent <= @list_indent_stack[-2]
end
# Special case: Multiple "paragraphs" get accumulated.

0 comments on commit 3922887

Please sign in to comment.
Something went wrong with that request. Please try again.