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

Support Markdown links on MyST #250

Open
jhj0411jhj opened this issue Dec 19, 2022 · 9 comments
Open

Support Markdown links on MyST #250

jhj0411jhj opened this issue Dec 19, 2022 · 9 comments
Labels
Feature New feature

Comments

@jhj0411jhj
Copy link

I love the features you provide. But I'm writing Sphinx docs with markdown (myst-parser).

For example, I often write a link to other documents in my docs (markdown):

[Another guide](./xxx/some_file)

I wish when I hover over the markdown link, a preview of that doc is shown. Is it possible to support hoverxref in markdown? Thanks.

@jhj0411jhj
Copy link
Author

I've noticed this issue #114. And I find the ref syntex provided by my-st is useful: https://myst-parser.readthedocs.io/en/latest/syntax/syntax.html#targets-and-cross-referencing

{ref}`my text <header_target>`

I'm wondering whether hoverxref_auto_ref can identify and convert markdown links ({any} role?) written by [name](file) automatically.

@jhj0411jhj
Copy link
Author

I find a solution.

First, generate section label:

extensions += ['sphinx.ext.autosectionlabel']
# Make sure the target is unique
autosectionlabel_prefix_document = True
autosectionlabel_maxdepth = None

Then use {ref} provided by myst-parser in markdown:

{ref}`design principle <overview/overview:design principle>`

hoverxref will identify the ref above.

However, the markdown links cannot be identified:

using sphinx.ext.autosectionlabel:
[](<overview/overview:design principle>)

using markdown anchor. for example, set `myst_heading_anchors = 3` 
[](../overview/overview.md#design-principle)

So I have to rewrite all my links using {ref}. Is there any way to avoid rewriting existing markdown links ([text](file#header))?

@kiteloopdesign
Copy link

Hi, same question/issue here with Myst markdown in Sphinx. Commenting here for visibility.

@humitos humitos changed the title Support markdown links Support Markdown links on MyST Jan 10, 2023
@humitos
Copy link
Member

humitos commented Jan 10, 2023

Hi all! I don't have too much experience working with MyST and how it generates the nodes. It makes sense that it works when using {ref} in your links since that's a Sphinx role and it's translated into a ref node in docutils.

However, I'm not sure to what node [text](file#header) translates to. We will need to figure it out that first. Once we know it, we can probably add a small chunk of code to this extension to handle those as ref as well.

@humitos humitos added the Feature New feature label Jan 10, 2023
@chrisjsewell
Copy link

Hey gang, so yeh I wanted this also, plus didn't really like the whole having to have it hosted on RTD to get it working.

So I created my own extension 😅, that works by pre-compiling all the tips, rather than fetching them interactively (and also supports other APIs like wikipedia and DOI)

Here it is: https://sphinx-tippy.readthedocs.io, and you can see it in action on https://myst-parser.readthedocs.io

happy to work with you guys on it

@FlyingToto
Copy link

Hello Everyone,
I am sorry but I can't figure out from the docs above how to get these tippy tooltips to work with Myst Markdown.
We use: md files -> myst -> sphinx -> github -> readthedocs

We basically have 3 simple use-cases when the mouse hovers our keyword 'foo':

  • show 1 line tooltip: just display the string "Hello World!"
  • show multi-lines tooltip: just display the text:
    "Hello line1 !
    Hello line2!"
    when the mouse over the keyword.
  • show a box with the content of another html page: hello_world.html ? (although I assume we write the file as hello_world.md and it get translated to hello_world.html by myst+sphinx)

...I am very new to this whole markdown things, so I apologize if my question is somehow obvious...
for instance for item 1,
I did add to my md file: "Custom tip" which I stole from your tippy doc source code.
but it only show the link in the bottom left corner of my browser no tooltip is showing.
I think I did configure some of tippy properly because I do see some tooltip showing up when I hover over some of my headers in the menu...

Thank you so much!

@LecrisUT
Copy link

LecrisUT commented Dec 15, 2023

Am I doing something wrong, or are external roles not supported? I tried on a .md file as:

{external+rtd:std:doc}`test<intro/getting-started-with-sphinx>`

but that did not seem to work. ref with hoverxref_auto_ref seemed to work, but I am not sure how to translate the equivalent of <inv:rtd:std:doc#intro/getting-started-with-sphinx> to that. I've also tried doc as:

{doc}`test<rtd:index>`

~~but that did not work either. ~~ Actually it works, I did not configure hoverxref_intersphinx appropriately

Basically what would be the minimum setup and supported roles that could be used? Ideally compared to myst documentation here and here

@LecrisUT
Copy link

@humitos is this reference useful? Or maybe the class of that caller is needed?

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

No branches or pull requests

7 participants