[DRE-commits] [ruby-org] 243/303: Refactoring of parser was done. Fixes parsing headlines within quote and center blocks.
Jérémy Bobbio
lunar at alioth.debian.org
Fri Aug 9 17:34:06 UTC 2013
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository ruby-org.
commit b93c01dcd38b13fcb43f03a5c679e01685b86817
Author: vonavi <ivvl82 at gmail.com>
Date: Mon Jan 28 02:27:18 2013 +0200
Refactoring of parser was done. Fixes parsing headlines within quote and center blocks.
---
lib/org-ruby/html_output_buffer.rb | 2 +-
lib/org-ruby/line.rb | 16 +++----
lib/org-ruby/output_buffer.rb | 4 +-
lib/org-ruby/parser.rb | 82 ++++++++++-----------------------
lib/org-ruby/textile_output_buffer.rb | 6 +--
5 files changed, 39 insertions(+), 71 deletions(-)
diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index dfdff94..d89b449 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -24,7 +24,7 @@ module Orgmode
:table => "table",
:table_row => "tr",
:table_header => "tr",
- :blockquote => "blockquote",
+ :quote => "blockquote",
:example => "pre",
:src => "pre",
:inline_example => "pre",
diff --git a/lib/org-ruby/line.rb b/lib/org-ruby/line.rb
index 135a558..5d4d9ea 100644
--- a/lib/org-ruby/line.rb
+++ b/lib/org-ruby/line.rb
@@ -229,14 +229,14 @@ module Orgmode
:property_drawer_item
when metadata?
:metadata
- 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 block_type
+ case block_type.upcase
+ when "QUOTE" then :quote
+ when "CENTER" then :center
+ when "EXAMPLE" then :example
+ when "SRC" then :src
+ when "COMMENT" then :comment
+ end
when comment?
:comment
when table_separator?
diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb
index c67e0d3..302156d 100644
--- a/lib/org-ruby/output_buffer.rb
+++ b/lib/org-ruby/output_buffer.rb
@@ -77,7 +77,7 @@ module Orgmode
@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, :blockquote, :center, :example, :src
+ when :metadata, :table_separator, :blank, :comment, :property_drawer_item, :property_drawer_begin_block, :property_drawer_end_block, :quote, :center, :example, :src
# Nothing
else
@buffer << "\n"
@@ -131,7 +131,7 @@ module Orgmode
end
def mode_is_block?(mode)
- [:blockquote, :center, :example, :src].include? mode
+ [:quote, :center, :example, :src].include? mode
end
def mode_is_code?(mode)
diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb
index b79a251..6456691 100644
--- a/lib/org-ruby/parser.rb
+++ b/lib/org-ruby/parser.rb
@@ -102,10 +102,8 @@ module Orgmode
@lines.each do |text|
line = Line.new text, self
- case mode
- when :normal
-
- if (Headline.headline? line.line) then
+ if mode == :normal
+ if Headline.headline? line.line
@current_headline = Headline.new line.line, self, offset
@headlines << @current_headline
else
@@ -120,66 +118,38 @@ module Orgmode
end
end
table_header_set = false if !line.table?
- mode = :code if line.begin_block? and line.block_type.casecmp("EXAMPLE") == 0
- mode = :src_code if line.begin_block? and line.block_type.casecmp("SRC") == 0
- mode = :block_comment if line.begin_block? and line.block_type == "COMMENT"
+ mode = line.paragraph_type if line.begin_block?
mode = :property_drawer if line.property_drawer_begin_block?
- if (@current_headline) then
+ if @current_headline
@current_headline.body_lines << line
else
@header_lines << line
end
end
- when :block_comment
-
- if line.end_block? and line.block_type == "COMMENT"
- mode = :normal
- else
- line.assigned_paragraph_type = :comment
- end
-
- when :code
-
- # As long as we stay in code mode, force lines to be either blank or paragraphs.
- # Don't try to interpret structural items, like headings and tables.
- if line.end_block? and line.code_block?
- mode = :normal
- else
- line.assigned_paragraph_type = :paragraph unless line.blank?
- end
- if (@current_headline) then
- @current_headline.body_lines << line
- else
- @header_lines << line
- end
-
- when :src_code
-
- if line.end_block? and line.code_block?
- mode = :normal
- else
- line.assigned_paragraph_type = :src
- end
- if (@current_headline) then
- @current_headline.body_lines << line
- else
- @header_lines << line
+ else
+ mode = :normal if line.end_block? and mode == line.paragraph_type
+ mode = :normal if line.property_drawer_end_block? and mode == :property_drawer
+
+ case mode
+ when :example, :src
+ # As long as we stay in code mode, force lines to be paragraphs.
+ # Don't try to interpret structural items, like headings and tables.
+ line.assigned_paragraph_type = :paragraph
+ when :quote, :center
+ if Headline.headline? line.line
+ line = Headline.new line.line, self, offset
+ end
end
- when :property_drawer
-
- if line.property_drawer_end_block?
- mode = :normal
- else
- line.assigned_paragraph_type = :property_drawer unless line.blank?
- end
- if (@current_headline) then
- @current_headline.body_lines << line
- else
- @header_lines << line
+ unless mode == :comment
+ if @current_headline
+ @current_headline.body_lines << line
+ else
+ @header_lines << line
+ end
end
- end # case
+ end
previous_line = line
end # @lines.each
@@ -252,9 +222,7 @@ module Orgmode
# Writes the output to +output_buffer+.
def self.translate(lines, output_buffer)
output_buffer.output_type = :start
- lines.each do |line|
- output_buffer.insert(line)
- end
+ lines.each { |line| output_buffer.insert(line) }
output_buffer.flush!
output_buffer.pop_mode while output_buffer.current_mode
output_buffer.output_footnotes!
diff --git a/lib/org-ruby/textile_output_buffer.rb b/lib/org-ruby/textile_output_buffer.rb
index 666c990..871a68c 100644
--- a/lib/org-ruby/textile_output_buffer.rb
+++ b/lib/org-ruby/textile_output_buffer.rb
@@ -15,7 +15,7 @@ module Orgmode
@list_indent_stack.push(indent)
super(mode)
@output << "bc. " if mode_is_code? mode
- if mode == :center or mode == :blockquote
+ if mode == :center or mode == :quote
@add_paragraph = false
@output << "\n"
end
@@ -24,7 +24,7 @@ module Orgmode
def pop_mode(mode = nil)
m = super(mode)
@list_indent_stack.pop
- if m == :center or m == :blockquote
+ if m == :center or m == :quote
@add_paragraph = true
@output << "\n"
end
@@ -98,7 +98,7 @@ module Orgmode
when current_mode == :paragraph
@output << "p. " if @add_paragraph
@output << "p=. " if @mode_stack[0] == :center
- @output << "bq. " if @mode_stack[0] == :blockquote
+ @output << "bq. " if @mode_stack[0] == :quote
when current_mode == :list_item
if @mode_stack[-2] == :ordered_list
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-org.git
More information about the Pkg-ruby-extras-commits
mailing list