Edgewall Software
Modify

Ticket #992 (closed enhancement: duplicate)

Opened 7 years ago

Last modified 7 years ago

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

Reported by: trac-form@… Owned by: jonas
Priority: normal Milestone: 0.8.1
Component: wiki system Version: 0.8
Severity: normal Keywords: header anchors
Cc: manuzhai@…
Release Notes:
API 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

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

Download all attachments as: .zip

Change History

Changed 7 years ago by trac-form@…

Patch to add anchors to headings in the Wiki

Changed 7 years ago by trac-form@…

Newer version

Changed 7 years ago by trac-form@…

Version 3, with fixed wikilink pattern

comment:1 Changed 7 years ago by trac-form@…

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

comment:2 Changed 7 years ago by trac-form@…

comment:3 Changed 7 years ago by Steven N. Severinghaus <sns@…>

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 Changed 7 years ago by cmlenz

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 Changed 7 years ago by Manuzhai

  • 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 Changed 7 years ago by cmlenz

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 Changed 7 years ago by anonymous

  • Cc manuzhai@… added; manuzhai@… removed

comment:8 Changed 7 years ago by Manuzhai

Attached patch should fix all your concerns.

Well, except for the unit tests. Alas...

Changed 7 years ago by Manuzhai

cmlenz' concerns fixed.

comment:9 Changed 7 years ago by anonymous

  • Resolution set to fixed
  • Status changed from new to closed

comment:10 Changed 7 years ago by anonymous

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:11 Changed 7 years ago by cmlenz

  • Resolution set to duplicate
  • Status changed from reopened to closed

This is a duplicate of ticket #847.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
to The owner will be changed from jonas. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.