[DRE-commits] [ruby-org] 274/303: Support of HTML source blocks.

Jérémy Bobbio lunar at alioth.debian.org
Fri Aug 9 17:34:12 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 efe8132438ca148baf883ed6d4b5f7c1104f551c
Author: vonavi <ivvl82 at gmail.com>
Date:   Sun Feb 3 23:47:41 2013 +0200

    Support of HTML source blocks.
---
 lib/org-ruby/html_output_buffer.rb    |   11 +++++-----
 lib/org-ruby/line.rb                  |   14 +------------
 lib/org-ruby/output_buffer.rb         |   37 ++++++++++++++++-----------------
 lib/org-ruby/parser.rb                |    2 +-
 lib/org-ruby/textile_output_buffer.rb |   11 +++++-----
 spec/html_examples/raw-html.html      |   14 +++++++------
 spec/html_examples/raw-html.org       |    2 +-
 7 files changed, 40 insertions(+), 51 deletions(-)

diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index f8321aa..7c40306 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -104,6 +104,7 @@ module Orgmode
     end
 
     def flush!
+      return false if @buffer.empty?
       case
       when preserve_whitespace?
         strip_code_block! if mode_is_code? current_mode
@@ -133,6 +134,9 @@ module Orgmode
               @buffer = CodeRay.scan(@buffer, 'text').html(:wrap => nil, :css => :style)
             end
           end
+        when (current_mode == :html or current_mode == :raw_text)
+          @buffer.gsub!(/\A\n/, "") if @new_paragraph == :start
+          @new_paragraph = true
         else
           escape_buffer!
         end
@@ -145,12 +149,7 @@ module Orgmode
       when (mode_is_table? current_mode and skip_tables?)
         @logger.debug "SKIP       ==========> #{current_mode}"
 
-      when (current_mode == :raw_text and @buffer.length > 0)
-        @buffer.gsub!(/\A\n/, "") if @new_paragraph == :start
-        @new_paragraph = true
-        @output << @buffer
-
-      when @buffer.length > 0
+      else
         @buffer.lstrip!
         escape_buffer!
         @new_paragraph = nil
diff --git a/lib/org-ruby/line.rb b/lib/org-ruby/line.rb
index 96c376d..997fba9 100644
--- a/lib/org-ruby/line.rb
+++ b/lib/org-ruby/line.rb
@@ -177,10 +177,6 @@ module Orgmode
       block_type =~ /^(EXAMPLE|SRC)$/i
     end
 
-    def code_block_line?
-      @assigned_paragraph_type == :src
-    end
-
     InlineExampleRegexp = /^\s*:\s/
 
     # Test if the line matches the "inline example" case:
@@ -231,8 +227,6 @@ module Orgmode
       case
       when blank?
         :blank
-      when code_block_line? # Do not try to guess the type of this line if it is accumulating source code
-        :src
       when definition_list? # order is important! A definition_list is also an unordered_list!
         :definition_term
       when (ordered_list? or unordered_list?)
@@ -246,13 +240,7 @@ module Orgmode
       when metadata?
         :metadata
       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
+        block_type.downcase.to_sym
       when raw_text? # order is important! Raw text can be also a comment
         :raw_text
       when comment?
diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb
index f6afa1b..1115614 100644
--- a/lib/org-ruby/output_buffer.rb
+++ b/lib/org-ruby/output_buffer.rb
@@ -66,9 +66,24 @@ module Orgmode
         flush!
         maintain_mode_stack(line)
       end
-      add_line_attributes(line) if line.kind_of? Headline
 
-      if mode_is_code? current_mode and not line.begin_block?
+      # Adds the current line to the output buffer
+      case
+      when line.raw_text?
+        @buffer << "\n" << line.output_text if line.raw_text_tag == @buffer_tag
+      when preserve_whitespace?
+        @buffer << "\n" << line.output_text unless line.block_type
+      when (line.kind_of? Headline)
+        add_line_attributes line
+        @buffer << "\n" << line.output_text
+      when ([:definition_term, :list_item, :table_row, :table_header,
+             :horizontal_rule, :paragraph].include? line.paragraph_type)
+        @buffer << "\n"
+        buffer_indentation
+        @buffer << line.output_text.strip
+      end
+
+      if mode_is_code? current_mode and not line.block_type
         # Determines the amount of whitespaces to be stripped at the
         # beginning of each line in code block.
         if @code_block_indent
