[Home]WikiPatches/ImageTags

UseModWiki | WikiPatches | RecentChanges | Preferences

This patch implements the following markup:
 @x@imagename.extension
Where "X" is one of l,r,i for image alignment and "extension" is one of "gif|jpg|png|jpeg".

It's in operation on the UnrealWiki.

Note: I've since altered this patch to create IMG CLASS="blah" instead of ALIGN="blah". Alignement options can then be set in CSS. "Display:block" is particularly useful I found.

Contact: Unreal:Tarquin

Ideas

This could be extended quite a bit to allow classes of image, by adding new options for the "x" part of the markup.

Patch

variables

  1. new options added by tarquin
$ImgUrl? = "../wiki-img/"; # path to image files as used by the @X@ markup

Set this in config too.

sub CommonMarkup

Insert this at the end of sub CommonMarkup. I've put it within the "if ($doLines)" block, but I have to admit I'm not sure why...
 # tarq: @x@ markup for images
 s/(\@[lri]\@)(\S+\.(gif|jpg|png|jpeg))\s/&GetImgTag($1, $2)/gei ;

new sub

I've inserted this just before "sub WikiToHTML".
	# ###### tarq: this makes an IMG tag
	sub GetImgTag{
	  my( $AlignLetter, $PicName ) = @_ ;
	  my( $AlignFull , $ImgTag );

	  #$AlignFull =
	  #    {"l" => "left", "r" => "right", "i" => "inline"}->{lc $AlignLetter};
	  #print "Alignfull is: " . $AlignFull . "\n" ;
	  if( $AlignLetter =~ /l/i ){
	    $AlignFull = "left";
	    } elsif( $AlignLetter =~ /r/i ){
	    $AlignFull = "right";
	    } elsif( $AlignLetter =~ /i/i ){
	     $AlignFull = "middle";
	    }
	  # make sure to cover all possibilities matched in the calling search.
	  $ImgTag = '<img align="' . $AlignFull . '" src="' . $ImgUrl . $PicName . '"> ';
	  return $ImgTag ;
	}
	# ###### end tarq


Could you extend this to accept a remote image (not local), in the way: @x@location/imagename.extension

Have the sub process its $PicName? to look for an initial HTTP. Roughly:
Yes, but that will be broken by the UseMod already existing image inclusion, which will need to be disabled for this to work. The original checks for mailto:'s and other potential missusages, which the code below does not.... hmmm...

Ok, I came up with this:

# Restricted image URLs so that mailto:foo@bar.gif is not an imag
  if ($useImage && ($name =~ /^(http:|https:|ftp:).+\.$ImageExtensions$/)) {
-   return ("<img src=\"$name\">",$punct);
+   return ("$name", $punct);
  }

And then I modified the sub below like this:

	# ###### tarq: this makes an IMG tag
sub GetImgTag {
          my($AlignLetter, $PicName) = @_ ;
          my($AlignFull , $ImgTag);
  
         if ($AlignLetter =~ /l/i) {
          $AlignFull = "left";
         } 
         elsif ($AlignLetter =~ /r/i) {
          $AlignFull = "right";
         } 
         elsif ($AlignLetter =~ /i/i) {
           $AlignFull = "middle";
         }
        # make sure to cover all possibilities matched in the calling search.
         if ($PicName =~ /^(http:|https:|ftp:).+\.$ImageExtensions$/) {
            $ImgTag = '<img align="' . $AlignFull . '" src="' . $PicName . '"> ';
            return $ImgTag;
         }
         else { 
            $ImgTag = '<img align="' . $AlignFull . '" src="' . $ImgUrl . $PicName . '"> ';
            return $ImgTag;
         }
}
	# ###### end tarq

Now I can align local images and remote ones :-) . Thanks!


There is a one more patch for images, simplier and with different syntax: WikiPatches/ImageTagsAlt

--FerdinandPrantl


UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited March 28, 2005 11:32 pm by MarkusLude (diff)
Search: