[DRE-commits] [ruby-org] 280/303: Fixes regexps for preparing links.

Jérémy Bobbio lunar at alioth.debian.org
Fri Aug 9 17:34:13 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 f5e44dc373fab5889827f79f97d0a2b877b8acaa
Author: vonavi <ivvl82 at gmail.com>
Date:   Wed Feb 6 12:06:53 2013 +0200

    Fixes regexps for preparing links.
---
 lib/org-ruby/html_output_buffer.rb    |   25 ++++++++++---------------
 lib/org-ruby/textile_output_buffer.rb |   23 +++++++++++++++--------
 2 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index 03095e6..72c482d 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -275,29 +275,24 @@ module Orgmode
           end
         end
       end
-      @re_help.rewrite_links str do |link, text|
-        link = link.sub(/^file:(.*)::(.*?)$/) do
-
+      @re_help.rewrite_links str do |link, defi|
+        [link, defi].compact.each do |text|
           # We don't support search links right now. Get rid of it.
-
-          "file:#{$1}"
+          text.sub!(/\A(file:[^\s]+)::[^\s]*?\Z/, "\\1")
+          text.sub!(/\A(file:[^\s]+)\.org\Z/i, "\\1.html")
+          text.sub!(/\Afile:(?=[^\s]+\Z)/, "")
         end
-        if link.match(/^file:.*\.org$/)
-          link = link.sub(/\.org$/i, ".html")
-        end
-
-        link = link.sub(/^file:/i, "") # will default to HTTP
 
         # We don't add a description for images in links, because its
         # empty value forces the image to be inlined.
-        text ||= link unless link =~ @re_help.org_image_file_regexp
+        defi ||= link unless link =~ @re_help.org_image_file_regexp
 
-        if text =~ @re_help.org_image_file_regexp
-          text = "@<img src=\"#{text}\" alt=\"#{text}\" />"
+        if defi =~ @re_help.org_image_file_regexp
+          defi = "@<img src=\"#{defi}\" alt=\"#{defi}\" />"
         end
 
-        if text
-          "@<a href=\"#{link}\">#{text}@</a>"
+        if defi
+          "@<a href=\"#{link}\">#{defi}@</a>"
         else
           "@<img src=\"#{link}\" alt=\"#{link}\" />"
         end
diff --git a/lib/org-ruby/textile_output_buffer.rb b/lib/org-ruby/textile_output_buffer.rb
index 5f371d0..4f839ac 100644
--- a/lib/org-ruby/textile_output_buffer.rb
+++ b/lib/org-ruby/textile_output_buffer.rb
@@ -54,20 +54,27 @@ module Orgmode
           "^#{text}^"
         end
       end
-      @re_help.rewrite_links input do |link, text|
+      @re_help.rewrite_links input do |link, defi|
+        [link, defi].compact.each do |text|
+          # We don't support search links right now. Get rid of it.
+          text.sub!(/\A(file:[^\s]+)::[^\s]*?\Z/, "\\1")
+          text.sub!(/\A(file:[^\s]+)\.org\Z/i, "\\1.textile")
+          text.sub!(/\Afile:(?=[^\s]+\Z)/, "")
+        end
+
         # We don't add a description for images in links, because its
         # empty value forces the image to be inlined.
-        text ||= link unless link =~ @re_help.org_image_file_regexp
+        defi ||= link unless link =~ @re_help.org_image_file_regexp
         link = link.gsub(/ /, "%%20")
 
-        if text =~ @re_help.org_image_file_regexp
-          text = "!#{text}(#{text})!"
-        else
-          text = "\"#{text}\"" if text
+        if defi =~ @re_help.org_image_file_regexp
+          defi = "!#{defi}(#{defi})!"
+        elsif defi
+          defi = "\"#{defi}\""
         end
 
-        if text
-          "#{text}:#{link}"
+        if defi
+          "#{defi}:#{link}"
         else
           "!#{link}(#{link})!"
         end

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