mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-04-26 01:36:03 +03:00
[PR #1117] [MERGED] feat: support line number in fragment in MD051/link-fragments (e.g: '#L7') #3083
Labels
No labels
bug
enhancement
enhancement
enhancement
fixed in next
fixed in next
fixed in next
new rule
new rule
new rule
pull-request
question
refactoring
refactoring
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/markdownlint#3083
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/DavidAnson/markdownlint/pull/1117
Author: @theoludwig
Created: 1/31/2024
Status: ✅ Merged
Merged: 2/10/2024
Merged by: @DavidAnson
Base:
next← Head:feat/support-line-number-in-fragment📝 Commits (2)
4307342Update MD051/link-fragments to support GitHub-style line/column range syntax in URLs (refs #1117).d6d091eRefine previous commit for MD051/link-fragments to tweak behavior, tests, and documentation.📊 Changes
8 files changed (+440 additions, -26 deletions)
View changed files
📝
demo/markdownlint-browser.js(+3 -1)📝
doc-build/md051.md(+26 -0)📝
doc/Rules.md(+26 -0)📝
doc/md051.md(+26 -0)📝
lib/md051.js(+4 -2)📝
test/link-fragments.md(+44 -0)📝
test/snapshots/markdownlint-test-scenarios.js.md(+311 -23)📝
test/snapshots/markdownlint-test-scenarios.js.snap(+0 -0)📄 Description
Hello! 😄
I'm the original author of the rule MD051, work started in this PR: https://github.com/DavidAnson/markdownlint/pull/495.
I'm also the author of https://github.com/theoludwig/markdownlint-rule-relative-links custom rule.
This custom rule, verify if relative links exists in the file system using Node.js
node:fs, it also checks for links fragments referencing other files (similar to the rule MD051, by trying to have as much as possible the same behavior as the MD051 built-in rule in this regard).GitHub supports links fragments for referring to a specific line, e.g:
#L7means "Go To Line 7`.More context: https://github.com/theoludwig/markdownlint-rule-relative-links/issues/6
Currently MD051 reports an error for that kind of fragments, but it should not, as they are valid on GitHub.
This PR fixes the issue, similarly to how it is done in
markdownlint-rule-relative-links.In the custom rule, we can go even further and check if the file has enough lines to be a valid line number reference (e.g:
#L7in a empty file, is invalid, as line 7 doesn't exist), but that needs access to Node.jsnode:fs, which as far as I understand, you don't want to use for built-in rule for compatibility with the browser. So for now we're just considering it's valid without extra checks.Feel free to suggest ideas, suggest better implementation, or maybe you have ideas of more test cases to add?
Thanks!
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.