Support align attribute for img with caption
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 5 Jan 2010 14:23:22 +0000 (15:23 +0100)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 6 Jan 2010 20:02:09 +0000 (21:02 +0100)
This is achieved by preparing CSS definitions that emulates the behavior
of the align attribute, and passing it to the outermost IMG wrapper
(A or TABLE) instead of passing the align value to IMG directly.

IkiWiki/Plugin/img.pm
doc/style.css

index 32023fa97af8ba8e63192cacaff10a4677d20654..6f1919ea04a5621a94a1fae2e746c2d7600411af 100644 (file)
@@ -155,16 +155,23 @@ sub preprocess (@) {
                '" height="'.$dheight.'"'.
                (exists $params{alt} ? ' alt="'.$params{alt}.'"' : '').
                (exists $params{title} ? ' title="'.$params{title}.'"' : '').
-               (exists $params{align} ? ' align="'.$params{align}.'"' : '').
                (exists $params{class} ? ' class="'.$params{class}.'"' : '').
                (exists $params{id} ? ' id="'.$params{id}.'"' : '').
                ' />';
 
        if (! defined $params{link} || lc($params{link}) eq 'yes') {
-               $imgtag='<a href="'.$fileurl.'">'.$imgtag.'</a>';
+               if (exists $params{caption} || !exists $params{align}) {
+                       $imgtag='<a href="'.$fileurl.'">'.$imgtag.'</a>';
+               } else {
+                       $imgtag='<a href="'.$fileurl.'" class="align-'.$params{align}.'">'.$imgtag.'</a>';
+               }
        }
        elsif ($params{link} =~ /^\w+:\/\//) {
-               $imgtag='<a href="'.$params{link}.'">'.$imgtag.'</a>';
+               if (exists $params{caption} || !exists $params{align}) {
+                       $imgtag='<a href="'.$params{link}.'">'.$imgtag.'</a>';
+               } else {
+                       $imgtag='<a href="'.$params{link}.'" class="align-'.$params{align}.'">'.$imgtag.'</a>';
+               }
        }
        else {
                my $b = bestlink($params{page}, $params{link});
@@ -173,12 +180,16 @@ sub preprocess (@) {
                        add_depends($params{page}, $b, deptype("presence"));
                        $imgtag=htmllink($params{page}, $params{destpage},
                                $params{link}, linktext => $imgtag,
-                               noimageinline => 1);
+                               noimageinline => 1,
+                               (exists $params{caption} || !exists $params{align}) ?
+                                       () : (class => 'align-'.$params{align}));
                }
        }
 
        if (exists $params{caption}) {
-               return '<table class="img">'.
+               return '<table class="img'.
+                       (exists $params{align} ? ' align-'.$params{align} : '').
+                       '">'.
                        '<caption>'.$params{caption}.'</caption>'.
                        '<tr><td>'.$imgtag.'</td></tr>'.
                        '</table>';
index be86a081870be1ff1b48eb6d194e253535d14044..c56494fffb9c42bc1c263fef1d4ba3a9f16eff1c 100644 (file)
@@ -82,6 +82,26 @@ div.tags {
        text-align: center;
 }
 
+.align-left {
+       float:left;
+}
+
+.align-right {
+       float:right;
+}
+
+.align-top {
+       vertical-align:top;
+}
+
+.align-bottom {
+       vertical-align:bottom;
+}
+
+.align-middle {
+       vertical-align:middle;
+}
+
 #backlinks {
        margin-top: 1em;
 }