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

Markdocs docs with embeded autodoc fails to create valid links #521

Open
jborean93 opened this issue Feb 16, 2022 · 2 comments
Open

Markdocs docs with embeded autodoc fails to create valid links #521

jborean93 opened this issue Feb 16, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@jborean93
Copy link

Describe the bug

context
When I have an embedded autodoc entry in my markdown file for myst to build, any references in the docstring are rendered invalid.

Was initially reported in #228 (comment) but was off topic to the issue there (my bad).

expectation
I expect the links to be created with the correct name and the correct href target set.

bug
But instead myst generates a warning about an unknown target and the link in the rendered docs points to an invalid target happens.
Here's an error message I ran into...

$ sphinx-build ...
/path/to/mymodule/__init__.py:docstring of mymodule.my_function:12: ERROR: Unknown target name: "link".

The converted HTML has the following element set for this is

<a href="#id309"><span class="problematic" id="id310">`link`_</span></a>.</p>

problem
This is a problem for people trying to generate Python docs from a docstring using automodule because it breaks any embedded links they may have in the docstring itself.

The same docstring works just fine if I have an rst with the autodoc entry and is rendered outside of MyST. Unfortunately as mentioned in #519 the latest release seems to have changed how links are referenced so my other MyST generated docs that had the following now no longer work.

[Link To My Function](./source/mymodule.html#mymodule.my_function)

By using a markdown file to embed the autodoc entries these links now work, albiet in a slightly different way, but the actual docstring references in the function/classes are broken. Happy to try out anything as right now I'm stuck on the older version where both scenarios still work.

Reproduce the bug

Create a markdown file in your docs build with the following contents

````{eval-rst}
.. automodule:: mymodule
   :members:
   :undoc-members:
   :show-inheritance:
````

Inside your mymodule create a dummy function with the following

A docstring (Google style) I'm using is something like

def my_function():
    """Header

    Some text with a `link`_.

    .. _link:
        https://github.com
    """
    pass

Sphinx can be invoked like sphinx-build -M html "source_dir" "build_dir" -W --keep-going to run the build process.

List your environment

Not using Jupyter but just Sphinc with this library and autodoc. I'm running Sphinx with Python 3.8, myst-parser==0.17.0, and Sphinx==4.4.0.

@jborean93 jborean93 added the bug Something isn't working label Feb 16, 2022
@welcome
Copy link

welcome bot commented Feb 16, 2022

Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.

If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).

Welcome to the EBP community! 🎉

@tpvasconcelos
Copy link

I'm still experiencing the same issue. I am forced to use autodoc directives in rst files only. An alternative is to use inline references but this is far from ideal. e.g.

def my_function():
    """Header

    Some text with a `link <https://github.com>`_.
    """
    pass

@jborean93 did you ever find a good solution for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants