I have a function in python 3.x
def foo():
"""Lorem ipsum for more info, see here""
I want to add a hyperlink to 'here' to point to a web site. How can I do that without installing external plugin?
I have a function in python 3.x
def foo():
"""Lorem ipsum for more info, see here""
I want to add a hyperlink to 'here' to point to a web site. How can I do that without installing external plugin?
Just add the link as a string into the docstring, like so:
def foo():
"""Lorem ipsum for more info, see here: www.myfancydocu.com""
The doctring is just a string, so there is no Hyperlink. But anyone that wants to look at the website can just copy the link.
There are automatic documentation-builders that build a documentation out of your code and docstrings in e.g. html. Those can probably add hyperlinks to the documentation with a specific syntax, but that syntax then depends on which documentation-builder you use. If you only have your code, then just adding the url as a string is all you can do.
If you're using sphinx to generate your documentation
"""
`here <url>`__
"""
in your docstrings should be parsed properly.
Just add the link as a string into the docstring, like so:
def foo():
"""Lorem ipsum for more info, see here: www.myfancydocu.com""
The doctring is just a string, so there is no Hyperlink. But anyone that wants to look at the website can just copy the link.
There are automatic documentation-builders that build a documentation out of your code and docstrings in e.g. html. Those can probably add hyperlinks to the documentation with a specific syntax, but that syntax then depends on which documentation-builder you use. If you only have your code, then just adding the url as a string is all you can do.
If you are using mkdocstrings
to generate documentation for a mkdocs
project (rather than using Sphinx
) you can generate a clickable url link in the documentation by embedding it between the less than (<) and greater than (>) characters. Something like this:
def foo():
"""Lorem ipsum for more info, see here <https://www.example.com>"""
pass
mkdocs
project (mkdocs.org) where the API documentation was pulled from the function docstrings using mkdocstrings
(mkdocstrings.github.io). mkdocstrings
can handle different programming languages and docstring formats based on specificiations in a .yaml
file. –
Adessive Syntax should be:
`hyperlink_name`_.
(grave accent before and after the hyperlink name)
.. _hyperlink_name: https://www.example.com
For example:
def class_name():
"""
Inspired from the `PSM-Net`_.
.. _PSM-Net: https://arxiv.org/abs/1803.08669
"""
...
If you put your cursor on the class_name
the result will be:
© 2022 - 2024 — McMap. All rights reserved.