image alt
This commit is contained in:
+22
-1
@@ -78,10 +78,31 @@ module Gollum
|
|||||||
name = parts[0].strip
|
name = parts[0].strip
|
||||||
|
|
||||||
if file = find_file(name)
|
if file = find_file(name)
|
||||||
%{<img src="/#{file.path}" />}
|
attrs = process_image_tag_attributes(tag)
|
||||||
|
%{<img src="/#{file.path}" #{attrs}/>}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Process any attributes present on the image tag and format them as an
|
||||||
|
# image tag fragment.
|
||||||
|
#
|
||||||
|
# tag - The String tag contents (the stuff inside the double brackets).
|
||||||
|
#
|
||||||
|
# Returns the String image tag fragment.
|
||||||
|
def process_image_tag_attributes(tag)
|
||||||
|
attrs = tag.split('|')[1..-1].inject({}) do |memo, attr|
|
||||||
|
parts = attr.split('=').map { |x| x.strip }
|
||||||
|
memo[parts[0]] = (parts.size == 1 ? true : parts[1])
|
||||||
|
memo
|
||||||
|
end
|
||||||
|
|
||||||
|
fragments = []
|
||||||
|
if alt = attrs['alt']
|
||||||
|
fragments << %{alt="#{alt}"}
|
||||||
|
end
|
||||||
|
fragments.size > 0 ? fragments.join(' ') + ' ' : ''
|
||||||
|
end
|
||||||
|
|
||||||
# Attempt to process the tag as a file link tag.
|
# Attempt to process the tag as a file link tag.
|
||||||
#
|
#
|
||||||
# tag - The String tag contents (the stuff inside the double brackets).
|
# tag - The String tag contents (the stuff inside the double brackets).
|
||||||
|
|||||||
@@ -46,6 +46,12 @@ context "Markup" do
|
|||||||
assert_equal %{<p>a <img src="/greek/alpha.jpg" /> b</p>\n}, output
|
assert_equal %{<p>a <img src="/greek/alpha.jpg" /> b</p>\n}, output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "image with alt" do
|
||||||
|
content = "a [[alpha.jpg|alt=Alpha Dog]] b"
|
||||||
|
output = %{<p>a <img src="/greek/alpha.jpg" alt="Alpha Dog" /> b</p>\n}
|
||||||
|
relative_image(content, output)
|
||||||
|
end
|
||||||
|
|
||||||
test "file link with absolute path" do
|
test "file link with absolute path" do
|
||||||
index = @wiki.repo.index
|
index = @wiki.repo.index
|
||||||
index.add("alpha.jpg", "hi")
|
index.add("alpha.jpg", "hi")
|
||||||
@@ -68,4 +74,14 @@ context "Markup" do
|
|||||||
assert_equal %{<p>a <a href="/greek/alpha.jpg">Alpha</a> b</p>\n}, output
|
assert_equal %{<p>a <a href="/greek/alpha.jpg">Alpha</a> b</p>\n}, output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def relative_image(content, output)
|
||||||
|
index = @wiki.repo.index
|
||||||
|
index.add("greek/alpha.jpg", "hi")
|
||||||
|
index.add("greek/Bilbo-Baggins.md", content)
|
||||||
|
index.commit("Add alpha.jpg")
|
||||||
|
|
||||||
|
page = @wiki.page("Bilbo Baggins")
|
||||||
|
rendered = Gollum::Markup.new(page).render
|
||||||
|
assert_equal output, rendered
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user