[pmwiki-users] Tip: having <h1 id> instead of <a name>

porneL mailinglist at pornel.net
Tue Feb 28 04:11:58 CST 2006


I've made a tweak I could share:

On my setup PMWiki translates [[#xx]] into:
<p><a name='xx' id='xx'></p>

which creates empty element and empty paragraph... not very nice.

Here's a bit of code for config.php.

// [[#xx]] stores ID in internal variable:

Markup('[[#','<[[','/(?>\\[\\[#([A-Za-z][-.:\\w]*))\\]\\]/e',
   "NewAnchor(\"$1\")");

$LastAnchor=NULL;
function NewAnchor($a)
{
   global $LastAnchor;
   $out="<:block>";
   if ($LastAnchor) $out = Keep("<div id='$LastAnchor'></div>",'L');
   $LastAnchor = $a;
   return $out;
}

// and outputs this variable whenever heading is inserted:

Markup('^!', 'block',  '/^(!{1,6})\\s?(.*)$/e',
   "'<:block,1><h'.strlen('$1').OutAnchor().PSS('>$2</h').strlen('$1').'>'");

function OutAnchor()
{
   global $LastAnchor;
   $out = '';
   if ($LastAnchor) {$out = " id='$LastAnchor'"; $LastAnchor=NULL;}
   return $out;
}


So Wiki:

[[#something]]
!!Hello

creates HTML:
<h2 id='something'>Hello</h2>

The downside is that [[#xx]] has to be before some heading.

Installed on http://kurs.browsehappy.pl

-- 
regards, porneL




More information about the pmwiki-users mailing list