From 8cca294c255d32dee2daeeb4a8ef3d344a16bf19 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Mon, 19 Apr 2010 16:11:43 -0700 Subject: [PATCH] fix img vert and horiz align --- lib/gollum/markup.rb | 14 ++++++++------ test/test_markup.rb | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index 1c3204fb..ef13e1c2 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -80,22 +80,24 @@ module Gollum if file = find_file(name) opts = parse_image_tag_options(tag) - floated = false + containered = false classes = [] # applied to whatever the outermost container is attrs = [] # applied to the image styles = [] # applied to the image + align = opts['align'] if opts['float'] - floated = true - align = opts['align'] || 'left' + containered = true + align ||= 'left' if %w{left right}.include?(align) classes << "float-#{align};" end elsif %w{top texttop middle absmiddle bottom absbottom baseline}.include?(align) - attrs << "align=#{align}" - elsif align = opts['align'] + attrs << %{align="#{align}"} + elsif align if %w{left center right}.include?(align) + containered = true classes << "align-#{align}" end end @@ -123,7 +125,7 @@ module Gollum style_string = %{ style="#{styles.join(' ')}"} end - if opts['frame'] || floated + if opts['frame'] || containered classes << 'frame' if opts['frame'] %{
} + %{
} + diff --git a/test/test_markup.rb b/test/test_markup.rb index e2a51c7d..3391b245 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -70,6 +70,22 @@ context "Markup" do end end + test "image with vertical align" do + %w{top texttop middle absmiddle bottom absbottom baseline}.each do |align| + content = "a [[alpha.jpg|align=#{align}]] b" + output = "

a b

\n" + relative_image(content, output) + end + end + + test "image with horizontal align" do + %w{left center right}.each do |align| + content = "a [[alpha.jpg|align=#{align}]] b" + output = "

a

b

\n" + relative_image(content, output) + end + end + test "image with float" do content = "a\n\n[[alpha.jpg|float]]\n\nb" output = "

a

\n\n

\n\n

b

\n"