[DRE-commits] [ruby-org] 278/303: Switches the formatting of image links to default Org-mode behavior.
Jérémy Bobbio
lunar at alioth.debian.org
Fri Aug 9 17:34:12 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 76d8274ec2e82663245acbe70d5c0017e51ceb08
Author: vonavi <ivvl82 at gmail.com>
Date: Tue Feb 5 01:02:55 2013 +0200
Switches the formatting of image links to default Org-mode behavior.
---
lib/org-ruby/html_output_buffer.rb | 19 ++++++++++++-------
lib/org-ruby/regexp_helper.rb | 19 ++-----------------
lib/org-ruby/textile_output_buffer.rb | 17 +++++++++++++++--
3 files changed, 29 insertions(+), 26 deletions(-)
diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index c37c966..03095e6 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -275,11 +275,7 @@ module Orgmode
end
end
end
- @re_help.rewrite_images str do |link|
- "@<a href=\"#{link}\">@<img src=\"#{link}\" />@</a>"
- end
@re_help.rewrite_links str do |link, text|
- text ||= link
link = link.sub(/^file:(.*)::(.*?)$/) do
# We don't support search links right now. Get rid of it.
@@ -292,10 +288,19 @@ module Orgmode
link = link.sub(/^file:/i, "") # will default to HTTP
- text = text.gsub(/([^\]]*\.(jpg|jpeg|gif|png))/xi) do |img_link|
- "@<img src=\"#{img_link}\" />"
+ # 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
+
+ if text =~ @re_help.org_image_file_regexp
+ text = "@<img src=\"#{text}\" alt=\"#{text}\" />"
+ end
+
+ if text
+ "@<a href=\"#{link}\">#{text}@</a>"
+ else
+ "@<img src=\"#{link}\" alt=\"#{link}\" />"
end
- "@<a href=\"#{link}\">#{text}@</a>"
end
if @output_type == :table_row
str.gsub!(/^\|\s*/, "@<td>")
diff --git a/lib/org-ruby/regexp_helper.rb b/lib/org-ruby/regexp_helper.rb
index 0e2e989..5f6825b 100644
--- a/lib/org-ruby/regexp_helper.rb
+++ b/lib/org-ruby/regexp_helper.rb
@@ -39,14 +39,8 @@ module Orgmode
# body-regexp A regexp like \".\" to match a body character. Don't use
# non-shy groups here, and don't allow newline here.
# newline The maximum number of newlines allowed in an emphasis exp.
- attr_reader :pre_emphasis
- attr_reader :post_emphasis
- attr_reader :border_forbidden
- attr_reader :body_regexp
- attr_reader :max_newlines
- attr_reader :markers
- attr_reader :org_emphasis_regexp
+ attr_reader :org_image_file_regexp
def initialize
# Set up the emphasis regular expression.
@@ -162,13 +156,6 @@ module Orgmode
str # for testing
end
- # Rewrites all of the inline image tags.
- def rewrite_images str # :yields: image_link
- str.gsub! @org_img_regexp do |match|
- yield $1
- end
- end
-
def restore_code_snippets str
str = str % @code_snippet_stack
@code_snippet_stack = []
@@ -193,10 +180,8 @@ module Orgmode
\](\[
([^\]\[]+) # This is the friendly text
\])?\]/x
- @org_img_regexp = /\[\[
- ([^\]\[]+\.(jpg|jpeg|gif|png)) # Like a normal URL, but must end with a specified extension
- \]\]/xi
@org_angle_link_text_regexp = /<(\w+:[^\]\s<>]+)>/
+ @org_image_file_regexp = /\.(gif|jpe?g|p(?:bm|gm|n[gm]|pm)|svg|tiff?|x[bp]m)/i
end
end # class Emphasis
end # module Orgmode
diff --git a/lib/org-ruby/textile_output_buffer.rb b/lib/org-ruby/textile_output_buffer.rb
index d3ff95b..5f371d0 100644
--- a/lib/org-ruby/textile_output_buffer.rb
+++ b/lib/org-ruby/textile_output_buffer.rb
@@ -55,9 +55,22 @@ module Orgmode
end
end
@re_help.rewrite_links input do |link, text|
- text ||= link
+ # 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
link = link.gsub(/ /, "%%20")
- "\"#{text}\":#{link}"
+
+ if text =~ @re_help.org_image_file_regexp
+ text = "!#{text}(#{text})!"
+ else
+ text = "\"#{text}\"" if text
+ end
+
+ if text
+ "#{text}:#{link}"
+ else
+ "!#{link}(#{link})!"
+ end
end
@re_help.rewrite_footnote input do |name, definition|
# textile only support numerical names, so we need to do some conversion
--
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