MyST-Parser
MyST-Parser copied to clipboard
Markdocs docs with embeded autodoc fails to create valid links
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 https://github.com/executablebooks/MyST-Parser/issues/228#issuecomment-1041097220 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 https://github.com/executablebooks/MyST-Parser/issues/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.
Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
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! :tada:
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?