[pmwiki-users] Setting an id-tag to a 2nd level heading and removing "name=" in anchor
Patrick R. Michaud
pmichaud at pobox.com
Tue Mar 22 14:06:11 CDT 2011
On Tue, Mar 22, 2011 at 05:56:09PM +0000, Hans wrote:
> Tuesday, March 22, 2011, 5:21:52 PM, Martin Kerz wrote:
> > is it possible to ad an id-tag to a 2nd level heading?
> > I need html that looks like this:
> > <h2 id="heading">Heading</h2>
>
> This may work for you:
> add to config:
>
> ## headings with id
> Markup('^!id!', '<^!',
> '/^(!{1,6})([A-Za-z][-.:\\w]*)!\\s?(.*)$/e',
> "'<:block,1><h'.strlen('$1').' id=\"$2\"'.PSS('>$3</h').strlen('$1').'>'");
>
> and in a page use like this:
> [...]
If you just need an id tag for navigation (i.e., it doesn't have
to be an attribute on the heading itself), then the canonical
markup is:
!! [[#heading]] Heading
This produces <h2><a id="heading"></a>Heading</h2>, and also
allows the section to be extracted via (:include:).
If you really need it *in* the <h2> tag, you can do:
!! %block id=heading% Heading
This produces <h2 id="heading">Heading</h2> (which I believe is
what you wanted). One can create WikiStyle shortcuts to reduce
the typing needed for %block%.
If creating a new markup (per Hans' suggestion), I strongly
suggest retaining the use of '#' to indicate tag identifiers
(since that's what is used in urls and CSS):
Markup('^!#id', '<^!',
'/^(!{1,6})#([A-Za-z][-.:\\w]*)\\s(.*)$/e',
"'<:block,1><h'.strlen('$1').' id=\"$2\"'.PSS('>$3</h').strlen('$1').'>'");
This enables a markup like
!!#heading Heading
to produce
<h2 id="heading">Heading</h2>
Pm
More information about the pmwiki-users
mailing list