-
Notifications
You must be signed in to change notification settings - Fork 90
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 internal links in markdown long_descriptions #169
Comments
Thanks for the feature request! One complication with this is that we currently use URL fragments on project pages to link to PyPI-specific things, e.g.:
If we wanted to support this, would need to make sure that this existing behavior remains. |
I was very surprised to discover this PyPI limitation, which breaks a README.md/long_description's Table of Contents. I agree with @Oberon00 that this feature is needed for consistency between Markdown source shared between GitHub and PyPI. |
Any updates on this ? @di I see that for reStructuredText documents, anchor links are working as expected. For example, see this package. https://pypi.org/project/demandlib/ . I can easily navigate to sections using the table of contents. |
I transferred this issue to pypa/readme_renderer which is responsible for rendering descriptions on PyPI. I don't have any updates. For anyone wanting to work on this, first steps would be to determine where id/name attributes are being stripped for markdown, whether this is intentional, or can be modified, and then modifying it. |
I just ran into this problem for my package here: https://pypi.org/project/twitter-to-sqlite/ I added a table of contents to my README on https://github.com/dogsheep/twitter-to-sqlite (using this recipe) but it doesn't work on PyPI. |
It looks like Bleach is meant to be allowing the readme_renderer/readme_renderer/clean.py Lines 36 to 43 in be206d3
|
... but in poking around with the library it looks like those |
There's an open issue about that here: theacodes/cmarkgfm#20 |
And I think the root issue is over in |
Not sure if there have been fixes in regards to all this - maybe id tags aren't being stripped anymore, or you simply need to add them explicitly - but the following works on both GitHub and PyPI now: Contents:<a id="contents"></a> [Section Header](#section-header)
# Section Header [`↩`](#contents) <a id="section-header"></a> Using ↩ in single quotes creates what to me is an intuitive/appealing back button (although it's rendered differently on PyPI). See any of my projects for an example of how it looks/functions. |
My two cents:
(Note - no space between title and tag, otherwise you'll have self-link 🔗 pointing "title-" instead of "title") BUT - it would be awesome if pypi would automatically create anchors same way as github do. |
What about the |
What's the current workaround for this? |
Thank you! It'd be nice if PyPI did this automatically though 😅 |
## Changes This PR fixes readme links so that they work in PyPI, according to this comment: pypa/readme_renderer#169. I've also replaced the examples section of the readme to match what we have in our documentation, which may be easier for folks to follow. Resolves #289. ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [ ] `make test` run locally - [ ] `make fmt` applied - [ ] relevant integration tests applied
1. Images must use absolute, raw URLs so they resolve 2. The `<a name="..."></a>` doesn't work, but [this issue]( pypa/readme_renderer#169) suggests that `<a id="..."></a>` may work. Giving it a try.
1. Images must use absolute, raw URLs so they resolve 2. The `<a name="..."></a>` doesn't work, but [this issue]( pypa/readme_renderer#169) suggests that `<a id="..."></a>` may work. Giving it a try.
Manually create anchor tags for PyPi. See: pypa/readme_renderer#169 (comment)
## Summary This pull request adds anchor tags to the elements referenced in the table of contents section of the readme used on [PyPI](https://pypi.org/project/ruff/) as an attempt to fix #7257. This update follows [this suggestion](pypa/readme_renderer#169 (comment)) to add anchor tags (with no spaces) after the title that is to be linked to. ## Test Plan - This has been tested on GitHub to check that the additional tags do not interfere with how the read me is rendered; see: https://github.com/calumy/ruff/blob/add-links-to-pypi-docs/README.md - MK docs were generated using the `generate_mkdocs.py` script; however as the added tags are beyond the comment `<!-- End section: Overview -->`, they are excluded so will not change how the docs are rendered. - I was unable to verify how PyPI renders this change, any suggestions would be appreciated and I can follow up on this. Hopefully, the four thumbs up/heart on [this comment](pypa/readme_renderer#169 (comment)) and [this suggestion](pypa/readme_renderer#169 (comment)) all suggest that this approach should work.
What's the problem this feature will solve?
I want to set internal links/anchors in my README.md/long_description in markdown format (for example
See [the documentation](#documentation) for more information
which links to a## Documentation
heading or an explicit<a name="documentation"></a>
anchor). Ideally I'd like to use the same internally linked Markdown source for both GitHub and PyPI.Describe the solution you'd like
Explicit link creation via
<a name>
and<a id>
should be supported (maybe only<a name>
, depending on the potential to disturb any Javascript code).Ideally GitHub-compatible automatic anchor generation for headings should also be supported.
Additional context
A GitHub README.md supports two ways of setting anchors:
<a id="lower-case-with-some-chars-replaced-by-hyphens">
)<a id="...">
or<a name="..."
> tags.Warehouse does not automatically generate anchors for headings. It also strips
id
andname
attributes from HTML embedded in the Markdown file. This leaves no possibility of linking to another location within the description (without using an absolute link to PyPI.org, which is undesirable since the README is typically used in other places like GitHub too).The text was updated successfully, but these errors were encountered: