[pmwiki-users] Automatically add anchors to heading tags? pmwiki-users Digest, Vol 25, Issue 50

Petko Yotov 5ko at free.fr
Thu Jul 26 06:18:54 CDT 2007

> FWIW, the crc32 solution[1] is a simple number-link possibility that
> only seems to fall down on duplicate headings.
> Hagan
> [1] http://www.pmwiki.org/wiki/PITS/00955#checksum

If I understand correctly, people wish to have automatically created 
heading-ids in order to successfully link to individual page sections more 
easily (instead of manually adding [[#my_section]] anchors in the page). 

But these "easier" links should work both from within the (pm)wiki and from an 
external page/site, so a checksum of any kind (crc32, md5) seems not a good 
solution, one has to look at the html-source to get the id.

MediaWiki [1] has this capability from version 1.8 [2], one can link to a 
section like this:

   [[Wiki#Editing wiki pages|Click here]] will link to:

where there is a heading "==Editing wiki pages==".

The conversion algorythm heading->anchor_id is quite simple:
 - wiki to plain text (all links and styles removed)
 - whitespace trimmed ("= Title =" and "=Title=" are the same)
 - in case there is a repeated heading in the same page (including "included" 
pages), a _2 or _3 etc. is added;
 - spaces replaced with underscores;
 - the string is "urlencoded";
 - "%"-signs are replaced with dots.

This allows to have html that validates, and is very easy for the writers 
(PmWiki philosophy n°1). The conversion function works also in other 
languages, that is UTF-8 encoding: while it is not very nice in the html code 
for non-latin languages, it works both with the page table of contents and 
with links from other pages [[Page#Section name]].

If the section heading changes order, the links to it will still work (unlike 
if all anchor_ids are id1, id2...). If the section heading dissapears or 
changes, the anchor_id will also change and then the links will redirect to 
the top of the page (least surprise).

If one wishes to get a link to a section, there is the table of contents, and 
with right-click on a link he can copy the url-address (currently without a 
core TOC, for PmWiki this will be unavailable).

Personally, I am not a big supporter for this request, but if it is added, it 
should be easy for wikiwriters to link to sections in the same page, or in 
other pages, and should work with any language (removing all non-ascii won't 


[1] http://meta.wikimedia.org/wiki/Help:Link#Anchors
see the function anchorencode().

More information about the pmwiki-users mailing list