@@ -78,22 +93,6 @@ module Orgmode
         end
       end
 
-      # Adds the current line to the output buffer
-      if preserve_whitespace? and not line.begin_block?
-        @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, :quote, :center, :example, :src
-          # Nothing
-        when :raw_text
-          @buffer << "\n" << line.output_text if line.raw_text_tag == @buffer_tag
-        else
-          @buffer << "\n"
-          buffer_indentation
-          @buffer << line.output_text.strip
-        end
-      end
-
       @output_type = line.assigned_paragraph_type || line.paragraph_type
     end
 
@@ -120,7 +119,7 @@ module Orgmode
 
     # Test if we're in an output mode in which whitespace is significant.
     def preserve_whitespace?
-      mode_is_code? current_mode or current_mode == :inline_example
+      [:example, :html, :inline_example, :raw_text, :src].include? current_mode
     end
 
     ######################################################################
diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb
index f3dfb2a..ea24ad8 100644
--- a/lib/org-ruby/parser.rb
+++ b/lib/org-ruby/parser.rb
@@ -116,7 +116,7 @@ module Orgmode
           end
           table_header_set = false if !line.table?
 
-        when :example, :src
+        when :example, :src, :html
           # 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
diff --git a/lib/org-ruby/textile_output_buffer.rb b/lib/org-ruby/textile_output_buffer.rb
index 37024ac..d3ff95b 100644
--- a/lib/org-ruby/textile_output_buffer.rb
+++ b/lib/org-ruby/textile_output_buffer.rb
@@ -68,7 +68,7 @@ module Orgmode
           footnote[:definition] = definition if definition and not footnote[:definition]
         else
           # There is no footnote with the current name so we add it
-          footnote = { :name => name, :definition => definition } 
+          footnote = { :name => name, :definition => definition }
           @footnotes << footnote
         end
 
@@ -92,6 +92,7 @@ module Orgmode
 
     # Flushes the current buffer
     def flush!
+      return false if @buffer.empty? and @output_type != :blank
       @logger.debug "FLUSH ==========> #{@output_type}"
       @buffer.gsub!(/\A\n*/, "")
 
@@ -99,7 +100,10 @@ module Orgmode
       when preserve_whitespace?
         @output << @buffer << "\n"
 
-      when @buffer.length > 0
+      when @output_type == :blank
+        @output << "\n"
+
+      else
         case current_mode
         when :paragraph
           @output << "p. " if @add_paragraph
@@ -120,9 +124,6 @@ module Orgmode
           end
         end
         @output << inline_formatting(@buffer) << "\n"
-
-      when @output_type == :blank
-        @output << "\n"
       end
       @buffer = ""
     end
diff --git a/spec/html_examples/raw-html.html b/spec/html_examples/raw-html.html
index 1c97d11..37de4e6 100644
--- a/spec/html_examples/raw-html.html
+++ b/spec/html_examples/raw-html.html
@@ -4,9 +4,11 @@
 <p>And this will render some Javascript:</p>
 <script> alert('hello') </script>
 <h2>HTML blocks</h2>
-<p>Unsupported for now, they behave as follows:</p>#+begin_html
-  <p><p style=”color:#cafe12; background-color:#999999”>
-    <pre></p>
-  <p>Hello.</p>
-  <p></pre>
-    </p></p>#+end_html
+<p>They behave as follows:</p>
+<p style="color:#cafe12; background-color:#999999">
+<pre>
+
+Hello.
+
+</pre>
+</p>
diff --git a/spec/html_examples/raw-html.org b/spec/html_examples/raw-html.org
index 4a9332f..8abc3ad 100644
--- a/spec/html_examples/raw-html.org
+++ b/spec/html_examples/raw-html.org
@@ -10,7 +10,7 @@ And this will render some Javascript:
 
 ** HTML blocks
 
-Unsupported for now, they behave as follows:
+They behave as follows:
 
 #+begin_html
 <p style="color:#cafe12; background-color:#999999">

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