[DRE-commits] [ruby-org] 156/303: Lists with code fragments should work (fixes #27)

Jérémy Bobbio lunar at alioth.debian.org
Fri Aug 9 17:33:48 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 c5d3108f63ae210f958241aaf85f5adc8da5986b
Author: Waldemar Quevedo <waldemar.quevedo at gmail.com>
Date:   Wed Jul 4 02:49:01 2012 +0900

    Lists with code fragments should work (fixes #27)
---
 lib/org-ruby/html_output_buffer.rb        |   55 ++++++++++++-
 lib/org-ruby/output_buffer.rb             |    6 +-
 spec/html_examples/advanced-lists.html    |   39 ++++++----
 spec/html_examples/block_code.html        |    6 +-
 spec/html_examples/code-lists.html        |  119 +++++++++++++++++++++++++++++
 spec/html_examples/code-lists.org         |   83 ++++++++++++++++++++
 spec/html_examples/custom-seq-todo.html   |    6 +-
 spec/html_examples/custom-todo.html       |    6 +-
 spec/html_examples/custom-typ-todo.html   |    6 +-
 spec/html_examples/inline-formatting.html |   15 ++--
 spec/html_examples/inline-images.html     |   12 ++-
 spec/html_examples/link-features.html     |   18 +++--
 spec/html_examples/lists.html             |   21 +++--
 spec/html_examples/only-list.html         |    9 ++-
 14 files changed, 351 insertions(+), 50 deletions(-)

diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index 437e96e..c5bc5f7 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -41,6 +41,7 @@ module Orgmode
       end
       @options = opts
       @footnotes = {}
+      @unclosed_tags = []
       @logger.debug "HTML export options: #{@options.inspect}"
     end
 
@@ -77,8 +78,20 @@ module Orgmode
           @logger.debug "</code>\n"
           @output << "</code>\n"
         end
+
+        # Need to close the floating li elements before closing the list
+        if (m == :unordered_list or
+            m == :ordered_list or
+            m == :definition_list) and 
+            (not @unclosed_tags.empty?)
+          close_floating_li_tags
+        end
+
         @logger.debug "</#{ModeTag[m]}>\n"
         @output << "</#{ModeTag[m]}>\n" unless mode == :table and skip_tables?
+
+        # In case it was a sublist, close it here
+        close_last_li_tag_maybe
       end
     end
 
@@ -110,6 +123,11 @@ module Orgmode
           unless buffer_mode_is_table? and skip_tables?
             @logger.debug "FLUSH      ==========> #{@buffer_mode}"
             output_indentation
+            if ((@buffered_lines[0].plain_list?) and 
+                (@unclosed_tags.count == @list_indent_stack.count))
+              @output << @unclosed_tags.pop
+              output_indentation
+            end
             @output << "<#{HtmlBlockTag[@output_type]}#{@title_decoration}>"
             if (@buffered_lines[0].kind_of?(Headline)) then
               headline = @buffered_lines[0]
@@ -125,7 +143,18 @@ module Orgmode
               end
             end
             @output << inline_formatting(@buffer)
-            @output << "</#{HtmlBlockTag[@output_type]}>\n"
+
+            # Only close the list when it is the last element from that list,
+            # or when starting another list
+            if (@output_type == :unordered_list or 
+                @output_type == :ordered_list   or
+                @output_type == :definition_list) and 
+                (not @list_indent_stack.empty?)
+              @unclosed_tags.push("</#{HtmlBlockTag[@output_type]}>\n")
+              @output << "\n"
+            else
+              @output << "</#{HtmlBlockTag[@output_type]}>\n"
+            end
             @title_decoration = ""
           else
             @logger.debug "SKIP       ==========> #{@buffer_mode}"
@@ -242,5 +271,29 @@ module Orgmode
       Orgmode.special_symbols_to_html(str)
       str
     end
+
+    def close_floating_li_tags
+      unless @final_list_node
+        unless @unclosed_tags.empty?
+          @output << "  " << @unclosed_tags.pop
+          output_indentation
+        end
+      end
+
+      @final_list_node = false
+    end
+
+    def close_last_li_tag_maybe
+      if (@list_indent_stack.count < @unclosed_tags.count) and not
+          (@list_indent_stack.empty? and @unclosed_tags.empty?)
+        output_indentation
+        @output << @unclosed_tags.pop
+        if (@list_indent_stack.count == @unclosed_tags.count) and not
+            (@list_indent_stack.empty? and @unclosed_tags.empty?)
+          @final_list_node = true
+          pop_mode
+        end
+      end
+    end
   end                           # class HtmlOutputBuffer
 end                             # module Orgmode
diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb
index e2ac05e..720b086 100644
--- a/lib/org-ruby/output_buffer.rb
+++ b/lib/org-ruby/output_buffer.rb
@@ -180,9 +180,9 @@ module Orgmode
 
         # Nothing
 
-      elsif ((line.paragraph_type == :paragraph) and
-             (not @list_indent_stack.empty? and
-              line.indent > @list_indent_stack.last))
+      elsif ((not line.plain_list?) and
+             (not @list_indent_stack.empty?) and
+             (line.indent > @list_indent_stack.last))
 
         # Nothing -- output this paragraph inside
         # the list block (ul/ol)
diff --git a/spec/html_examples/advanced-lists.html b/spec/html_examples/advanced-lists.html
index 8696320..15b0c34 100644
--- a/spec/html_examples/advanced-lists.html
+++ b/spec/html_examples/advanced-lists.html
@@ -2,30 +2,43 @@
 <p><code>org-ruby</code> supports the following list features of <code>org-mode</code>:</p>
 <h1>Nested lists</h1>
 <ul>
-  <li>You can have nested lists</li>
-  <li>This is first-level</li>
+  <li>You can have nested lists
+  </li>
+  <li>This is first-level
   <ul>
-    <li>This is a nested item</li>
-    <li>This is another nested item</li>
+    <li>This is a nested item
+    </li>
+    <li>This is another nested item
+    </li>
   </ul>
-  <li>Back to the first level</li>
-  <li>Another first level item</li>
+  </li>
+  <li>Back to the first level
+  </li>
+  <li>Another first level item
   <ol>
-    <li>This is a numbered list nested within the unordered list</li>
-    <li>This is another numbered item</li>
+    <li>This is a numbered list nested within the unordered list
+    </li>
+    <li>This is another numbered item
+    </li>
   </ol>
+  </li>
 </ul>
 <p>Note the list ends just some more text. Make sure both list blocks are closed.</p>
 <h1>Multi-paragraph list items</h1>
 <p>This list will end with the end-of-file. Make sure all blocks are closed.</p>
 <ul>
-  <li>This is a list item</li>
-  <li>This list item has multiple paragraphs.</li>
+  <li>This is a list item
+  </li>
+  <li>This list item has multiple paragraphs.
   <p>This is paragraph two.</p>
   <p>And paragraph three.</p>
-  <li>Back to a list item.</li>
+  </li>
+  <li>Back to a list item.
   <ul>
-    <li>Nested, just for grins!</li>
-    <li>woo hoo!</li>
+    <li>Nested, just for grins!
+    </li>
+    <li>woo hoo!
+    </li>
   </ul>
+  </li>
 </ul>
diff --git a/spec/html_examples/block_code.html b/spec/html_examples/block_code.html
index 226d10e..9fafc72 100644
--- a/spec/html_examples/block_code.html
+++ b/spec/html_examples/block_code.html
@@ -23,6 +23,8 @@ This is my code!
 Another line!
 </pre>
 <ul>
-  <li>My list should cancel this.</li>
-  <li>Another list line.</li>
+  <li>My list should cancel this.
+  </li>
+  <li>Another list line.
+  </li>
 </ul>
diff --git a/spec/html_examples/code-lists.html b/spec/html_examples/code-lists.html
new file mode 100644
index 0000000..d881849
--- /dev/null
+++ b/spec/html_examples/code-lists.html
@@ -0,0 +1,119 @@
+<h1 class="title">normal list should work</h1>
+<ul>
+  <li>one text in the same line
+  <p>This is a paragraph</p>
+  <ul>
+    <li>A sublist
+    <ul>
+      <li>Another sublist
+      <p>Sublist paragraph</p>
+      </li>
+    </ul>
+    </li>
+    <li>2nd sublist
+    <ul>
+      <li>2nd sublist item
+      <p>Paragraph from 2nd sublist</p>
+      </li>
+    </ul>
+    </li>
+  </ul>
+  </li>
+  <li>two
+  <ol>
+    <li>a new list
+    <p>paragraph</p>
+    </li>
+    <li>another sublist
+    </li>
+  </ol>
+  </li>
+  <li>final list
+  </li>
+</ul>
+<h1>paragraphs in lists should work</h1>
+<ul>
+  <li>Foo
+  <ul>
+    <li>How does this work?
+    <p>uno dos tres</p>
+    </li>
+    <li>Should not this be a paragraph?
+    </li>
+  </ul>
+  </li>
+  <li>Bar
+  </li>
+</ul>
+<h1>begin example in lists should work</h1>
+<ul>
+  <li>Foo
+  <pre class="example">
+    class Hello
+      def say
+        puts 'cheers'
+      end
+    end
+  </pre>
+  </li>
+  <li>Bar
+  <pre class="example">
+    This gets lumped in to the above line "Example"
+  </pre>
+  </li>
+  <li>Hello
+  </li>
+</ul>
+<h1>begin quote in lists should work</h1>
+<ul>
+  <li>Example
+  <ul>
+    <li>Uno Lorem
+    <blockquote>
+      <p>A quote!!!</p>
+    </blockquote>
+    <p>dolor</p>
+    </li>
+    <li>Dos
+    </li>
+  </ul>
+  </li>
+</ul>
+<h1>tables in lists should work</h1>
+<ul>
+  <li>Example
+  <ul>
+    <li>Table
+    <p>This table:</p>
+    <table>
+      <tr><td>a</td><td>b</td></tr>
+      <tr><td>0</td><td>1</td></tr>
+      <tr><td>1</td><td>2</td></tr>
+    </table>
+    </li>
+  </ul>
+  </li>
+  <li>After the table
+  <p>The table should be above</p>
+  </li>
+</ul>
+<h1>definition lists should work</h1>
+<ul>
+  <li>Example
+  <dl>
+    <dt>Hello</dt><dd>Hola Paragrap continues here</dd>
+    <blockquote>
+      <p>Cuando me desperté, el dinosaurio estaba allí.</p>
+    </blockquote>
+    <dt>Dog</dt><dd>Perro Paragraph</dd>
+    <li>Last sublist
+    </li>
+  </dl>
+  </li>
+  <li>Another list
+  <ul>
+    <li>with a sublist
+    </li>
+  </ul>
+  </li>
+</ul>
diff --git a/spec/html_examples/code-lists.org b/spec/html_examples/code-lists.org
new file mode 100644
index 0000000..54eac4b
--- /dev/null
+++ b/spec/html_examples/code-lists.org
@@ -0,0 +1,83 @@
+* normal list should work
+
+- one
+  text in the same line
+
+  This is a paragraph
+  + A sublist
+    - Another sublist
+
+      Sublist paragraph
+  + 2nd sublist
+    - 2nd sublist item
+
+      Paragraph from 2nd sublist
+- two
+  1. a new list
+
+     paragraph
+  2. another sublist
+- final list
+* paragraphs in lists should work
+
+- Foo
+    + How does this work?
+
+      uno dos tres
+    + Should not this be a paragraph?
+- Bar
+
+* begin example in lists should work
+
+  - Foo
+    #+begin_example
+    class Hello
+      def say
+        puts 'cheers'
+      end
+    end
+    #+end_example
+  - Bar
+    #+begin_example
+    This gets lumped in to the above line "Example"
+    #+end_example
+  - Hello
+
+* begin quote in lists should work
+
+- Example
+  + Uno
+    Lorem
+    #+begin_quote
+    A quote!!!
+    #+end_quote
+    dolor
+  + Dos
+
+* tables in lists should work
+
+- Example
+  + Table
+
+    This table:
+    | a | b |
+    | 0 | 1 |
+    | 1 | 2 |
+
+- After the table
+
+  The table should be above
+
+* definition lists should work
+
+- Example
+  + Hello :: Hola
+	     Paragrap continues here
+	     #+begin_quote
+	     Cuando me desperté, el dinosaurio estaba allí.
+	     #+end_quote
+  + Dog :: Perro
+	   Paragraph
+  + Last sublist
+- Another list
+  + with a sublist
diff --git a/spec/html_examples/custom-seq-todo.html b/spec/html_examples/custom-seq-todo.html
index 2cb7712..d19a3e3 100644
--- a/spec/html_examples/custom-seq-todo.html
+++ b/spec/html_examples/custom-seq-todo.html
@@ -2,8 +2,10 @@
 <p>I copied this todo sequence from Worg. It shows a lot of power of the built-in todo functionality. Now, let’s make sure all of these are recognized (and therefore NOT exported.)</p>
 <h1><span class="todo-keyword TODO">TODO </span>Sample</h1>
 <ul>
-  <li>State “CANCELED”   from “INPROGRESS” [2009-12-29 Tue 22:26] \ I gave up.</li>
-  <li>State “WAITING”    from “”           [2009-12-29 Tue 22:25] \ huh?</li>
+  <li>State “CANCELED”   from “INPROGRESS” [2009-12-29 Tue 22:26] \ I gave up.
+  </li>
+  <li>State “WAITING”    from “”           [2009-12-29 Tue 22:25] \ huh?
+  </li>
 </ul>
 <h1><span class="todo-keyword INPROGRESS">INPROGRESS </span>this one’s in progress</h1>
 <h1><span class="todo-keyword WAITING">WAITING </span>who am I waiting on?</h1>
diff --git a/spec/html_examples/custom-todo.html b/spec/html_examples/custom-todo.html
index 2cb7712..d19a3e3 100644
--- a/spec/html_examples/custom-todo.html
+++ b/spec/html_examples/custom-todo.html
@@ -2,8 +2,10 @@
 <p>I copied this todo sequence from Worg. It shows a lot of power of the built-in todo functionality. Now, let’s make sure all of these are recognized (and therefore NOT exported.)</p>
 <h1><span class="todo-keyword TODO">TODO </span>Sample</h1>
 <ul>
-  <li>State “CANCELED”   from “INPROGRESS” [2009-12-29 Tue 22:26] \ I gave up.</li>
-  <li>State “WAITING”    from “”           [2009-12-29 Tue 22:25] \ huh?</li>
+  <li>State “CANCELED”   from “INPROGRESS” [2009-12-29 Tue 22:26] \ I gave up.
+  </li>
+  <li>State “WAITING”    from “”           [2009-12-29 Tue 22:25] \ huh?
+  </li>
 </ul>
 <h1><span class="todo-keyword INPROGRESS">INPROGRESS </span>this one’s in progress</h1>
 <h1><span class="todo-keyword WAITING">WAITING </span>who am I waiting on?</h1>
diff --git a/spec/html_examples/custom-typ-todo.html b/spec/html_examples/custom-typ-todo.html
index 2cb7712..d19a3e3 100644
--- a/spec/html_examples/custom-typ-todo.html
+++ b/spec/html_examples/custom-typ-todo.html
@@ -2,8 +2,10 @@
 <p>I copied this todo sequence from Worg. It shows a lot of power of the built-in todo functionality. Now, let’s make sure all of these are recognized (and therefore NOT exported.)</p>
 <h1><span class="todo-keyword TODO">TODO </span>Sample</h1>
 <ul>
-  <li>State “CANCELED”   from “INPROGRESS” [2009-12-29 Tue 22:26] \ I gave up.</li>
-  <li>State “WAITING”    from “”           [2009-12-29 Tue 22:25] \ huh?</li>
+  <li>State “CANCELED”   from “INPROGRESS” [2009-12-29 Tue 22:26] \ I gave up.
+  </li>
+  <li>State “WAITING”    from “”           [2009-12-29 Tue 22:25] \ huh?
+  </li>
 </ul>
 <h1><span class="todo-keyword INPROGRESS">INPROGRESS </span>this one’s in progress</h1>
 <h1><span class="todo-keyword WAITING">WAITING </span>who am I waiting on?</h1>
diff --git a/spec/html_examples/inline-formatting.html b/spec/html_examples/inline-formatting.html
index 74e8d24..2a01fd4 100644
--- a/spec/html_examples/inline-formatting.html
+++ b/spec/html_examples/inline-formatting.html
@@ -2,19 +2,24 @@
 <p>I want to make sure I handle all inline formatting. I need to handle <b>bold</b>, <i>italic</i>, <code>code</code>, <code>verbatim</code>, <span style="text-decoration:underline;">underline</span>, <del>strikethrough</del>.</p>
 <p>In addition, I need to make sure I can handle links. We’ve got simple links, like this:</p>
 <ul>
-  <li><a href="http://www.bing.com">http://www.bing.com</a></li>
-  <li><a href="http://www.google.com">http://www.google.com</a></li>
-  <li>http://www.gmail.com</li>
+  <li><a href="http://www.bing.com">http://www.bing.com</a>
+  </li>
+  <li><a href="http://www.google.com">http://www.google.com</a>
+  </li>
+  <li>http://www.gmail.com
+  </li>
 </ul>
 <p>Note the last one <b>is not</b> a link, as the source doesn’t include it in double-brackets and I don’t auto-recognize URLs.</p>
 <p>I should also handle links with <a href="http://www.xkcd.com">helpful text</a>.</p>
 <p>Helpful addition from <a href="https://github.com/punchagan">punchagan</a>, we now recognize when the link goes to an image and make the link anchor be the image, like this:</p>
 <ul>
-  <li><a href="http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg"><img src="http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg" /></a></li>
+  <li><a href="http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg"><img src="http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg" /></a>
+  </li>
 </ul>
 <p>Also, if you make the descriptive text be an image, then it will get formatted with an image tag, like so:</p>
 <ul>
-  <li><a href="http://www.xkcd.com"><img src="http://imgs.xkcd.com/comics/t_cells.png" /></a></li>
+  <li><a href="http://www.xkcd.com"><img src="http://imgs.xkcd.com/comics/t_cells.png" /></a>
+  </li>
 </ul>
 <p>Helpful addition from <a href="https://github.com/wallyqs">wallyqs</a>:</p>
 <p>While “naked” links don’t work (like http://www.google.com), angle links do work. This should look like a link: <a href="http://www.google.com">http://www.google.com</a>.</p>
diff --git a/spec/html_examples/inline-images.html b/spec/html_examples/inline-images.html
index 562f6c2..c6aa8cf 100644
--- a/spec/html_examples/inline-images.html
+++ b/spec/html_examples/inline-images.html
@@ -3,8 +3,12 @@
 <p><a href="http://farm5.static.flickr.com/4049/4358074549_5efb8b4903.jpg"><img src="http://farm5.static.flickr.com/4049/4358074549_5efb8b4903.jpg" /></a></p>
 <p>I currently do not support the caption/link syntax, but I can include the inline image. I recognize the following image file types:</p>
 <ul>
-  <li>.jpg</li>
-  <li>.png</li>
-  <li>.gif</li>
-  <li>.jpeg</li>
+  <li>.jpg
+  </li>
+  <li>.png
+  </li>
+  <li>.gif
+  </li>
+  <li>.jpeg
+  </li>
 </ul>
diff --git a/spec/html_examples/link-features.html b/spec/html_examples/link-features.html
index f5b5c28..d55efc5 100644
--- a/spec/html_examples/link-features.html
+++ b/spec/html_examples/link-features.html
@@ -8,13 +8,19 @@
 <p><a href="code-comment.html">Code Comment</a></p>
 <h1>Correct handling of .org URIs in HTML markup routine (thanks @rayl!)</h1>
 <ul>
-  <li><a href="http://foo.com">foo.com website</a></li>
-  <li><a href="http://foo.org">foo.org website</a></li>
+  <li><a href="http://foo.com">foo.com website</a>
+  </li>
+  <li><a href="http://foo.org">foo.org website</a>
+  </li>
 </ul>
 <h1>In these links, .org is converted to .html</h1>
 <ul>
-  <li><a href="http://foo.org/foo.html">foo.org/foo.org</a></li>
-  <li><a href="http://localhost:4567/foo.html">localhost:4567/foo.org</a></li>
-  <li><a href="path.html">file:path.org label</a></li>
-  <li><a href="notes/path.html">file:notes/path.org label</a></li>
+  <li><a href="http://foo.org/foo.html">foo.org/foo.org</a>
+  </li>
+  <li><a href="http://localhost:4567/foo.html">localhost:4567/foo.org</a>
+  </li>
+  <li><a href="path.html">file:path.org label</a>
+  </li>
+  <li><a href="notes/path.html">file:notes/path.org label</a>
+  </li>
 </ul>
diff --git a/spec/html_examples/lists.html b/spec/html_examples/lists.html
index c956701..28c121d 100644
--- a/spec/html_examples/lists.html
+++ b/spec/html_examples/lists.html
@@ -1,20 +1,27 @@
 <h1 class="title">Lists</h1>
 <p>I want to make sure I have great support for lists.</p>
 <ul>
-  <li>This is an unordered list</li>
-  <li>This continues the unordered list</li>
+  <li>This is an unordered list
+  </li>
+  <li>This continues the unordered list
+  </li>
 </ul>
 <p>And this is a paragraph <b>after</b> the list.</p>
 <h2>Wrapping within the list</h2>
 <ul>
-  <li>This is a single-line list item in the org file.</li>
-  <li>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo du [...]
-  <li>And this is the next item. The previous item needs to be on one line to keep <code>textile</code> happy.</li>
-  <li>Ditto the previous line, actually.</li>
+  <li>This is a single-line list item in the org file.
+  </li>
+  <li>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo du [...]
+  </li>
+  <li>And this is the next item. The previous item needs to be on one line to keep <code>textile</code> happy.
+  </li>
+  <li>Ditto the previous line, actually.
+  </li>
 </ul>
 <h2>Edge cases</h2>
 <ul>
-  <li>This is a single-line list.</li>
+  <li>This is a single-line list.
+  </li>
 </ul>
 <p>And this is a <b>separate paragraph.</b> Note the indentation in the org file.</p>
 <h2>Invalid lists</h2>
diff --git a/spec/html_examples/only-list.html b/spec/html_examples/only-list.html
index 91e354a..bbfaf83 100644
--- a/spec/html_examples/only-list.html
+++ b/spec/html_examples/only-list.html
@@ -1,5 +1,8 @@
 <ul>
-  <li>This file has only a list</li>
-  <li>Note it will end with nothing other than a list item.</li>
-  <li>the world wants to know: Will org-ruby write the closing ul tag?</li>
+  <li>This file has only a list
+  </li>
+  <li>Note it will end with nothing other than a list item.
+  </li>
+  <li>the world wants to know: Will org-ruby write the closing ul tag?
+  </li>
 </ul>

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