[DRE-commits] [ruby-org] 113/303: Added preliminar support for the property drawer from org-mode. Property drawer tags do not appear on the output now.

Jérémy Bobbio lunar at alioth.debian.org
Fri Aug 9 17:33:39 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 961bcf511bb52ef6e7ea9e7296f1801e1255dada
Author: Waldemar Quevedo <waldemar.quevedo at gmail.com>
Date:   Sat Sep 17 22:54:30 2011 +0200

    Added preliminar support for the property drawer from org-mode.
    Property drawer tags do not appear on the output now.
---
 lib/org-ruby/line.rb          |   23 +++++++++++++++++++++++
 lib/org-ruby/output_buffer.rb |    8 +++++---
 lib/org-ruby/parser.rb        |   28 +++++++++++++++++++++-------
 3 files changed, 49 insertions(+), 10 deletions(-)

diff --git a/lib/org-ruby/line.rb b/lib/org-ruby/line.rb
index 3be7a68..7a16c80 100644
--- a/lib/org-ruby/line.rb
+++ b/lib/org-ruby/line.rb
@@ -41,6 +41,26 @@ module Orgmode
       return @line =~ /^#/
     end
 
+    PropertyDrawerRegexp = /^\s*:(PROPERTIES|END):/i
+
+    def property_drawer_begin_block?
+      @line =~ PropertyDrawerRegexp && $1 =~ /PROPERTIES/
+    end
+
+    def property_drawer_end_block?
+      @line =~ PropertyDrawerRegexp && $1 =~ /END/
+    end
+
+    def property_drawer?
+      check_assignment_or_regexp(:property_drawer, PropertyDrawerRegexp)
+    end
+
+    PropertyDrawerItemRegexp = /^\s*:(\w+):\s*(.*)$/i
+
+    def property_drawer_item?
+      @line =~ PropertyDrawerItemRegexp
+    end
+
     # Tests if a line contains metadata instead of actual content.
     def metadata?
       check_assignment_or_regexp(:metadata, /^\s*(CLOCK|DEADLINE|START|CLOSED|SCHEDULED):/)
@@ -173,6 +193,9 @@ module Orgmode
       return :definition_list if definition_list? # order is important! A definition_list is also an unordered_list!
       return :ordered_list if ordered_list?
       return :unordered_list if unordered_list?
+      return :property_drawer_begin_block if property_drawer_begin_block?
+      return :property_drawer_end_block if property_drawer_end_block?
+      return :property_drawer_item if property_drawer_item?
       return :metadata if metadata?
       return :begin_block if begin_block?
       return :end_block if end_block?
diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb
index 91fd7e3..5f70271 100644
--- a/lib/org-ruby/output_buffer.rb
+++ b/lib/org-ruby/output_buffer.rb
@@ -54,7 +54,7 @@ module Orgmode
       push_mode(:normal)
     end
 
-    Modes = [:normal, :ordered_list, :unordered_list, :definition_list, :blockquote, :src, :example, :table, :inline_example, :center]
+    Modes = [:normal, :ordered_list, :unordered_list, :definition_list, :blockquote, :src, :example, :table, :inline_example, :center, :property_drawer]
 
     def current_mode
       @mode_stack.last
@@ -84,8 +84,10 @@ 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(:inline_example) if line.inline_example? and current_mode != :inline_example and not line.property_drawer?
+      pop_mode(:inline_example) if current_mode == :inline_example and !line.inline_example?
+      push_mode(:property_drawer) if line.property_drawer? and current_mode != :property_drawer
+      pop_mode(:property_drawer) if current_mode == :property_drawer and line.property_drawer_end_block?
       push_mode(:table) if enter_table?
       pop_mode(:table) if exit_table?
       @buffered_lines.push(line)
diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb
index 03b6da1..7c5a02b 100644
--- a/lib/org-ruby/parser.rb
+++ b/lib/org-ruby/parser.rb
@@ -77,7 +77,7 @@ module Orgmode
     # Should we export sub/superscripts? (_{foo}/^{foo})
     # only {} mode is currently supported.
     def use_sub_superscripts?
-      @options["^"] != "nil" 
+      @options["^"] != "nil"
     end
 
     # I can construct a parser object either with an array of lines
@@ -122,6 +122,7 @@ module Orgmode
             table_header_set = false if !line.table?
             mode = :code if line.begin_block? and line.block_type == "EXAMPLE"
             mode = :block_comment if line.begin_block? and line.block_type == "COMMENT"
+            mode = :property_drawer if line.property_drawer_begin_block?
             if (@current_headline) then
               @current_headline.body_lines << line
             else
@@ -152,6 +153,20 @@ module Orgmode
           else
             @header_lines << line
           end
+
+        when :property_drawer
+
+          line = Line.new line, self
+          if line.property_drawer_end_block?
+            mode = :normal
+          else
+            line.assigned_paragraph_type = :property_drawer unless line.blank?
+          end
+          if (@current_headline) then
+            @current_headline.body_lines << line
+          else
+            @header_lines << line
+          end
         end                     # case
         previous_line = line
       end                       # @lines.each
@@ -186,7 +201,7 @@ module Orgmode
       export_options[:skip_tables] = true if not export_tables?
       output = ""
       output_buffer = HtmlOutputBuffer.new(output, export_options)
-      
+
       if @in_buffer_settings["TITLE"] then
 
         # If we're given a new title, then just create a new line
@@ -195,7 +210,7 @@ module Orgmode
         Parser.translate([title], output_buffer)
       end
       Parser.translate(@header_lines, output_buffer) unless skip_header_lines?
-      
+
       # If we've output anything at all, remove the :decorate_title option.
       export_options.delete(:decorate_title) if (output.length > 0)
       @headlines.each do |headline|
@@ -224,11 +239,10 @@ module Orgmode
         # See if we're carrying paragraph payload, and output
         # it if we're about to switch to some other output type.
         output_buffer.prepare(line)
-
         case line.paragraph_type
-        when :metadata, :table_separator, :blank, :comment
+        when :metadata, :table_separator, :blank, :comment, :property_drawer_item, :property_drawer_begin_block, :property_drawer_end_block
 
-          output_buffer << line.line if output_buffer.preserve_whitespace?          
+          output_buffer << line.line if output_buffer.preserve_whitespace?
 
         when :begin_block
 
@@ -249,7 +263,7 @@ module Orgmode
           output_buffer << line.line.lstrip
 
         when :unordered_list, :ordered_list, :definition_list
-          
+
           output_buffer << line.output_text << " "
 
         when :inline_example

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