[DRE-commits] [ruby-org] 251/303: Simplifies determining the indent of code block.
Jérémy Bobbio
lunar at alioth.debian.org
Fri Aug 9 17:34:07 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 945d7cd0eb76e0dff9d8c4cdab179d56cf212401
Author: vonavi <ivvl82 at gmail.com>
Date: Wed Jan 30 12:41:58 2013 +0200
Simplifies determining the indent of code block.
---
lib/org-ruby/html_output_buffer.rb | 9 ++-------
lib/org-ruby/output_buffer.rb | 14 +++++++++++++-
lib/org-ruby/parser.rb | 13 -------------
3 files changed, 15 insertions(+), 21 deletions(-)
diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index a76c069..75eee18 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -13,11 +13,6 @@ module Orgmode
class HtmlOutputBuffer < OutputBuffer
- # The amount of whitespaces to be stripped at the beginning of
- # each line in code block. Each array's element corresponds to a
- # code block.
- attr_accessor :code_indent_stack
-
HtmlBlockTag = {
:paragraph => "p",
:ordered_list => "ol",
@@ -326,9 +321,9 @@ module Orgmode
end
def strip_code_block!
- code_indent = @code_indent_stack.shift
- strip_regexp = Regexp.new('\n' + ' ' * code_indent)
+ strip_regexp = Regexp.new('\n' + ' ' * @code_block_indent)
@buffer.gsub!(strip_regexp, "\n")
+ @code_block_indent = nil
end
end # class HtmlOutputBuffer
end # module Orgmode
diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb
index dbc2981..a828ef3 100644
--- a/lib/org-ruby/output_buffer.rb
+++ b/lib/org-ruby/output_buffer.rb
@@ -30,6 +30,7 @@ module Orgmode
@output_type = :start
@list_indent_stack = []
@mode_stack = []
+ @code_block_indent = nil
@logger = Logger.new(STDERR)
if ENV['DEBUG'] or $DEBUG
@@ -66,7 +67,16 @@ module Orgmode
maintain_mode_stack(line)
end
add_line_attributes(line) if line.kind_of? Headline
- @output_type = line.assigned_paragraph_type || line.paragraph_type
+
+ if mode_is_code? current_mode and not line.begin_block?
+ # Determines the amount of whitespaces to be stripped at the
+ # beginning of each line in code block.
+ if @code_block_indent
+ @code_block_indent = [@code_block_indent, line.indent].min
+ else
+ @code_block_indent = line.indent
+ end
+ end
# Adds the current line to the output buffer
if preserve_whitespace? and not line.begin_block?
@@ -81,6 +91,8 @@ module Orgmode
@buffer << line.output_text.strip
end
end
+
+ @output_type = line.assigned_paragraph_type || line.paragraph_type
end
# Gets the next headline number for a given level. The intent is
diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb
index 7456d54..f3dfb2a 100644
--- a/lib/org-ruby/parser.rb
+++ b/lib/org-ruby/parser.rb
@@ -96,8 +96,6 @@ module Orgmode
@header_lines = []
@in_buffer_settings = { }
@options = { }
- @code_indent_stack = []
- @code_indent = nil
mode = :normal
previous_line = nil
table_header_set = false
@@ -118,17 +116,7 @@ module Orgmode
end
table_header_set = false if !line.table?
- if @code_indent
- @code_indent_stack.push @code_indent
- @code_indent = nil
- end
when :example, :src
- if @code_indent
- @code_indent = [@code_indent, line.indent].min
- else
- @code_indent = line.indent
- end
-
# 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
@@ -188,7 +176,6 @@ module Orgmode
export_options[:skip_tables] = true if not export_tables?
output = ""
output_buffer = HtmlOutputBuffer.new(output, export_options)
- output_buffer.code_indent_stack = @code_indent_stack
if @in_buffer_settings["TITLE"] then
--
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