[DRE-commits] [ruby-org] 78/303: Added CSS tags to SRC and EXAMPLE blocks

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 aefe36786ed0d4ec31c247552eb4e6a3a758747d
Author: Brian Dewey <bdewey at gmail.com>
Date:   Wed Dec 30 21:03:58 2009 -0800

    Added CSS tags to SRC and EXAMPLE blocks
---
 lib/org-ruby/html_output_buffer.rb       |   17 +++++++---
 lib/org-ruby/line.rb                     |   10 ++++--
 lib/org-ruby/output_buffer.rb            |   16 +++++----
 lib/org-ruby/textile_output_buffer.rb    |    4 +--
 spec/html_examples/advanced-code.html    |   36 ++++++++++++++++++++
 spec/html_examples/advanced-code.org     |   53 ++++++++++++++++++++++++++++++
 spec/html_examples/block_code.html       |    4 +--
 spec/html_examples/code-comment.html     |    2 +-
 spec/html_examples/escape-pre.html       |    2 +-
 spec/html_examples/metadata-comment.html |    2 +-
 10 files changed, 126 insertions(+), 20 deletions(-)

diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index 1ece574..e31c2b1 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",
+      :example => "pre",
+      :src => "pre",
       :inline_example => "pre"
     }
 
@@ -34,17 +35,25 @@ module Orgmode
       @logger.debug "HTML export options: #{@options.inspect}"
     end
 
+    # Output buffer is entering a new mode. Use this opportunity to
+    # write out one of the block tags in the ModeTag constant to put
+    # this information in the HTML stream.
     def push_mode(mode)
       if ModeTag[mode] then
         output_indentation
-        @logger.debug "<#{ModeTag[mode]}>\n" 
-        @output << "<#{ModeTag[mode]}>\n" unless mode == :table and skip_tables?
+        css_class = ""
+        css_class = " class=\"src\"" if mode == :src
+        css_class = " class=\"example\"" if (mode == :example || mode == :inline_example)
+        @logger.debug "#{mode}: <#{ModeTag[mode]}#{css_class}>\n" 
+        @output << "<#{ModeTag[mode]}#{css_class}>\n" unless mode == :table and skip_tables?
         # Entering a new mode obliterates the title decoration
         @title_decoration = ""
       end
       super(mode)
     end
 
+    # We are leaving a mode. Close any tags that were opened when
+    # entering this mode.
     def pop_mode(mode = nil)
       m = super(mode)
       if ModeTag[m] then
@@ -56,7 +65,7 @@ module Orgmode
 
     def flush!
       escape_buffer!
-      if (@buffer_mode == :code or @buffer_mode == :inline_example)then
+      if mode_is_code(@buffer_mode) then
         # Whitespace is significant in :code mode. Always output the buffer
         # and do not do any additional translation.
         @logger.debug "FLUSH CODE ==========> #{@buffer.inspect}"
diff --git a/lib/org-ruby/line.rb b/lib/org-ruby/line.rb
index 950d3ae..7ce84d3 100644
--- a/lib/org-ruby/line.rb
+++ b/lib/org-ruby/line.rb
@@ -117,6 +117,10 @@ module Orgmode
       $2 if @line =~ BlockRegexp
     end
 
+    def code_block_type?
+      block_type =~ /^(EXAMPLE|SRC)$/
+    end
+
     InlineExampleRegexp = /^\s*:/
 
     # Test if the line matches the "inline example" case:
@@ -189,10 +193,12 @@ module Orgmode
           
           if line.begin_block?
             output_buffer.push_mode(:blockquote) if line.block_type == "QUOTE"
-            output_buffer.push_mode(:code) if line.block_type == "EXAMPLE"
+            output_buffer.push_mode(:src) if line.block_type == "SRC"
+            output_buffer.push_mode(:example) if line.block_type == "EXAMPLE"
           elsif line.end_block?
             output_buffer.pop_mode(:blockquote) if line.block_type == "QUOTE"
