[DRE-commits] [ruby-org] 77/303: Recognizes ":" at the beginning of the line as a signal for preformatted text.

Jérémy Bobbio lunar at alioth.debian.org
Fri Aug 9 17:33:31 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 19a21fab678b380fd62474c3ff22e45f924d0b9d
Author: Brian Dewey <bdewey at gmail.com>
Date:   Wed Dec 30 20:21:23 2009 -0800

    Recognizes ":" at the beginning of the line as a signal for preformatted text.
---
 lib/org-ruby/html_output_buffer.rb |    8 +++-----
 lib/org-ruby/line.rb               |   13 +++++++++++++
 lib/org-ruby/output_buffer.rb      |    6 ++++--
 spec/line_spec.rb                  |    7 +++++++
 4 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index f74e6f2..1ece574 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -17,7 +17,8 @@ module Orgmode
       :ordered_list => "ol",
       :table => "table",
       :blockquote => "blockquote",
-      :code => "pre"
+      :code => "pre",
+      :inline_example => "pre"
     }
 
     attr_reader :options
@@ -55,12 +56,9 @@ module Orgmode
 
     def flush!
       escape_buffer!
-      if @buffer_mode == :code then
+      if (@buffer_mode == :code or @buffer_mode == :inline_example)then
         # Whitespace is significant in :code mode. Always output the buffer
         # and do not do any additional translation.
-        # 
-        # FIXME 2009-12-29 bdewey: It looks like I'll always get an extraneous
-        # newline at the start of code blocks. Find a way to fix this.
         @logger.debug "FLUSH CODE ==========> #{@buffer.inspect}"
         @output << @buffer << "\n"
       else
diff --git a/lib/org-ruby/line.rb b/lib/org-ruby/line.rb
index 0e9b37c..950d3ae 100644
--- a/lib/org-ruby/line.rb
+++ b/lib/org-ruby/line.rb
@@ -117,6 +117,14 @@ module Orgmode
       $2 if @line =~ BlockRegexp
     end
 
+    InlineExampleRegexp = /^\s*:/
+
+    # Test if the line matches the "inline example" case:
+    # the first character on the line is a colon.
+    def inline_example?
+      check_assignment_or_regexp(:inline_example, InlineExampleRegexp)
+    end
+
     InBufferSettingRegexp = /^#\+(\w+):\s*(.*)$/
 
     # call-seq:
@@ -148,6 +156,7 @@ module Orgmode
       return :table_separator if table_separator?
       return :table_row if table_row?
       return :table_header if table_header?
+      return :inline_example if inline_example?
       return :paragraph
     end
 
@@ -200,6 +209,10 @@ module Orgmode
           
           output_buffer << line.strip_unordered_list_tag << " "
 
+        when :inline_example
+
+          output_buffer << line.line.sub(InlineExampleRegexp, "")
+          
         when :paragraph
 
           if output_buffer.preserve_whitespace? then
diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb
index 826e9e1..e7130bd 100644
--- a/lib/org-ruby/output_buffer.rb
+++ b/lib/org-ruby/output_buffer.rb
@@ -45,7 +45,7 @@ module Orgmode
       push_mode(:normal)
     end
 
-    Modes = [:normal, :ordered_list, :unordered_list, :blockquote, :code, :table]
+    Modes = [:normal, :ordered_list, :unordered_list, :blockquote, :code, :table, :inline_example]
 
     def current_mode
       @mode_stack.last
@@ -75,6 +75,8 @@ module Orgmode
         maintain_list_indent_stack(line)
         @output_type = line.paragraph_type 
       end
+      push_mode(:inline_example) if line.inline_example? and current_mode != :inline_example
+      pop_mode(:inline_example) if current_mode == :inline_example && !line.inline_example?
       push_mode(:table) if enter_table?
       pop_mode(:table) if exit_table?
     end
@@ -108,7 +110,7 @@ module Orgmode
 
     # Test if we're in an output mode in which whitespace is significant.
     def preserve_whitespace?
-      return current_mode == :code
+      return current_mode == :code || current_mode == :inline_example
     end
 
     ######################################################################
diff --git a/spec/line_spec.rb b/spec/line_spec.rb
index 80f8de9..9faad61 100644
--- a/spec/line_spec.rb
+++ b/spec/line_spec.rb
@@ -24,6 +24,13 @@ describe Orgmode::Line do
     end
   end
 
+  [": inline", " :inline", "\t\t:\tinline"].each do |inline_example|
+    it "should recognize this inline example: #{inline_example}" do
+      Orgmode::Line.new(inline_example).inline_example?.should be_true
+    end
+  end
+    
+
   it "should recognize plain lists" do
     list_formats = ["-",
                     "+",

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