[DRE-commits] [ruby-org] 126/303: Added code tags for #+BEGIN/END_SRC blocks and specify code language

Jérémy Bobbio lunar at alioth.debian.org
Fri Aug 9 17:33:41 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 1b9e838af84ce3cf0558ad2e2348a94d1aa976c3
Author: Waldemar Quevedo <waldemar.quevedo at gmail.com>
Date:   Sun Jan 15 21:21:58 2012 +0900

    Added code tags for #+BEGIN/END_SRC blocks and specify code language
---
 lib/org-ruby/html_output_buffer.rb    |    9 +++++++++
 lib/org-ruby/line.rb                  |    6 +++++-
 lib/org-ruby/output_buffer.rb         |    1 +
 spec/html_examples/advanced-code.html |   12 ++++++++++++
 spec/html_examples/advanced-code.org  |    5 +++++
 5 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index d2ae9f7..14448d1 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -59,6 +59,11 @@ module Orgmode
         css_class = " style=\"text-align: center\"" if mode == :center
         @logger.debug "#{mode}: <#{ModeTag[mode]}#{css_class}>\n" 
         @output << "<#{ModeTag[mode]}#{css_class}>\n" unless mode == :table and skip_tables?
+        # Special case to add code tags to src blogs and specify language
+        if mode == :src
+          @logger.debug "<code class=\"#{@block_lang}\">\n"
+          @output << "<code class=\"#{@block_lang}\">\n"
+        end
         # Entering a new mode obliterates the title decoration
         @title_decoration = ""
       end
@@ -71,6 +76,10 @@ module Orgmode
       m = super(mode)
       if ModeTag[m] then
         output_indentation
+        if mode == :src
+          @logger.debug "</code>\n"
+          @output << "</code>\n"
+        end
         @logger.debug "</#{ModeTag[m]}>\n"
         @output << "</#{ModeTag[m]}>\n" unless mode == :table and skip_tables?
       end
diff --git a/lib/org-ruby/line.rb b/lib/org-ruby/line.rb
index 7a16c80..6db2ad1 100644
--- a/lib/org-ruby/line.rb
+++ b/lib/org-ruby/line.rb
@@ -140,7 +140,7 @@ module Orgmode
       table_row? or table_separator? or table_header?
     end
 
-    BlockRegexp = /^\s*#\+(BEGIN|END)_(\w*)/i
+    BlockRegexp = /^\s*#\+(BEGIN|END)_(\w*)\s*(\w*)?/i
 
     def begin_block?
       @line =~ BlockRegexp && $1 =~ /BEGIN/i
@@ -154,6 +154,10 @@ module Orgmode
       $2 if @line =~ BlockRegexp
     end
 
+    def block_lang
+      $3 if @line =~ BlockRegexp
+    end
+
     def code_block_type?
       block_type =~ /^(EXAMPLE|SRC)$/i
     end
diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb
index 5f70271..aedaa59 100644
--- a/lib/org-ruby/output_buffer.rb
+++ b/lib/org-ruby/output_buffer.rb
@@ -80,6 +80,7 @@ module Orgmode
     def prepare(line)
       @logger.debug "Looking at #{line.paragraph_type}: #{line.to_s}"
       if not should_accumulate_output?(line) then
+        @block_lang = line.block_lang if line.begin_block? and line.code_block_type?
         flush!
         maintain_list_indent_stack(line)
         @output_type = line.paragraph_type 
diff --git a/spec/html_examples/advanced-code.html b/spec/html_examples/advanced-code.html
index 3395bad..da6835c 100644
--- a/spec/html_examples/advanced-code.html
+++ b/spec/html_examples/advanced-code.html
@@ -17,6 +17,7 @@
 <h1><span class="heading-number heading-number-1">2 </span>BEGIN_SRC</h1>
 <p>And this:</p>
 <pre class="src">
+<code class="ruby">
     # Finds all emphasis matches in a string.
     # Supply a block that will get the marker and body as parameters.
     def match_all(str)
@@ -24,9 +25,11 @@
         yield $2, $3
       end
     end
+</code>
 </pre>
 <p>Now let’s test case-insensitive code blocks.</p>
 <pre class="src">
+<code class="ruby">
     # Finds all emphasis matches in a string.
     # Supply a block that will get the marker and body as parameters.
     def match_all(str)
@@ -34,8 +37,10 @@
         yield $2, $3
       end
     end
+</code>
 </pre>
 <pre class="src">
+<code class="clojure">
 (def fib-seq
   (concat
    [0 1]
@@ -44,4 +49,11 @@
  
 user> (take 20 fib-seq)
 (0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181)
+</code>
+</pre>
+<p>Even if no language is set, it is still wrapped in code tags but class is empty.</p>
+<pre class="src">
+<code class="">
+echo 'Defaults env_keeps="http_proxy https_proxy ftp_proxy"' | sudo tee -a /etc/sudoers
+</code>
 </pre>
diff --git a/spec/html_examples/advanced-code.org b/spec/html_examples/advanced-code.org
index 9f4c51d..552f177 100644
--- a/spec/html_examples/advanced-code.org
+++ b/spec/html_examples/advanced-code.org
@@ -75,3 +75,8 @@ user> (take 20 fib-seq)
 (0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181)
 #+end_src
 
+Even if no language is set, it is still wrapped in code tags but class is empty.
+
+#+BEGIN_SRC 
+echo 'Defaults env_keeps="http_proxy https_proxy ftp_proxy"' | sudo tee -a /etc/sudoers
+#+END_SRC

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