-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Support linking to anchors in directories #49
Comments
This won’t be trivial, but, may be doable, and is useful!
|
I just tested again, and you're absolutely correct. Either my memory trolled me or GitHub changed this.
Definitely. But GitHub still allows you to have a
Sorry, couldn't really follow you on that. Would you mind to rephrase or elaborate on this? 🙂 |
👍 We process every file to find outgoing links and defined links. |
Oh okay, I think I got it. So instead of internally resolving the directory to the readme file as I suggested, we'd do it the other way around and internally copy over the found anchors from each readme to its corresponding directory? |
Yes! So, paths to folders currently fail, we fix them, by loading a correct readme. This solves the case where links are mixed: both to a readme, and to its folder. Only need to process that file once. |
Sounds good. I'll take a look and attach a PR if I manage to wrap my head around it. 😉 |
One more concern I just came up with: If we want to detect a readme file in a folder, we'd have to read all files in the directory and match them against the readme pattern. This might become a performance concern with really big folders. Do you think it would be worth it to check for for the most common |
Hmm, One potential approach is 🤷♂️ I don’t know! Maybe just go with the simplest approach and see if there are bottlenecks later? We can always fix it in the future. |
Alright, potential case of YAGNI detected. 😁 |
Ok, I'm a bit stuck and need a little heads-up: Given I don't want to do a major program flow change to the plugin, I'll have to detect readme files inside the Is it fine to do it there using the I'm asking because I don't know what the browser support story is for this module and how it relates to |
I would suggest using adding a I think actual fs access can go in check-files.js, which already has a simplified version for browsers? |
That's pretty much where I'm stuck. My latest approach was roughly like "inject the file set into the check-files.js and add the readme vfile from there". This works in part as the added file will actually go through a To be honest, I'm not sure whether it's a good idea for me to finish up this issue. I'm not too confident working with Node streams and not at all familiar with how remark works overall — I'll probably cause you more work by live-learning these things and then delivering a mediocre solution than I would if I left the implementation to you. 🙈 |
🤗 alright, thanks for working on it! And for helping figure out a solution. I'm away for the weekend so can't code on it now. But I'll get to it soon! |
No hurry, thanks for offering all these great packages in the first place. 😁 Looking forward to how you're going to approach this, I'll probably learn more about remark from the resulting code diff than from the last hours of reading the existing code. 😉 |
By the way, here is the markdown file that I added to my branch for future tests of this feature. All links containing the term "invalid" should produce some kind of warning, all others should pass. (The link to the project root at the end of the file might be a bit odd, but it's there to prevent regression of a currently present bug: Linking to the project root at some point leads to effectively calling |
Previously, a link to a directory such as `folder#anchor`, didn’t work. This commit adds support for, in such a case: 1. Loading the particular readme file that vendors such as GitHub, GitLab, and BitBucket display as an index on those page 2. For every processed file that is a readme of a directory, marking its anchors as valid Closes GH-49.
Previously, a link to a directory such as `folder#anchor`, didn’t work. This commit adds support for, in such a case: 1. Loading the particular readme file that vendors such as GitHub, GitLab, and BitBucket display as an index on those page 2. For every processed file that is a readme of a directory, marking its anchors as valid Closes GH-49. Closes GH-50.
Subject of the feature
Linking directly to folders, showing the folder's readme, is supported by all three supported Git hosts — GitHub, Gitlab and Bitbucket, and also by this plugin.
However, this plugin considers anchors appended to those directory links invalid without checking (reported as
missing-heading-in-file
).Problem
Linking to a section in a folder's readme directly (without linking explicitly to the readme file) is a pattern I like to use a lot in larger projects. It works perfectly fine in GitHub and Gitlab and should therefore not be reported as an issue by this plugin. (It should theoretically work in BitBucket as well since that also renders the readme below a directory's file list. But since BitBucket behaves more like an SPA it generally has trouble with anchors in cross-folder links.)
Expected behaviour
When provided a directory link with a hash, this plugin should consider that a link to the
README.md
of that folder and evaluate the hash accordingly.If no readme exists, a
missing-file
should be appropriate.I added a repro at loilo/repro-remark-directory-links-49. It shows some of the described warnings but exits early due to a runtime error that occurs when linking to the root folder with a hash appended.
Caveats
In addition to headline anchors, the
#readme
anchor should be supported — however, this should already be taken care of by Allow links to point to the top of the document #48.Case sensitivity is a little bit unclear: While GitHub supports uppercase and lowercase readme file names, there's no documentation on which one is preferred if more than one matching file is present.
I tested this a while ago and if I remember correctly, there is no way to determine priority from the file name, but actually the readme file committed first will be used. GitHub will even prefer a
README.rst
over aREADME.md
if it was added earlier.Gitlab and BitBucket also support case-insensitive readme file names, but I have no idea (and have not done any tests) how they determine the preferred file.
However, I'd probably ignore all this "multiple readme files" fluff as "weird edge case" and hands down just pick the first thing that looks like a
/^readme.md$/g
.The text was updated successfully, but these errors were encountered: