#992 closed enhancement (duplicate)
Heading "anchors" would be useful, particular for a TOC macro
Reported by: | 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)
Change History (16)
by , 20 years ago
Attachment: | anchors.diff added |
---|
comment:1 by , 20 years ago
The TOC macro uses this patch to automatically generate tables of contents.
comment:3 by , 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 , 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 , 20 years ago
Cc: | 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 , 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 , 20 years ago
Cc: | added; removed |
---|
comment:8 by , 20 years ago
Attached patch should fix all your concerns.
Well, except for the unit tests. Alas…
comment:9 by , 20 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:10 by , 20 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:11 by , 20 years ago
Resolution: | → duplicate |
---|---|
Status: | reopened → closed |
This is a duplicate of ticket #847.
Patch to add anchors to headings in the Wiki