[dokuwiki] Re: Is it possible to set anchors for headers

  • From: Frank Thommen <list.dokuwiki@xxxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Wed, 22 May 2019 19:15:07 +0200

On 5/8/19 10:08 AM, Martin Burnicki wrote:

Frank Thommen wrote:
The problem with "anchors" is, that it doesn't integrate with the header
syntax and the anchors will not be used for the automatic TOC.  Ideally
something like

    ====== My Title {{anchor:title1}} ======

could be used.  With anchors I need

    ====== My Title ======

That's a lot of work and additional Wikitext.

I fully agree.


I have managed to get custom anchors, using the following syntax:

    ====== My Title | my_anchor ======

I modified some of the DW files for this:

inc/parser/xhtml.php -> header(): Add

        if (preg_match("/(.*)\s*\|/", $text, $matches)) {
            $text = $matches[1];

just before "$this->doc .= DOKU_LF.'<h'.$level;"

inc/html.php -> html_mktocitem(): Insert

    if (preg_match("/(.*)\s*\|/", $text, $matches)) {
        $text = $matches[1];

right at the beginning of the function.

inc/pageutils.php -> sectionID(): Insert

    if  (preg_match("/.*\|\s*([^\s=]+)/", $title, $matches)) {
        $title = $matches[1];

right at the beginning of the function.

That's the places that I found, where headers and TOCs are created. However I don't know wether these are the really appropriate places and if the suggested syntax goes ok for DokuWiki policies. If it does, then I'd be happy to post a feature request and a pull request. Maybe one of the developers can comment on these points?


DokuWiki mailing list - more info at

Other related posts: