Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option "case insensitive" #147

Closed
Yuri05 opened this issue Apr 20, 2022 · 7 comments
Closed

Add option "case insensitive" #147

Yuri05 opened this issue Apr 20, 2022 · 7 comments

Comments

@Yuri05
Copy link

Yuri05 commented Apr 20, 2022

Is it possible to check anchors case insensitive or to add such an option?
E.g. when checking the html below, I get the error error: bad link test.html#Some-Section
However both links "#some-section" and "#Some-Section" should be valid in my context.
Thank you.

<h1>Test</h1>

<a href="#some-section">link</a>
<a href="#Some-Section">link</a>

<h1 id="some-section">Some section</h1>
@untitaker
Copy link
Owner

are they valid because you're using JS? the provided html snippet, pasted into a html file and opened with firefox does not have both links working

@Yuri05
Copy link
Author

Yuri05 commented Apr 20, 2022

For me both links work when opening the html e.g. in MS Edge (on Windows).
But in fact I am checking the cross references within (GitHub flavored) Markdown documents, which I convert to html first

@untitaker
Copy link
Owner

Can you try with other browsers? I don't have access to a windows machine

@Yuri05
Copy link
Author

Yuri05 commented Apr 24, 2022

As I mentioned, my primary intention is to validate cross-references in (GitHub flavored) Markdown (gfm) documents.
Here is an example: https://github.com/Yuri05/TestReport/blob/main/test.md

In this file, there one chapter and one html anchor (which is supported by gfm) are defined:

<a id="introduction_anchor"></a>
## 1 Introduction

At the beginning of the document, 4 cross-references are defined:

# Valid links
[Valid chapter link](#1-introduction) <br>
[Valid chapter link case insensitive](#1-Introduction) <br>
[Valid anchor link](#introduction_anchor) <br>
[Valid anchor link case insensitive](#Introduction_Anchor) <br>

Now when I open this md file in a browser (on Windows) - all those 4 links work (tried it with Firefox, Edge and Chrome).
But when checking the converted html: 2 links are reported as invalid because of the case sensitive check

Error: bad anchors:
  test.html#1-Introduction
  test.html#Introduction_Anchor

@untitaker
Copy link
Owner

untitaker commented Apr 25, 2022

I don't think i can help here. You are converting the Markdown to HTML in a fundamentally different way than GitHub does. GitHub uses a ton of JS to make anchors work (the resulting DOM does not contain the element IDs verbatim), and for some reason they do it case-insensitively.

I think you have two options:

  • You adjust your markdown conversion process to mimick what GitHub does to anchors, but without JS. From what I can tell this might just mean lowercasing IDs and links to anchors.
  • Use lychee, not hyperlink. It is a linkchecker that directly validates markdown files and the primary usecase is validating links in READMEs. I am not sure whether it supports anchors in markdown files, but if not, a feature request there would be more in-scope than here.

@Yuri05
Copy link
Author

Yuri05 commented Apr 25, 2022

Use lychee, not hyperlink. It is a linkchecker that directly validates markdown files and the primary usecase is validating links in READMEs. I am not sure whether it supports anchors in markdown files...

Already tried before - it does not :)

... but if not, a feature request there would be more in-scope than here.

OK.

@untitaker
Copy link
Owner

maybe this helps: https://github.com/phseiff/github-flavored-markdown-to-html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants