-
Notifications
You must be signed in to change notification settings - Fork 32
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
Allow ..image:: directive on 404.rst #21
Changes from all commits
0e2058b
9b1da45
68fc1ba
a5333a2
69cfef8
197f863
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
from sphinx.builders.html import DirectoryHTMLBuilder | ||
|
||
|
||
def replace_uris(app, doctree, nodetype, nodeattr): | ||
""" | ||
Replace ``nodetype`` URIs from ``doctree`` to the proper one. | ||
|
||
:param app: Sphinx Application | ||
:type app: sphinx.application.Sphinx | ||
:param doctree: doctree representing the document | ||
:type doctree: docutils.nodes.document | ||
:param nodetype: type of node to replace URIs | ||
:type nodetype: docutils.nodes.Node | ||
:param nodeattr: node attribute to be replaced | ||
:type nodeattr: str | ||
""" | ||
# https://github.com/sphinx-doc/sphinx/blob/2adeb68af1763be46359d5e808dae59d708661b1/sphinx/environment/adapters/toctree.py#L260-L266 | ||
for node in doctree.traverse(nodetype): | ||
refuri = node.attributes.get(nodeattr) # somepage.html (or ../sompage.html) | ||
|
||
if isinstance(app.builder, DirectoryHTMLBuilder): | ||
# When the builder is ``DirectoryHTMLBuilder``, refuri will be | ||
# ``../somepage.html``. In that case, we want to remove the | ||
# initial ``../`` to make valid links | ||
if refuri.startswith('../'): | ||
refuri = refuri.replace('../', '') | ||
|
||
if app.config.notfound_no_urls_prefix: | ||
uri = '/{filename}'.format( | ||
filename=refuri, | ||
) | ||
else: | ||
uri = '/{language}/{version}/{filename}'.format( | ||
language=app.config.language or 'en', | ||
version=os.environ.get('READTHEDOCS_VERSION', 'latest'), | ||
filename=refuri, | ||
) | ||
node.replace_attr(nodeattr, uri) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,16 @@ This file should be rendered instead of the default one. | |
|
||
Variables Sphinx substitution should be allowed here. | ||
Example, version: |version|. | ||
|
||
Including an image using ``.. image::`` directive, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would just put both directives in the same sentence, like: using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is used for the tests to check that they render properly. Both directive are needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thought this was an actual doc page p: |
||
should also make the extension to fix the URIs. | ||
|
||
.. image:: test.png | ||
:alt: An image | ||
|
||
|
||
Also, using ``.. figure::`` should work as well. | ||
|
||
.. figure:: test.png | ||
|
||
Description. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason this can't be included in the docstring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to display it in the autoapi docs.