[DRE-commits] [ruby-org] 84/303: Added support for inline images
Jérémy Bobbio
lunar at alioth.debian.org
Fri Aug 9 17:33:32 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 c0d0aa0e13cf62bdb19ae5c2156ee32a5587435e
Author: Brian Dewey <bdewey at gmail.com>
Date: Mon Feb 15 23:06:57 2010 -0800
Added support for inline images
---
.gitignore | 1 +
lib/org-ruby/html_output_buffer.rb | 3 +++
lib/org-ruby/regexp_helper.rb | 15 ++++++++++++++-
spec/html_examples/inline-images.html | 10 ++++++++++
spec/html_examples/inline-images.org | 15 +++++++++++++++
5 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6911c29
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.tmproj
\ No newline at end of file
diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index 6199d7e..9d094ff 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -145,6 +145,9 @@ module Orgmode
str = @re_help.rewrite_emphasis(str) do |marker, s|
"#{Tags[marker][:open]}#{s}#{Tags[marker][:close]}"
end
+ str = @re_help.rewrite_images(str) do |link|
+ "<img src=\"#{link}\" />"
+ end
str = @re_help.rewrite_links(str) do |link, text|
text ||= link
link = link.sub(/^file:(.*)::(.*?)$/) do
diff --git a/lib/org-ruby/regexp_helper.rb b/lib/org-ruby/regexp_helper.rb
index 7da41a9..e03512d 100644
--- a/lib/org-ruby/regexp_helper.rb
+++ b/lib/org-ruby/regexp_helper.rb
@@ -14,6 +14,9 @@ module Orgmode
#
# * Use +rewrite_links+ to get a chance to rewrite all org-mode
# links with suitable markup for the output.
+ #
+ # * Use +rewrite_images+ to rewrite all inline image links with suitable
+ # markup for the output.
class RegexpHelper
######################################################################
@@ -121,7 +124,7 @@ module Orgmode
# +http://www.hotmail.com+. In both cases, the block returns an
# HTML-style link, and that is how things will get recorded in
# +result+.
- def rewrite_links(str)
+ def rewrite_links(str) # :yields: link, text
i = str.gsub(@org_link_regexp) do |match|
yield $1, nil
end
@@ -129,6 +132,13 @@ module Orgmode
yield $1, $2
end
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
private
@@ -146,6 +156,9 @@ module Orgmode
@org_link_regexp = /\[\[
([^\]]*) # This is the URL
\]\]/x
+ @org_img_regexp = /\[\[
+ ([^\]]*\.(jpg|jpeg|gif|png)) # Like a normal URL, but must end with a specified extension
+ \]\]/xi
@org_link_text_regexp = /\[\[
([^\]]*) # This is the URL
\]\[
diff --git a/spec/html_examples/inline-images.html b/spec/html_examples/inline-images.html
new file mode 100644
index 0000000..e31af9f
--- /dev/null
+++ b/spec/html_examples/inline-images.html
@@ -0,0 +1,10 @@
+<p class="title">Inline Images</p>
+<p>Per the org-mode <a href="http://orgmode.org/manual/Images-and-tables.html#Images-and-tables">spec</a>, you can include inline images as links without any descriptive link text, like this:</p>
+<p><img src="http://farm5.static.flickr.com/4049/4358074549_5efb8b4903.jpg" /></p>
+<p>I currently do not support the caption/link syntax, but I can include the inline image. I recognize the following image file types:</p>
+<ul>
+ <li>.jpg</li>
+ <li>.png</li>
+ <li>.gif</li>
+ <li>.jpeg</li>
+</ul>
diff --git a/spec/html_examples/inline-images.org b/spec/html_examples/inline-images.org
new file mode 100644
index 0000000..9bb1608
--- /dev/null
+++ b/spec/html_examples/inline-images.org
@@ -0,0 +1,15 @@
+Inline Images
+
+Per the org-mode [[http://orgmode.org/manual/Images-and-tables.html#Images-and-tables][spec]], you can include inline images as links without
+any descriptive link text, like this:
+
+[[http://farm5.static.flickr.com/4049/4358074549_5efb8b4903.jpg]]
+
+I currently do not support the caption/link syntax, but I can include
+the inline image. I recognize the following image file types:
+
+- .jpg
+- .png
+- .gif
+- .jpeg
+
--
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