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 autodoc parameter hrefs #516

Merged
merged 1 commit into from
Sep 13, 2024
Merged

Fix autodoc parameter hrefs #516

merged 1 commit into from
Sep 13, 2024

Conversation

gante
Copy link
Member

@gante gante commented Jul 26, 2024

TL;DR

fixes hrefs for class parameters on ALL classes across ALL librares 🤗


Problem

Currently, hrefs for individual parameters are broken. Examples (try to click on individual parameters of the classes):

We can see in the pages' source code that the hrefs are sketchy
Screenshot 2024-07-26 at 10 38 33

Diving deeper in the doc builder and in our docs, we can see that:

  1. The issue is somewhat recent, ~3 months old;
  2. The issue can be solved if we comment out these recent lines that replace # by their html equivalent on inline code blocks

Solution

The # conversion exists to prevent bad formatting in some cases, so it can't simply be removed -- see #504

The solution adopted consists in detecting inline code blocks inside the autodoc section, which contain the href anchor, and preserving the # there. The solution in the PR consists in reverting the conversion -- in my quick experiments, a complete regex that skipped the conversion in autodoc blocks was much much slower.

Example of an href after these changes:
Screenshot 2024-07-26 at 10 37 01

Same href in a previously working version:
Screenshot 2024-07-26 at 10 36 29

Tests

I couldn't find a test section for the kit folder 🤔

@gante gante requested a review from mishig25 July 26, 2024 09:42
@@ -6,12 +6,17 @@ export const hashInCodePreprocess = {
markup: async ({ content }) => {
const REGEX_CODE_BLOCK = /```.*?```/gs;
const REGEX_INLINE_CODE = /`.*?`/g;
const REGEX_INLINE_EXCEPTION = /(?!.*HF_DOC_BODY_START)`.*?`(?<!HF_DOC_BODY_END.*)/gs;
Copy link
Member Author

@gante gante Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic tl;dr: find all inline code blocks (`.*?`) between HF_DOC_BODY_START and HF_DOC_BODY_END, the autodocs delimiters

@gante
Copy link
Member Author

gante commented Sep 6, 2024

@mishig25 ping :)

Copy link
Contributor

@mishig25 mishig25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm !

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