Tuesday, April 14, 2009

Anchors in Trac

I had the need to use anchors today within a single page in Trac. The basic idea was to have a table of contents at the top of the page that would allow the user to link to subsections within the same page. After reading through the wikiformatting pages and google, it turns out the answer is quite simple. All of the headings are turned into anchors, whose names are the heading tokens with the spaces removed. For example, the following heading:
= My Heading =
Would be translated into the following markup:
<h2> id="MyHeading"&gtMy Heading</h2>
Within the contents section, you can link to a specific anchor via:
[wiki:somesite#MyHeading Links to My Heading Anchor]
So it turned out to be reasonably simple, just not so obvious to me at first.

No comments: