00681: Allow padding and borders on images, again

Summary: Allow padding and borders on images, again
Created: 2006-03-02 10:28
Status: Closed - already exists
Category: Feature
From: RJM
Assigned:
Priority: 554
Version: 2.1.beta30
OS:

Description:

20060227: There is apparently no documentation about these attributes. Meanwhile I found that the *width* and *height* attributes are automatically embedded in a *img* tag, when these wikistyles are placed just before an *Attach:* command.

To V2.1b30 I have changed following lines in *wikistyles.php*, in order to allow *class* to be embedded in *img*, too. This allows truly flexibility with image attributing (lines 132/137):

        if (($k=='class' || $k=='width' || $k=='height') && !@$WikiStyleApply[$a]
            && preg_match('/\\s*<img\\b/', $p)) 
          $p = preg_replace("/<img(?![^>]*\\s$k=)/", "<img $k='$v'", $p);
        elseif ($k == 'class' && $v) $spanattr = "class='$v'";
        elseif ($k=='id') $id = preg_replace('/\W/', '_', $v);

In a test, this works fine, e.g. %img-border%Attach:image.jpg"name"

However, a few questions arise: pmwiki2.1b30, pmwiki.php:
line 157: img { border:0px; }

  • probably defined here in order to provide better browser compatibility? - but now any definition of *img* in CSS is blocked.

(This text originally appeared in PITS:00257; I reopened it as a new issue. --Pm)

One can already get a class= attribute to appear in an <img> tag by explicitly designating it that way:

%apply=img img-border% Attach:pmwiki-32.gif

This also works for other wikistyle attributes:

%apply=img padding-left:20px background-color:#999999% Attach:pmwiki-32.gif

As far as any definition of img in CSS being blocked -- that's not at all true, more specific selectors will always override the img selector, and any later stylesheet can override PmWiki's default.

--Pm

Thanks for this additional information. Nevertheless, I'd suggest to alter the code as proposed above, since non defined wikistyle keywords are automatically interpreted as class names. This is simpler to handle than the apply keyword. I have wikisites in mind, where non-experienced users shall be able to add images in a certain 'corporate' style.

Where I find time, I will update the relevant documentation pages regarding images.

--RJM

If there's a certain 'corporate' style involved, then the site administrator should probably define a custom wikistyle that already includes the 'apply=' component. For example:

    %define=corporate class=corporate apply=img%

Then, an author wanting to display an image in the corporate style will simply use

    %corporate% Attach:pmwiki-32.gif

and the corporate class (as well as any other attributes defined for the corporate wikistyle) will automatically be attached to the image tag.

--Pm

I see that CustomStyleShortcuts can be defined group-wide and site-wide. For site-wide definitions, config.php should contain a corresponding definition, according to LocalCustomizations. However, I don't know how to specify it here.
BTW: This method is ok, since this enables specifying the image border properties without CSS. However, a patch as proposed above will allow the administrator the choice of CSS specification and/or a separate wikistyle definition.

One may have a look on a test site, which uses a site-wide border (although currently using the patch as above)
[(approve links) edit diff]

-- RJM