[DRE-commits] [ruby-org] 95/303: Added support for Footnotes (both HTML and Textile).
Jérémy Bobbio
lunar at alioth.debian.org
Fri Aug 9 17:33:35 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 7554cdcde9af5189099ff495e266b79c3072e2f8
Author: Rüdiger Sonderfeld <ruediger at c-plusplus.de>
Date: Thu Jul 21 03:15:48 2011 +0200
Added support for Footnotes (both HTML and Textile).
It currently only works with non-numerical footnotes ([fn:1] does work but [1] does not, as recommended by the org-mode manual) and it only supports inline definition ([fn:name:definition]).
---
lib/org-ruby/html_output_buffer.rb | 26 +++++++++++++++++++++++++-
lib/org-ruby/output_buffer.rb | 4 ++++
lib/org-ruby/parser.rb | 4 +++-
lib/org-ruby/regexp_helper.rb | 8 ++++++++
lib/org-ruby/textile_output_buffer.rb | 17 +++++++++++++++++
spec/html_examples/footnotes.html | 10 ++++++++++
spec/html_examples/footnotes.org | 6 ++++++
spec/textile_examples/footnotes.org | 6 ++++++
spec/textile_examples/footnotes.textile | 8 ++++++++
9 files changed, 87 insertions(+), 2 deletions(-)
diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index 4a7c39f..09bbc6c 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -42,6 +42,7 @@ module Orgmode
@title_decoration = ""
end
@options = opts
+ @footnotes = {}
@logger.debug "HTML export options: #{@options.inspect}"
end
@@ -125,6 +126,23 @@ module Orgmode
clear_accumulation_buffer!
end
+ def output_footnotes!
+ return false unless @options[:export_footnotes] and not @footnotes.empty?
+
+ @output << "<div id=\"footnotes\">\n<h2 class=\"footnotes\">Footnotes: </h2>\n<div id=\"text-footnotes\">\n"
+
+ @footnotes.each do |name, defi|
+ @output << "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.#{name}\" href=\"#fnr.#{name}\">#{name}</a></sup>" \
+ << inline_formatting(defi) \
+ << "</p>\n"
+ end
+
+ @output << "</div>\n</div>\n"
+
+ return true
+ end
+
+
######################################################################
private
@@ -198,8 +216,14 @@ module Orgmode
str.gsub!(/\s*\|$/, "</th>")
str.gsub!(/\s*\|\s*/, "</th><th>")
end
+ if @options[:export_footnotes] then
+ str = @re_help.rewrite_footnote(str) do |name, defi|
+ # TODO escape name for url?
+ @footnotes[name] = defi if defi
+ "<sup><a class=\"footref\" name=\"fnr.#{name}\" href=\"#fn.#{name}\">#{name}</a></sup>"
+ end
+ end
str
end
-
end # class HtmlOutputBuffer
end # module Orgmode
diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb
index a0d472f..91fd7e3 100644
--- a/lib/org-ruby/output_buffer.rb
+++ b/lib/org-ruby/output_buffer.rb
@@ -194,6 +194,10 @@ module Orgmode
end
end
+ def output_footnotes!
+ return false
+ end
+
# Tests if the current line should be accumulated in the current
# output buffer. (Extraneous line breaks in the orgmode buffer
# are removed by accumulating lines in the output buffer without
diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb
index 27f8b7a..905f310 100644
--- a/lib/org-ruby/parser.rb
+++ b/lib/org-ruby/parser.rb
@@ -170,7 +170,8 @@ module Orgmode
:decorate_title => true,
:export_heading_number => export_heading_number?,
:export_todo => export_todo?,
- :use_sub_superscripts => use_sub_superscripts?
+ :use_sub_superscripts => use_sub_superscripts?,
+ :export_footnotes => true
}
export_options[:skip_tables] = true if not export_tables?
output = ""
@@ -256,6 +257,7 @@ module Orgmode
end
output_buffer.flush!
output_buffer.pop_mode until output_buffer.current_mode == :normal
+ output_buffer.output_footnotes!
output_buffer.output
end
diff --git a/lib/org-ruby/regexp_helper.rb b/lib/org-ruby/regexp_helper.rb
index 9333fe0..7378009 100644
--- a/lib/org-ruby/regexp_helper.rb
+++ b/lib/org-ruby/regexp_helper.rb
@@ -62,6 +62,7 @@ module Orgmode
build_org_emphasis_regexp
build_org_link_regexp
@org_subp_regexp = /([_^])\{(.*?)\}/
+ @org_footnote_regexp = /\[fn:(.+?)(:(.*?))?\]/
end
# Finds all emphasis matches in a string.
@@ -107,6 +108,13 @@ module Orgmode
end
end
+ # rewrite footnotes
+ def rewrite_footnote(str) # :yields: name, definition or nil
+ str.gsub(@org_footnote_regexp) do |match|
+ yield $1, $3
+ end
+ end
+
# = Summary
#
# Rewrite org-mode links in a string to markup suitable to the
diff --git a/lib/org-ruby/textile_output_buffer.rb b/lib/org-ruby/textile_output_buffer.rb
index 3ec91fb..b3f4737 100644
--- a/lib/org-ruby/textile_output_buffer.rb
+++ b/lib/org-ruby/textile_output_buffer.rb
@@ -8,6 +8,7 @@ module Orgmode
super(output)
@add_paragraph = false
@support_definition_list = true # TODO this should be an option
+ @footnotes = {}
end
def push_mode(mode)
@@ -51,9 +52,25 @@ module Orgmode
link = link.gsub(/ /, "%20")
"\"#{text}\":#{link}"
end
+ input = @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}]"
+ end
input
end
+ def output_footnotes!
+ return false if @footnotes.empty?
+
+ @footnotes.each do |name, defi|
+ @output << "\nfn#{name}. #{defi}\n"
+ end
+
+ return true
+ end
+
# Flushes the current buffer
def flush!
@logger.debug "FLUSH ==========> #{@output_type}"
diff --git a/spec/html_examples/footnotes.html b/spec/html_examples/footnotes.html
new file mode 100644
index 0000000..cda267d
--- /dev/null
+++ b/spec/html_examples/footnotes.html
@@ -0,0 +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>
+<div id="footnotes">
+<h2 class="footnotes">Footnotes: </h2>
+<div id="text-footnotes">
+<p class="footnote"><sup><a class="footnum" name="fn.abc" href="#fnr.abc">abc</a></sup>definition of abc</p>
+<p class="footnote"><sup><a class="footnum" name="fn.1" href="#fnr.1">1</a></sup><b>blub</b></p>
+</div>
+</div>
diff --git a/spec/html_examples/footnotes.org b/spec/html_examples/footnotes.org
new file mode 100644
index 0000000..f5c5ef2
--- /dev/null
+++ b/spec/html_examples/footnotes.org
@@ -0,0 +1,6 @@
+#+TITLE: Footnotes
+
+Hello[fn:abc]
+World[fn:abc:definition of abc]
+
+Bfoo[fn:1:*blub*]
diff --git a/spec/textile_examples/footnotes.org b/spec/textile_examples/footnotes.org
new file mode 100644
index 0000000..f5c5ef2
--- /dev/null
+++ b/spec/textile_examples/footnotes.org
@@ -0,0 +1,6 @@
+#+TITLE: Footnotes
+
+Hello[fn:abc]
+World[fn:abc:definition of abc]
+
+Bfoo[fn:1:*blub*]
diff --git a/spec/textile_examples/footnotes.textile b/spec/textile_examples/footnotes.textile
new file mode 100644
index 0000000..4dc0863
--- /dev/null
+++ b/spec/textile_examples/footnotes.textile
@@ -0,0 +1,8 @@
+
+Hello[833038373] World[833038373]
+
+Bfoo[1]
+
+fn1. *blub*
+
+fn833038373. definition of abc
--
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