- $page.="$text<a name=\"$anchor\" />";
-
- # Take the first header level seen as the topmost level,
+ $page.="$text<a name=\"$anchor\"></a>";
+ # if the heading already has a unique ID, use that instead in TOC
+ if ($attr->{id}) {
+ $anchor = $attr->{id};
+ }
+
+ # Unless we're given startlevel as a parameter,
+ # take the first header level seen as the topmost level,