[DRE-commits] [ruby-org] 196/303: Produce Textile and HTML outputs keeping newlines. RegexpHelper is modified, now it works better.

Jérémy Bobbio lunar at alioth.debian.org
Fri Aug 9 17:33:56 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 da2173c8165496a5f7eb82b0bd717850f21e995a
Author: vonavi <ivvl82 at gmail.com>
Date:   Sat Nov 3 01:42:52 2012 +0200

    Produce Textile and HTML outputs keeping newlines. RegexpHelper is modified, now it works better.
---
 lib/org-ruby/html_output_buffer.rb    |    9 +++++----
 lib/org-ruby/parser.rb                |   10 +++-------
 lib/org-ruby/regexp_helper.rb         |   19 ++++++++++---------
 lib/org-ruby/textile_output_buffer.rb |    1 +
 4 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index 895db63..2340ca0 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -88,7 +88,7 @@ module Orgmode
         # Need to close the floating li elements before closing the list
         if (m == :unordered_list or
             m == :ordered_list or
-            m == :definition_list) and 
+            m == :definition_list) and
             (not @unclosed_tags.empty?)
           close_floating_li_tags
         end
@@ -105,6 +105,7 @@ module Orgmode
     end
 
     def flush!
+      @buffer = @buffer.rstrip
       if buffer_mode_is_src_block?
 
         # Only try to colorize #+BEGIN_SRC blocks with a specified language,
@@ -166,7 +167,7 @@ module Orgmode
           unless buffer_mode_is_table? and skip_tables?
             @logger.debug "FLUSH      ==========> #{@buffer_mode}"
             output_indentation
-            if ((@buffered_lines[0].plain_list?) and 
+            if ((@buffered_lines[0].plain_list?) and
                 (@unclosed_tags.count == @list_indent_stack.count))
               @output << @unclosed_tags.pop
               output_indentation
@@ -189,9 +190,9 @@ module Orgmode
 
             # Only close the list when it is the last element from that list,
             # or when starting another list
-            if (@output_type == :unordered_list or 
+            if (@output_type == :unordered_list or
                 @output_type == :ordered_list   or
-                @output_type == :definition_list) and 
+                @output_type == :definition_list) and
                 (not @list_indent_stack.empty?)
               @unclosed_tags.push("</#{HtmlBlockTag[@output_type]}>\n")
               @output << "\n"
diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb
index 47cd5cd..312300d 100644
--- a/lib/org-ruby/parser.rb
+++ b/lib/org-ruby/parser.rb
@@ -278,23 +278,19 @@ module Orgmode
 
           output_buffer << line.line.lstrip
 
-        when :unordered_list, :ordered_list, :definition_list
+        when :unordered_list, :ordered_list, :definition_list, :src
 
-          output_buffer << line.output_text << " "
+          output_buffer << line.output_text << "\n"
 
         when :inline_example
 
           output_buffer << line.output_text
 
-        when :src
-
-          output_buffer << line.output_text << "\n"
-
         else
           if output_buffer.preserve_whitespace? then
             output_buffer << line.output_text
           else
-            output_buffer << line.output_text.strip << " "
+            output_buffer << line.output_text.strip << "\n"
           end
         end
       end
diff --git a/lib/org-ruby/regexp_helper.rb b/lib/org-ruby/regexp_helper.rb
index 3bfc6fa..135c90e 100644
--- a/lib/org-ruby/regexp_helper.rb
+++ b/lib/org-ruby/regexp_helper.rb
@@ -39,13 +39,11 @@ module Orgmode
     # body-regexp  A regexp like \".\" to match a body character.  Don't use
     #              non-shy groups here, and don't allow newline here.
     # newline      The maximum number of newlines allowed in an emphasis exp.
-    #
-    # I currently don't use +newline+ because I've thrown this information
-    # away by this point in the code. TODO -- revisit?
     attr_reader   :pre_emphasis
     attr_reader   :post_emphasis
     attr_reader   :border_forbidden
     attr_reader   :body_regexp
+    attr_reader   :max_newlines
     attr_reader   :markers
 
     attr_reader   :org_emphasis_regexp
@@ -56,6 +54,9 @@ module Orgmode
       @post_emphasis = "- \t\\.,:!\\?;'\"\\)\\}\\\\"
       @border_forbidden = " \t\r\n,\"'"
       @body_regexp = ".*?"
+      @max_newlines = 1
+      @body_regexp = "#{@body_regexp}" +
+                     "(?:\n#{@body_regexp}){0,#{@max_newlines}}" if @max_newlines > 0
       @markers = "\\*\\/_=~\\+"
       @logger = Logger.new(STDERR)
       @logger.level = Logger::WARN
@@ -160,12 +161,12 @@ module Orgmode
     private
 
     def build_org_emphasis_regexp
-      @org_emphasis_regexp = Regexp.new("([#{@pre_emphasis}]|^)\n" +
-                                        "( [#{@markers}] ) (?!\\2)\n" +
-                                        "( [^#{@border_forbidden}] | " +
-                                        "[^#{@border_forbidden}]#{@body_regexp}[^#{@border_forbidden}] )\n" +
-                                        "\\2\n" +
-                                        "(?=[#{@post_emphasis}]|$)\n", Regexp::EXTENDED)
+      @org_emphasis_regexp = Regexp.new("([#{@pre_emphasis}]|^)" +
+                                        "([#{@markers}])(?!\\2)" +
+                                        "([^#{@border_forbidden}]|" +
+                                        "[^#{@border_forbidden}]#{@body_regexp}" +
+                                        "[^#{@border_forbidden}])\\2" +
+                                        "(?=[#{@post_emphasis}]|$)")
       @logger.debug "Just created regexp: #{@org_emphasis_regexp}"
     end
 
diff --git a/lib/org-ruby/textile_output_buffer.rb b/lib/org-ruby/textile_output_buffer.rb
index e11688d..3ee8c44 100644
--- a/lib/org-ruby/textile_output_buffer.rb
+++ b/lib/org-ruby/textile_output_buffer.rb
@@ -74,6 +74,7 @@ module Orgmode
 
     # Flushes the current buffer
     def flush!
+      @buffer = @buffer.rstrip
       @logger.debug "FLUSH ==========> #{@output_type}"
       if (@output_type == :blank) then
         @output << "\n"

-- 
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