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

Automatically treat relative links as cross-references #149

Closed
asmeurer opened this issue May 26, 2020 · 11 comments
Closed

Automatically treat relative links as cross-references #149

asmeurer opened this issue May 26, 2020 · 11 comments
Labels
enhancement New feature or request

Comments

@asmeurer
Copy link
Contributor

asmeurer commented May 26, 2020

I don't know if this is within scope or not. It would be nice if relative links like

[link](page.html)

or

[link](page.html#header)

were automatically translated to cross-references, and especially if it didn't require adding a (header)= to the header if the slug is already named that.

The former does not work at all (it produces an error). The latter does work, but I believe it is just treating it like an external link, meaning if there is a spelling mistake in the page.html#header part it won't catch it.

A potential issue might be that Myst documents could be included alongside other documents, so you can't guarantee that a page that you can't find a reference to isn't something that will be there anyway. I don't know if that is the case.

@chrisjsewell
Copy link
Member

Have you tried just [link](page). The doc-role doesn't accept an extension (sphinx intrinsically doesn;t store the extension of pages). there is an issue in one of the repos about allowing this in the myst syntax though

@chrisjsewell
Copy link
Member

In general with sphinx (rST or MyST) I would always advise using specific targets over document/header names, since they are obviously lot more resilient to changes/refactoring of the documentation

@asmeurer
Copy link
Contributor Author

asmeurer commented May 26, 2020

Yes [link](page) works (#148 not withstanding). [link](header) works as well, but only after I add (header)=. The way I suggested is the way you have to write links in recommonmark, and it's also the way I would naturally write links in Markdown.

@chrisjsewell
Copy link
Member

Did you mean to but back-ticks around those links?

@chrisjsewell
Copy link
Member

Anyway these issues probably don't have a quick fix and I'm signing off for the evening, so will get back to you on these at a later time

@choldgraf
Copy link
Member

re: linking to headers without explicitly defining labels, doesn't recommonmark just use this sphinx extension? https://www.sphinx-doc.org/en/master/usage/extensions/autosectionlabel.html (which auto-adds labels for all section labels). If so, you could just activate that extension as well if you don't want to manually add labels.

@asmeurer
Copy link
Contributor Author

Oh I didn't know about that. I'll give it a try. If you don't want to make this a default that's fine with me. I'll leave you to discuss that. Either way though maybe Myst could document that it's an option in the cross-reference docs.

@pradyunsg
Copy link
Member

A borderline drive-by comment that it'd be nice to have the answer to "how do I link to a header in a different page in MyST" documented somewhere. :)

@chrisjsewell
Copy link
Member

In fact this issue can probably now be closed, given: https://myst-parser.readthedocs.io/en/latest/using/syntax-optional.html#auto-generated-header-anchors

@pradyunsg
Copy link
Member

Yeap!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants