[DRE-commits] [ruby-org] 267/303: Change implementation of footnotes in textile_output.

Jérémy Bobbio lunar at alioth.debian.org
Fri Aug 9 17:34:10 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 ccbc19b7d5b38207d9002afde0ca089a9deedc79
Author: Waldemar Quevedo <waldemar.quevedo at gmail.com>
Date:   Sun Feb 3 22:21:57 2013 +0900

    Change implementation of footnotes in textile_output.
    
    Update the footnote.org tests.
---
 lib/org-ruby/textile_output_buffer.rb   |   26 ++++++++++++++++++--------
 spec/html_examples/footnotes.html       |    9 ++++++---
 spec/html_examples/footnotes.org        |   13 ++++++++++---
 spec/textile_examples/footnotes.org     |   13 ++++++++++---
 spec/textile_examples/footnotes.textile |   19 ++++++++++++++-----
 5 files changed, 58 insertions(+), 22 deletions(-)

diff --git a/lib/org-ruby/textile_output_buffer.rb b/lib/org-ruby/textile_output_buffer.rb
index c42e7f9..37024ac 100644
--- a/lib/org-ruby/textile_output_buffer.rb
+++ b/lib/org-ruby/textile_output_buffer.rb
@@ -8,7 +8,7 @@ module Orgmode
       super(output)
       @add_paragraph = true
       @support_definition_list = true # TODO this should be an option
-      @footnotes = {}
+      @footnotes = []
     end
 
     def push_mode(mode, indent)
@@ -59,11 +59,20 @@ module Orgmode
         link = link.gsub(/ /, "%%20")
         "\"#{text}\":#{link}"
       end
-      @re_help.rewrite_footnote input do |name, defi|
-        # textile only support numerical names! Use hash as a workarround
-        name = name.hash.to_s unless name.to_i.to_s == name # check if number
-        @footnotes[name] = defi if defi
-        "[#{name}]"
+      @re_help.rewrite_footnote input do |name, definition|
+        # textile only support numerical names, so we need to do some conversion
+        # Try to find the footnote and use its index
+        footnote = @footnotes.select {|f| f[:name] == name }.first
+        if footnote
+          # The latest definition overrides other ones
+          footnote[:definition] = definition if definition and not footnote[:definition]
+        else
+          # There is no footnote with the current name so we add it
+          footnote = { :name => name, :definition => definition } 
+          @footnotes << footnote
+        end
+
+        "[#{@footnotes.index(footnote)}]"
       end
       Orgmode.special_symbols_to_textile(input)
       input = @re_help.restore_code_snippets input
@@ -73,8 +82,9 @@ module Orgmode
     def output_footnotes!
       return false if @footnotes.empty?
 
-      @footnotes.each do |name, defi|
-        @output << "\nfn#{name}. #{defi}\n"
+      @footnotes.each do |footnote|
+        index = @footnotes.index(footnote)
+        @output << "\nfn#{index}. #{footnote[:definition] || 'DEFINITION NOT FOUND' }\n"
       end
 
       return true
diff --git a/spec/html_examples/footnotes.html b/spec/html_examples/footnotes.html
index d1f4bdc..d08ad06 100644
--- a/spec/html_examples/footnotes.html
+++ b/spec/html_examples/footnotes.html
@@ -1,7 +1,10 @@
 <p class="title">Footnotes</p>
-<p>Hello<sup><a class="footref" name="fnr.abc" href="#fn.abc">abc</a></sup>
-  World<sup><a class="footref" name="fnr.abc" href="#fn.abc">abc</a></sup></p>
-<p>Bfoo<sup><a class="footref" name="fnr.1" href="#fn.1">1</a></sup></p>
+<h1>Footnotes</h1>
+<p>Using numbers <sup><a class="footref" name="fnr.0" href="#fn.0">0</a></sup></p>
+<p>Using letters and not defined in the footnote <sup><a class="footref" name="fnr.abc" href="#fn.abc">abc</a></sup></p>
+<p>Using letters and defined in the footnote <sup><a class="footref" name="fnr.abc" href="#fn.abc">abc</a></sup></p>
+<p>Defined in the footnote itself with markup <sup><a class="footref" name="fnr.1" href="#fn.1">1</a></sup></p>
+<p><sup><a class="footref" name="fnr.0" href="#fn.0">0</a></sup> Definition of first footnote</p>
 <div id="footnotes">
 <h2 class="footnotes">Footnotes:</h2>
 <div id="text-footnotes">
diff --git a/spec/html_examples/footnotes.org b/spec/html_examples/footnotes.org
index 86ee879..8468f7d 100644
--- a/spec/html_examples/footnotes.org
+++ b/spec/html_examples/footnotes.org
@@ -1,7 +1,14 @@
 #+TITLE: Footnotes
 #+OPTIONS: f:t
 
-Hello[fn:abc]
-World[fn:abc:definition of abc]
+* Footnotes
 
-Bfoo[fn:1:*blub*]
+Using numbers [fn:0]
+
+Using letters and not defined in the footnote [fn:abc]
+
+Using letters and defined in the footnote [fn:abc:definition of abc]
+
+Defined in the footnote itself with markup [fn:1:*blub*]
+
+[fn:0] Definition of first footnote
diff --git a/spec/textile_examples/footnotes.org b/spec/textile_examples/footnotes.org
index 86ee879..8468f7d 100644
--- a/spec/textile_examples/footnotes.org
+++ b/spec/textile_examples/footnotes.org
@@ -1,7 +1,14 @@
 #+TITLE: Footnotes
 #+OPTIONS: f:t
 
-Hello[fn:abc]
-World[fn:abc:definition of abc]
+* Footnotes
 
-Bfoo[fn:1:*blub*]
+Using numbers [fn:0]
+
+Using letters and not defined in the footnote [fn:abc]
+
+Using letters and defined in the footnote [fn:abc:definition of abc]
+
+Defined in the footnote itself with markup [fn:1:*blub*]
+
+[fn:0] Definition of first footnote
diff --git a/spec/textile_examples/footnotes.textile b/spec/textile_examples/footnotes.textile
index fb8ab3d..73e6cde 100644
--- a/spec/textile_examples/footnotes.textile
+++ b/spec/textile_examples/footnotes.textile
@@ -1,9 +1,18 @@
 
-p. Hello[3172870960376162564]
-World[3172870960376162564]
+h1. Footnotes
 
-p. Bfoo[1]
+p. Using numbers [0]
 
-fn3172870960376162564. definition of abc
+p. Using letters and not defined in the footnote [1]
 
-fn1. *blub*
+p. Using letters and defined in the footnote [1]
+
+p. Defined in the footnote itself with markup [2]
+
+p. [0] Definition of first footnote
+
+fn0. DEFINITION NOT FOUND
+
+fn1. definition of abc
+
+fn2. *blub*

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