-            output_buffer.pop_mode(:code) if line.block_type == "EXAMPLE"
+            output_buffer.pop_mode(:src) if line.block_type == "SRC"
+            output_buffer.pop_mode(:example) if line.block_type == "EXAMPLE"
           else
             output_buffer << line.line if output_buffer.preserve_whitespace?
           end
diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb
index e7130bd..4fbd114 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, :inline_example]
+    Modes = [:normal, :ordered_list, :unordered_list, :blockquote, :src, :example, :table, :inline_example]
 
     def current_mode
       @mode_stack.last
@@ -110,17 +110,19 @@ module Orgmode
 
     # Test if we're in an output mode in which whitespace is significant.
     def preserve_whitespace?
-      return current_mode == :code || current_mode == :inline_example
+      mode_is_code current_mode
     end
 
     ######################################################################
     private
 
-    # call-seq:
-    #     continue_current_list?  => boolean
-    #
-    # Tests if the line should continue the current list.
-    def continue_current_list?(line)
+    def mode_is_code(mode)
+      case mode
+      when :src, :inline_example, :example
+        true
+      else
+        false
+      end
     end
 
     def maintain_list_indent_stack(line)
diff --git a/lib/org-ruby/textile_output_buffer.rb b/lib/org-ruby/textile_output_buffer.rb
index 9d62790..d02bcd1 100644
--- a/lib/org-ruby/textile_output_buffer.rb
+++ b/lib/org-ruby/textile_output_buffer.rb
@@ -11,12 +11,12 @@ module Orgmode
 
     def push_mode(mode)
       super(mode)
-      @output << "bc.. " if mode == :code
+      @output << "bc.. " if mode_is_code(mode)
     end
 
     def pop_mode(mode = nil)
       m = super(mode)
-      @add_paragraph = (m == :code)
+      @add_paragraph = (mode_is_code(m))
       m
     end
 
diff --git a/spec/html_examples/advanced-code.html b/spec/html_examples/advanced-code.html
new file mode 100644
index 0000000..16e8dc3
--- /dev/null
+++ b/spec/html_examples/advanced-code.html
@@ -0,0 +1,36 @@
+<p class="title">advanced-code.org</p>
+<p>Turns out there’s more way to do code than just BEGIN_EXAMPLE.</p>
+<h1><span class="heading-number heading-number-1">1 </span>Inline examples</h1>
+<p>This should work:</p>
+<pre class="example">
+   fixed width? how does this work?   
+                         ...........
+                        ............
+                                   .
+                        .  .   .   .
+                        .          ..
+                        ....... .....
+                            .  .
+                            ....
+</pre>
+<p>Two ASCII blobs.</p>
+<h1><span class="heading-number heading-number-1">2 </span>BEGIN_SRC</h1>
+<pre class="example">
+PROPERTIES:
+ARCHIVE_TIME: 2009-12-26 Sat 22:16
+ARCHIVE_FILE: ~/brians-brain/content/projects/orgmode_parser.org
+ARCHIVE_OLPATH: &lt;%= @page.title %&gt;/Future Development
+ARCHIVE_CATEGORY: orgmode_parser
+ARCHIVE_TODO: DONE
+END:
+</pre>
+<p>And this:</p>
+<pre class="src">
+    # Finds all emphasis matches in a string.
+    # Supply a block that will get the marker and body as parameters.
+    def match_all(str)
+      str.scan(@org_emphasis_regexp) do |match|
+        yield $2, $3
+      end
+    end
+</pre>
diff --git a/spec/html_examples/advanced-code.org b/spec/html_examples/advanced-code.org
new file mode 100644
index 0000000..dc685d3
--- /dev/null
+++ b/spec/html_examples/advanced-code.org
@@ -0,0 +1,53 @@
+#+TITLE:     advanced-code.org
+#+AUTHOR:    Brian Dewey
+#+EMAIL:     bdewey at gmail.com
+#+DATE:      2009-12-30 Wed
+#+DESCRIPTION: More types of code support
+#+KEYWORDS: 
+#+LANGUAGE:  en
+#+OPTIONS:   H:3 num:t toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
+#+OPTIONS:   TeX:t LaTeX:nil skip:nil d:nil todo:t pri:nil tags:not-in-toc
+#+INFOJS_OPT: view:nil toc:nil ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js
+#+EXPORT_SELECT_TAGS: export
+#+EXPORT_EXCLUDE_TAGS: noexport
+#+LINK_UP:   
+#+LINK_HOME: 
+
+Turns out there's more way to do code than just BEGIN_EXAMPLE. 
+
+* Inline examples
+
+This should work:
+
+:   fixed width? how does this work?   
+:                         ...........
+:                        ............
+:                                   .
+:                        .  .   .   .
+:                        .          ..
+:                        ....... .....
+:                            .  .
+:                            ....
+
+Two ASCII blobs.
+
+* BEGIN_SRC
+:PROPERTIES:
+:ARCHIVE_TIME: 2009-12-26 Sat 22:16
+:ARCHIVE_FILE: ~/brians-brain/content/projects/orgmode_parser.org
+:ARCHIVE_OLPATH: <%= @page.title %>/Future Development
+:ARCHIVE_CATEGORY: orgmode_parser
+:ARCHIVE_TODO: DONE
+:END:
+
+And this:
+
+#+BEGIN_SRC ruby
+    # Finds all emphasis matches in a string.
+    # Supply a block that will get the marker and body as parameters.
+    def match_all(str)
+      str.scan(@org_emphasis_regexp) do |match|
+        yield $2, $3
+      end
+    end
+#+END_SRC
diff --git a/spec/html_examples/block_code.html b/spec/html_examples/block_code.html
index 71c7456..226d10e 100644
--- a/spec/html_examples/block_code.html
+++ b/spec/html_examples/block_code.html
@@ -1,6 +1,6 @@
 <h1 class="title">Block Code</h1>
 <p>I need to get block code examples working. In <code>orgmode</code>, they look like this:</p>
