anchor names from headers (Setext and atx)?

Milian Wolff mail at milianw.de
Mon Sep 24 14:18:46 EDT 2007


Am Montag, 24. September 2007 schrieb Michel Fortin:

> Le 2007-09-22 à 14:22, Jeremy C. Reed a écrit :

> > <a name="This is an H2"/>

>

> Be careful with that. The `/>` terminator is only recognised by

> browsers when using the XML parser, which is to say when you send

> your document with an XML mime type (text/xml, application/xml,

> application/xhtml+xml). For the HTML parser (text/html), the markup

> above will be an unclosed anchor tag, and will span until the next

> opening anchor tag unless a corresponding closing tag (`</a>`) is found.

>

> If your anchor is not a link, there will be few side effects beside a

> strange DOM tree inside the browser. That's unless you have some CSS

> rule defined for tag "a". For an example of this: go to the [Markdown

> project page][1] on Daring Fireball, move your mouse pointer over the

> first words in the paragraphs following the "Discussion List" and

> "Installation and Requirements" headers and you'll see some

> unexpected rollover effects.

>

> [1]: http://daringfireball.net/projects/markdown/

>

>

> The correct way to write an anchor (so that it can be read by HTML

> parsers) is to close it with an explicit closing tag:

>

> <a name="anchor-name"></a>


Yes and no: Your markup is valid though it bloatens the markup by inserting an
empty (thus meaningless) tag to the DOM Tree. Why not simply use the ID
attribute on the correct item?

--
Milian Wolff
http://milianw.de


More information about the Markdown-Discuss mailing list