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

fix: Properly detect 'Contents' header if it includes an HTML comment #174

Merged

Conversation

hyperupcall
Copy link
Contributor

Given an Awesome Markdown file that includes the following:

...
## Contents  <!-- omit from toc -->

- [Official](#official)
- [Instances](#instances)
- [Statistics](#statistics)
- [People](#people)
- [Tools](#tools)
...

Linting fails because of the <!-- omit from toc --> comment.

$ pnpx awesome-lint
✖ Linting

  README.md:11:3
  ✖   1:1  Missing or invalid Table of Contents  remark-lint:awesome-toc
  ✖  11:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  12:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  13:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  14:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  15:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  16:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  17:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  18:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  19:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  20:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  21:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  22:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  23:3  Invalid list item link URL            remark-lint:awesome-list-item

  14 errors

(This comment is useful because it tells the Markdown All in One VSCode extension to exclude it from the auto-generated table of contents, as per Awesome Rules.)

After applying this patch, no more errors are printed.

After:

$ pnpx awesome-lint
✔ Linting

Note that the toString() function does accept an option called includeHtml, but unfortunately that did not help in this case. So this regex seemed like the next best alternative.

@hyperupcall hyperupcall changed the title fix: Properly detect 'Contents' header including an HTML comment fix: Properly detect 'Contents' header if it includes an HTML comment Oct 1, 2023
@sindresorhus sindresorhus merged commit a9c66b3 into sindresorhus:main Oct 2, 2023
0 of 3 checks passed
@hyperupcall hyperupcall deleted the hyperupcall-fix-contents-comment branch October 2, 2023 06:13
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

Successfully merging this pull request may close these issues.

2 participants