Version 8 (modified by athomas, 11 years ago) (diff)

Deprecated by Trac 0.9

Adds href anchors to section headings


The AnchorPatch automatically adds href anchors to section headings.

Anchor names are generated from the headings using the following logic:

  • The heading name with all non-alphanumeric characters stripped.
  • If the heading is not unique a numeric offset is added to the second instance, starting at 1.

For example, the heading Bugs/Feature Requests in the TocMacro page is given the anchor TocMacro#BugsFeatureRequests. This method of generating anchor names was chosen as it allows human readable use of the anchors with minimal effort. If a second heading with the same name existed, the anchor would be TocMacro#BugsFeatureRequests1.

The patch also adds support for anchors to TracLinks, as evidenced above.

Note: This patch was applied to Trac trunk in trac-changeset:1250.

Bugs/Feature Requests

Existing bugs and feature requests for AnchorPatch are here.

If you have any issues, create a new ticket.




You can check out the source for AnchorPatch from Subversion at


If you view the source of this page you will see that each of the headers has been given an anchor.


Author: athomas