[DRE-commits] [ruby-org] 246/303: Proper indentation of code blocks done.
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 a4c354d2dd13647a14b8e36dc79a63ffa02a1fda
Author: vonavi <ivvl82 at gmail.com>
Date: Wed Jan 30 00:39:27 2013 +0200
Proper indentation of code blocks done.
---
lib/org-ruby/html_output_buffer.rb | 19 ++++++++++++++++---
lib/org-ruby/parser.rb | 14 ++++++++++++++
2 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index 7b69e74..e55cad1 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -13,6 +13,11 @@ 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",
@@ -105,12 +110,14 @@ module Orgmode
def flush!
case
when preserve_whitespace?
+ strip_code_block if mode_is_code? current_mode
+
# NOTE: CodeRay and Pygments already escape the html once, so
# no need to escape_buffer!
case
when (current_mode == :src and defined? Pygments)
- lang = normalize_lang(@block_lang)
- @output << "\n"
+ lang = normalize_lang @block_lang
+ @output << "\n" unless @new_paragraph == :start
begin
@buffer = Pygments.highlight(@buffer, :lexer => lang)
@@ -119,7 +126,7 @@ module Orgmode
@buffer = Pygments.highlight(@buffer, :lexer => 'text')
end
when (current_mode == :src and defined? CodeRay)
- lang = normalize_lang(@block_lang)
+ lang = normalize_lang @block_lang
# CodeRay might throw a warning when unsupported lang is set,
# then fallback to using the text lexer
@@ -317,5 +324,11 @@ module Orgmode
ensure
$VERBOSE = warn_level
end
+
+ def strip_code_block
+ code_indent = @code_indent_stack.shift
+ strip_regexp = Regexp.new('\n' + ' ' * code_indent)
+ @buffer.gsub!(strip_regexp, "\n")
+ end
end # class HtmlOutputBuffer
end # module Orgmode
diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb
index 3a268a3..582e4b6 100644
--- a/lib/org-ruby/parser.rb
+++ b/lib/org-ruby/parser.rb
@@ -96,6 +96,8 @@ module Orgmode
@header_lines = []
@in_buffer_settings = { }
@options = { }
+ @code_indent_stack = []
+ @code_indent = nil
mode = :normal
previous_line = nil
table_header_set = false
@@ -115,7 +117,18 @@ module Orgmode
end
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
@@ -175,6 +188,7 @@ 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