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

Allow links to point to the top of the document #48

Merged
merged 1 commit into from
Dec 12, 2019
Merged

Allow links to point to the top of the document #48

merged 1 commit into from
Dec 12, 2019

Conversation

loilo
Copy link
Contributor

@loilo loilo commented Dec 12, 2019

This PR enables linking to the top of a document on GitHub and Gitlab.

Both services have an anchor called #readme at the beginning of a rendered markdown document. This is useful for skipping the (potentially long) file list above it and it's heavily used in production (for example by npm init which appends it automatically if your package homepage is a GitHub repo).

BitBucket has no equivalent to this anchor, so this PR implements the feature as an environment-specific configuration.

I'll open this as a draft PR since I need clarification on the tests: I added a link pointing to #readme to each the github.md and the gitlab.md. They work as expected, however I added the same link to bitbucket.md, expecting it to fail, but it passed because it was tested as being in a GitHub environment.

Is there any mechanism in place to simulate BitBucket for tests?

@codecov-io

This comment has been minimized.

@wooorm
Copy link
Member

wooorm commented Dec 12, 2019

Hmm, the reason Bitbucket doesn’t warn about #top or #readme and the like (which I think you’re asking, right?), is that Bitbucket uses #markdown-header- as a heading prefix, and we ignore all anchor links that don’t use the heading prefix.

Because GH and GL use # as a heading prefix, in those environments, every anchor fails if it isn’t know. In case of BB, we ignore everything that doesn’t start with #markdown-header- silently.

@loilo
Copy link
Contributor Author

loilo commented Dec 12, 2019

Ah, alright. 👍
Then this is ready to review I guess. 🙂

@loilo loilo marked this pull request as ready for review December 12, 2019 09:39
@wooorm wooorm merged commit 46af9eb into remarkjs:master Dec 12, 2019
@wooorm wooorm added 🗄 area/interface This affects the public interface 💪 phase/solved Post is done 🦋 type/enhancement This is great to have 🧒 semver/minor This is backwards-compatible change labels Dec 12, 2019
@loilo
Copy link
Contributor Author

loilo commented Jan 8, 2020

Hey @wooorm, just for a bit of planning — when is the next minor release of this package scheduled? Having this thing solved would spare me a couple dozen noisy messages on my lint runs. 🙂

@loilo loilo deleted the allow-top-link branch January 8, 2020 14:38
@wooorm
Copy link
Member

wooorm commented Jan 8, 2020

Thanks, released!

@loilo
Copy link
Contributor Author

loilo commented Jan 8, 2020

Weee, thanks! 😄

@wooorm wooorm added the 💪 phase/solved Post is done label Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗄 area/interface This affects the public interface 💪 phase/solved Post is done 🧒 semver/minor This is backwards-compatible change 🦋 type/enhancement This is great to have
Development

Successfully merging this pull request may close these issues.

3 participants