Skip to content

Conversation

@mattip
Copy link
Contributor

@mattip mattip commented May 27, 2020

Fixes gh-39007

We replaced actual content with links to generated content in many places to break the documentation into manageable chunks. This caused references like

https://pytorch.org/docs/stable/torch.html#torch.flip

to become

https://pytorch.org/docs/master/generated/torch.flip.html#torch.flip

The textual content that was located at the old reference was replaced with a link to the new reference. This PR adds a <p id="xxx"/p> reference next to the link, so that the older references from outside tutorials and forums still work: they will bring the user to the link that they can then follow through to see the actual content.

The way this is done is to monkeypatch the sphinx writer method that produces the link. It is ugly but practical, and in my mind not worse than adding javascript to do the same thing.

@dr-ci
Copy link

dr-ci bot commented May 27, 2020

💊 CI failures summary and remediations

As of commit d46d8c7 (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 6 times.

@ShawnZhong
Copy link
Contributor

That’s cool! 👍 I didn’t know we can override HTML writer in Sphinx before.

ref = node.get('refuri')
ref_anchor = ref.split('#')
if len(ref_anchor) > 1:
self.body.append('<p id="{}"/p>'.format(ref_anchor[1]))
Copy link
Contributor

@ShawnZhong ShawnZhong May 28, 2020

Choose a reason for hiding this comment

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

The p tag might introduce an empty line in some cases:

Before After
image image
image image

We can consider changing it to a div tag: '<div id="{}" />'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tag should not be emitted here at all. Fixed with more hacks to filter out other references and use only the one that is relevant

Copy link
Contributor

Choose a reason for hiding this comment

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

As a minor side note here, we don’t put p after / for self closing tags, so it should be something like <p id="..." />

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, thanks

@ShawnZhong
Copy link
Contributor

ShawnZhong commented May 28, 2020

I also noticed that multiple references might be added for the same method, and the browser will choose to get to the first occurrence.

For example, https://5591729-65600975-gh.circle-artifacts.com/0/docs/torch.html#torch.max links to the middle of torch.clamp, since it is the first reference of torch.max on the page.

image

@mattip
Copy link
Contributor Author

mattip commented May 28, 2020

we can override HTML writer in Sphinx ...

The pandas theme does much more by using sphinx events but this PR is an attempt to keep it simple. If it needs more tweaking, maybe the event handling would be cleaner (or just use the javascript PR gh-39032).

@gchanan gchanan requested a review from jlin27 June 1, 2020 14:45
@gchanan gchanan added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jun 1, 2020
@mattip
Copy link
Contributor Author

mattip commented Jun 9, 2020

ping @jlin27 this is an alternative to gh-39032 which does something similar in javascript

@mattip
Copy link
Contributor Author

mattip commented Jul 4, 2020

@ShawnZhong is this still needed?

@jlin27
Copy link
Contributor

jlin27 commented Jul 9, 2020

Checked locally and works

Example:

file:///Users/jplin/github/pytorch/docs/build/html/torch.html#torch.is_tensor

brings users to the correct part of the documentation:
image

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@jlin27 is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@jlin27 merged this pull request in a88099b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged open source triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[docs] Urls changed => forum links would become invalid

7 participants