[pmwiki-users] Marking up the markup

Patrick R. Michaud pmichaud at pobox.com
Thu Apr 26 10:08:53 CDT 2007


On Wed, Apr 25, 2007 at 05:46:16PM -0400, DaveG wrote:
> I have another piece of code that I'm making use of which works based on 
> classes, picking up objects from the DOM based on class.
> 
> I'd have thought that adding a class to an anchor is not something out 
> of the usual.

The way that PmWiki would normally handle this would be with
a wikistyle... i.e., something like:

    %class=myclass apply=link% [[link]]

Unfortunately, getting apply=link to work properly here is
a bit tricky.  We can't just insert class='myclass' into
any <a ...> tag that follows, because the <a> tag might 
already have a class= attribute.  (Nearly all of PmWiki's
<a> tags have classes on them already.) 

So, the wikistyles code then has to be smart enough to

   - find any link tag
   - see if the link tag already has a class= attribute
   - if yes, then insert 'myclass' into the existing
     class= attribute (at the beginning? at the end?)
   - if no, then add class='myclass' into the <a> tag

While this can be done, it's not exactly trivial, and thus
PmWikiPhilosophy #3 applies.  Also, if someone is simply using 
classes for styling, then it's much easier to say 
"use 'span.class a' in the stylesheet", especially since the 
resulting markup is also simpler -- i.e., %myclass% [[link]] 
instead of %myclass apply=link% [[link]].

So yes, adding classes to anchors from markup is a bit on
the unusual side for PmWiki.  It's not at all an unreasonable
thing for a web designer to want to do... it just hasn't
met the threshhold of providing enough benefit for the amount
of work and code involved.

Hope this helps,

Pm


> Kathryn Andersen wrote:
> > On Wed, Apr 25, 2007 at 05:22:09PM -0400, DaveG wrote:
> >> Anyone help? I need to get a class tag inside an anchor link:
> >>       <a href="xyz" class="my_class">text</a>
> > 
> > Why?  What is the problem with having a class tag in a span around an
> > anchor link?
> > 
> >        <span class="my_class"><a href="xyz">text</a></span>
> > 
> > If you need to style the anchor with CSS, then the only difference is
> > that you would do something like this:
> > 
> > span.my_class a { ... }
> > 
> > rather than
> > 
> > a.my_class { ... }
> > 
> > It should still work perfectly well.
> > 
> > Kathryn Andersen
> 
> _______________________________________________
> pmwiki-users mailing list
> pmwiki-users at pmichaud.com
> http://www.pmichaud.com/mailman/listinfo/pmwiki-users



More information about the pmwiki-users mailing list