-<pre>
+<pre class="example">
 
     def initialize(output)
       @output = output
@@ -17,7 +17,7 @@
 <p>And now I should be back to normal text.</p>
 <p>Putting in another paragraph for good measure.</p>
 <p>Code should also get cancelled by a list, thus:</p>
-<pre>
+<pre class="example">
 This is my code!
 
 Another line!
diff --git a/spec/html_examples/code-comment.html b/spec/html_examples/code-comment.html
index 31ddb47..7e48ae2 100644
--- a/spec/html_examples/code-comment.html
+++ b/spec/html_examples/code-comment.html
@@ -1,6 +1,6 @@
 <h1 class="title">Code Comment</h1>
 <p>I need to be able to export things that look like org-mode comments inside of code blocks, like this:</p>
-<pre>
+<pre class="example">
 #+TITLE:     orgmode_parser.org
 #+AUTHOR:    
 #+EMAIL:     brian at BRIAN-DESK
diff --git a/spec/html_examples/escape-pre.html b/spec/html_examples/escape-pre.html
index 70ef701..0671519 100644
--- a/spec/html_examples/escape-pre.html
+++ b/spec/html_examples/escape-pre.html
@@ -1,4 +1,4 @@
-<pre>
+<pre class="example">
 <li>[ ] &#8220;smart quotes&#8221;</li> 
 <li>[ ] I think I need this for &#8216;single quotes&#8217; too. Don&#8217;t I?</li> 
 <li>[ ] Em dashes would be great &#8212; wouldn&#8217;t they?</li> 
diff --git a/spec/html_examples/metadata-comment.html b/spec/html_examples/metadata-comment.html
index 17bed02..9112ded 100644
--- a/spec/html_examples/metadata-comment.html
+++ b/spec/html_examples/metadata-comment.html
@@ -1,6 +1,6 @@
 <h1 class="title">Metadata, etc.</h1>
 <p>I normally filter out things that look like metadata. Can’t do it any more. I need to see all of the following:</p>
-<pre>
+<pre class="example">
 * DONE Handle inline formatting
   CLOSED: [2009-12-26 Sat 21:41]
   :PROPERTIES:

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