Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Anchors are generated with the deprecated attribute name instead of id #629

Open
@marrws

Description

@marrws

Describe the bug

  • Current behavior: When generating docs with anchors, the html element <a> uses the deprecated attribute name
  • Expected behavior: It should use the id attribute as the html5 spec says

This is what MDN1 says about name:

Deprecated

Was required to define a possible target location in a page. In HTML 4.01, id and name could both be used on <a>, as long as they had identical values.

This is what MDN says about id2 and fragment identification3

The id global attribute defines an identifier (ID) which must be unique in the whole document. Its purpose is to identify the element when linking (using a fragment identifier), scripting, or styling (with CSS).

How can we reproduce it?

Generate docs with the --anchor=true flag.

My guess is that this line is responsible for this behavior:

// the <a> link is purposely not sanitized as this breaks markdown formatting
return fmt.Sprintf("<a name=\"%s\"></a> [%s](#%s)", anchorName, sanitizedName, sanitizedAnchorName)

Footnotes

  1. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-name

  2. https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id

  3. https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Identifying_resources_on_the_Web#fragment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions