Skip to content

Anchors in attr_list contains other attribute value are reported as invalid urls #42

@try0

Description

@try0

Describe the bug

For example, the following header is reported as invalid url.

## Header {: #header-anchor .class-name }

anchor_slug: header-anchor-class-name

https://github.com/manuzhang/mkdocs-htmlproofer-plugin/blob/main/htmlproofer/plugin.py#L154

@staticmethod
def contains_anchor(markdown: str, anchor: str) -> bool:
    """Check if a set of Markdown source text contains a heading that corresponds to a
    given anchor."""
    for line in markdown.splitlines():
        # Markdown allows whitespace before headers and an arbitrary number of #'s.
        heading_match = HEADING_PATTERN.match(line)
        if heading_match is not None:
            heading = heading_match.groups()[0]

            # Headings are allowed to have images after them, of the form:
            # # Heading [![Image](image-link)] or ![Image][image-reference]
            # But these images are not included in the generated anchor, so remove them.
            heading = re.sub(IMAGE_PATTERN, '', heading)
            anchor_slug = slugify(heading, '-')
            if anchor == anchor_slug:
                return True

        link_match = HTML_LINK_PATTERN.match(line)
        if link_match is not None and link_match.group(1) == anchor:
            return True

    return False

mkdocs.yml

markdown_extensions:
  - attr_list

plugins:
  - htmlproofer

Would it be possible to support attr_list extensions format?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions