[DRE-commits] [ruby-org] 90/303: added support for subscript and superscript (foo_{sub} and foo^{sup})

Jérémy Bobbio lunar at alioth.debian.org
Fri Aug 9 17:33:33 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 73b5322c96ec40a712c070e2c8e18e0b39de7506
Author: Rüdiger Sonderfeld <ruediger at c-plusplus.de>
Date:   Wed Jul 20 19:50:36 2011 +0200

    added support for subscript and superscript (foo_{sub} and foo^{sup})
    
    Currently only the syntax with {} is supported. Similar to setting `org-use-sub-superscripts' to {}.
---
 lib/org-ruby/html_output_buffer.rb    |    7 +++++++
 lib/org-ruby/regexp_helper.rb         |    8 ++++++++
 lib/org-ruby/textile_output_buffer.rb |    7 +++++++
 spec/html_examples/subsupscript.html  |    3 +++
 spec/html_examples/subsupscript.org   |    5 +++++
 5 files changed, 30 insertions(+)

diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index 9d094ff..8c177c4 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -145,6 +145,13 @@ module Orgmode
       str = @re_help.rewrite_emphasis(str) do |marker, s|
         "#{Tags[marker][:open]}#{s}#{Tags[marker][:close]}"
       end
+      str = @re_help.rewrite_subp(str) do |type, text|
+        if type == "_" then
+          "<sub>#{text}</sub>"
+        elsif type == "^" then
+          "<sup>#{text}</sup>"
+        end
+      end
       str = @re_help.rewrite_images(str) do |link|
         "<img src=\"#{link}\" />"
       end
diff --git a/lib/org-ruby/regexp_helper.rb b/lib/org-ruby/regexp_helper.rb
index e03512d..9333fe0 100644
--- a/lib/org-ruby/regexp_helper.rb
+++ b/lib/org-ruby/regexp_helper.rb
@@ -61,6 +61,7 @@ module Orgmode
       @logger.level = Logger::WARN
       build_org_emphasis_regexp
       build_org_link_regexp
+      @org_subp_regexp = /([_^])\{(.*?)\}/
     end
 
     # Finds all emphasis matches in a string.
@@ -99,6 +100,13 @@ module Orgmode
       end
     end
 
+    # rewrite subscript and superscript (_{foo} and ^{bar})
+    def rewrite_subp(str) # :yields: type ("_" for subscript and "^" for superscript), text
+      str.gsub(@org_subp_regexp) do |match|
+        yield $1, $2
+      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 6fe85f5..d4aa03d 100644
--- a/lib/org-ruby/textile_output_buffer.rb
+++ b/lib/org-ruby/textile_output_buffer.rb
@@ -36,6 +36,13 @@ module Orgmode
         m = TextileMap[marker]
         "#{m}#{body}#{m}"
       end
+      input = @re_help.rewrite_subp(input) do |type, text|
+        if type == "_" then
+          "~#{text}~"
+        elsif type == "^" then
+          "^#{text}^"
+        end
+      end
       input = @re_help.rewrite_links(input) do |link, text|
         text ||= link
         link = link.gsub(/ /, "%20")
diff --git a/spec/html_examples/subsupscript.html b/spec/html_examples/subsupscript.html
new file mode 100644
index 0000000..5ed592f
--- /dev/null
+++ b/spec/html_examples/subsupscript.html
@@ -0,0 +1,3 @@
+<p class="title">SUBSUPSCRIPT</p>
+<p>a<sup>b</sup></p>
+<p>a<sub>b</sub></p>
diff --git a/spec/html_examples/subsupscript.org b/spec/html_examples/subsupscript.org
new file mode 100644
index 0000000..997a3e1
--- /dev/null
+++ b/spec/html_examples/subsupscript.org
@@ -0,0 +1,5 @@
+SUBSUPSCRIPT
+
+a^{b}
+
+a_{b}

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