Edgewall Software
Modify

Opened 20 years ago

Closed 20 years ago

Last modified 12 years ago

#992 closed enhancement (duplicate)

Heading "anchors" would be useful, particular for a TOC macro

Reported by: trac-form@… Owned by: Jonas Borgström
Priority: normal Milestone:
Component: wiki system Version: 0.8
Severity: normal Keywords: header anchors
Cc: manuzhai@… Branch:
Release Notes:
API Changes:
Internal Changes:

Description

This patch adds anchors for headings, simply by transforming the heading name into a name with only alphanumeric values.

This would be very useful for a table of contents macro (which is phase 2 of The Plan).

eg.

= Some heading =

becomes

<a name="Someheading"><h1>Some heading</h1></a>

Attachments (4)

anchors.diff (846 bytes ) - added by trac-form@… 20 years ago.
Patch to add anchors to headings in the Wiki
anchors.2.diff (3.9 KB ) - added by trac-form@… 20 years ago.
Newer version
anchors.3.diff (3.9 KB ) - added by trac-form@… 20 years ago.
Version 3, with fixed wikilink pattern
headingids.diff (3.7 KB ) - added by Manuzhai 20 years ago.
cmlenz' concerns fixed.

Download all attachments as: .zip

Change History (16)

by trac-form@…, 20 years ago

Attachment: anchors.diff added

Patch to add anchors to headings in the Wiki

by trac-form@…, 20 years ago

Attachment: anchors.2.diff added

Newer version

by trac-form@…, 20 years ago

Attachment: anchors.3.diff added

Version 3, with fixed wikilink pattern

comment:1 by trac-form@…, 20 years ago

The TOC macro uses this patch to automatically generate tables of contents.

comment:3 by Steven N. Severinghaus <sns@…>, 20 years ago

After patching, I changed the nesting of the anchor tag and the heading tag, since it is technically invalid to have the block-level heading inside the inline-level anchor. If you run the page the the W3 Validator, you'll see what I mean. The net result is <h#><a name="Foo">Foo</a></h> instead, and there don't seem to be any negative side effects. I would suggest this be incorporated into the anchor patch.

comment:4 by Christopher Lenz, 20 years ago

I see a couple of issues with this patch (version 3):

  • You change Href.py to include the anchor in the generated link. However, you put the anchor before the query string parameters, which doesn't work, i.e. the query string parameters will never be transmitted to the server if they come after the anchor.
  • The section names should really be unique, but the patch doesn't appear to enforce uniqueness in any way.
  • For that matter, I'd prefer the anchors to be implemented as id attributes on the headings themselves, instead of using additional <a name> tags. Simple saves a couple of bytes and is a bit cleaner IMHO.
  • It would be really cool if the patch would also include unit tests ;-)

comment:5 by Manuzhai, 20 years ago

Cc: manuzhai@… added

Does that even work, using id attributes on the headings? Does it get the behavior that you can use them in the URL as a fragment (after the #), and the browser automatically goes for that section? Because I'm fairly sure that only works for <a name>.

comment:6 by Christopher Lenz, 20 years ago

It works. See Anchors with the id attribute in the HTML 4 specification.

Also, see the XHTML 1 specification, which states in The elements with 'id' and 'name' attributes:

Note that in XHTML 1.0, the name attribute of these elements
is formally deprecated, and will be removed in a subsequent
version of XHTML.

comment:7 by anonymous, 20 years ago

Cc: manuzhai@… added; manuzhai@… removed

comment:8 by Manuzhai, 20 years ago

Attached patch should fix all your concerns.

Well, except for the unit tests. Alas…

by Manuzhai, 20 years ago

Attachment: headingids.diff added

cmlenz' concerns fixed.

comment:9 by anonymous, 20 years ago

Resolution: fixed
Status: newclosed

comment:10 by anonymous, 20 years ago

Resolution: fixed
Status: closedreopened

comment:11 by Christopher Lenz, 20 years ago

Resolution: duplicate
Status: reopenedclosed

This is a duplicate of ticket #847.

comment:12 by Christian Boos, 12 years ago

Milestone: 0.8.1

(clearing report:35)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jonas Borgström.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jonas Borgström to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.