Skip to content

DOC add permalink to summary of collapsed details section#27409

Merged
glemaitre merged 15 commits intoscikit-learn:mainfrom
glemaitre:is/27408
Oct 17, 2023
Merged

DOC add permalink to summary of collapsed details section#27409
glemaitre merged 15 commits intoscikit-learn:mainfrom
glemaitre:is/27408

Conversation

@glemaitre
Copy link
Copy Markdown
Member

@glemaitre glemaitre commented Sep 18, 2023

closes #27127
follow-up of #26872

Add permalink to summaries of collapsed details section.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Sep 18, 2023

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 5ab824b. Link to the linter CI: here

@glemaitre glemaitre mentioned this pull request Sep 18, 2023
12 tasks
@glemaitre
Copy link
Copy Markdown
Member Author

I am missing the auto-scrolling to the permalink when accessing the link.
I don't really know the reason why.

@glemaitre
Copy link
Copy Markdown
Member Author

Of course, I forgot to add the id.

@glemaitre
Copy link
Copy Markdown
Member Author

It remains 1 annoying thing that is already present in the website: the referencing will place the anchor at position 0 px and it will be hidden under the navbar.

@ArturoAmorQ
Copy link
Copy Markdown
Member

I opened #27418 without realizing you had worked on this. Should I close it?

@glemaitre
Copy link
Copy Markdown
Member Author

OK, so the results are now compelling regarding the rendering. The only drawback is the need to add create manually the referencing that was done by Sphinx in the past. I don't know how many of such editing we will need. Also, in the future, these links will not be checked by Sphinx and we can get dead link if the documentation page structure is changing.

@glemaitre
Copy link
Copy Markdown
Member Author

I opened #27418 without realizing you had worked on this. Should I close it?

This is reverting the problem but I assume that we will encounter it again on some other part. If this is really meaningful to have I think that we should come with a solution.

@ogrisel ogrisel changed the title DOC fix warning due to unknown anchor in dropdown menu DOC fix warnings caused by unknown anchors in collapsed details sections Sep 19, 2023
@ogrisel
Copy link
Copy Markdown
Member

ogrisel commented Sep 19, 2023

I am not a fan of the extra complexity induced by this PR. I think I would much prefer the approach of #27418.

@ogrisel
Copy link
Copy Markdown
Member

ogrisel commented Sep 19, 2023

Having the permalinks on the details headers is nice though but I would still avoid breaking sphinx references.

@ArturoAmorQ
Copy link
Copy Markdown
Member

ArturoAmorQ commented Sep 20, 2023

Just a tweak: #27418 introduced a typo "shortand" -> "shorthand" which I was too slow to catch. Now that you're working on this, can you please take care of it?

@glemaitre glemaitre changed the title DOC fix warnings caused by unknown anchors in collapsed details sections DOC add permalink to summary of collapsed details section Sep 20, 2023
@glemaitre
Copy link
Copy Markdown
Member Author

Just a tweak: #27418 introduced a typo "shortand" -> "shorthand" which I was to slow to catch. Now that you're working on this, can you please take care of it?

Indeed, I did solve the problem in main

@glemaitre
Copy link
Copy Markdown
Member Author

I know this is not purely documentation since there is a little bit of code but I think @scikit-learn/documentation-team you can have a review and merge this one if the rendering is what you expected from the original issue.

Comment on lines +23 to +25
// The ID uses the first line, lowercased, and spaces replaced with dashes
var anchorID = summaryElement.textContent.trim().split("\n")[0].replace(/\s+/g, '-').toLowerCase();
detailsElement.setAttribute('id', anchorID);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Question out of ignorance, what happens if the summary text contains special character such as \/:*? "<>|&%. '#[]+=„ ?

Or can we rather use .replace(/[\s\/:*?"<>|&%. '#\[\]+=„]+/g, '')?

Copy link
Copy Markdown
Member

@ArturoAmorQ ArturoAmorQ Oct 11, 2023

Choose a reason for hiding this comment

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

I think there might be cases where the summary text is repeated across a file, such as References or similar. Is there a way to add a counter of appearance per file or allow for custom anchor in some cases?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Regarding the special characters, I think that they can be part of the URL and it should not be a problem. I would not address this issue now. We can always change the code if in the future we have a compeling example.

For the second suggestion, this is something that I did not think about and this is a really good point. I will initiate a counter add it as a suffix.

Copy link
Copy Markdown
Member

@ArturoAmorQ ArturoAmorQ left a comment

Choose a reason for hiding this comment

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

The rendering looks good so I am approving this PR, but this is definitely not my field of expertise.

Copy link
Copy Markdown
Member

@lucyleeow lucyleeow left a comment

Choose a reason for hiding this comment

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

This is also outside of my wheelhouse but the code is well commented and it works well for me.

@glemaitre glemaitre merged commit ebe4c7e into scikit-learn:main Oct 17, 2023
glemaitre added a commit to glemaitre/scikit-learn that referenced this pull request Oct 31, 2023
…rn#27409)

Co-authored-by: Arturo Amor <86408019+ArturoAmorQ@users.noreply.github.com>
REDVM pushed a commit to REDVM/scikit-learn that referenced this pull request Nov 16, 2023
…rn#27409)

Co-authored-by: Arturo Amor <86408019+ArturoAmorQ@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOC Add permalinks to dropdown headers

4 participants