mirror of https://github.com/YosysHQ/yosys.git
Docs: Add autoref role
Use new `autoref` role when using single backticks. Allows automatic mapping to a cmd ref or a cell ref.
This commit is contained in:
parent
f9b4e04fef
commit
c0f9828b3c
|
@ -41,6 +41,9 @@ html_static_path = ['_static', "_images"]
|
||||||
pygments_style = 'colorful'
|
pygments_style = 'colorful'
|
||||||
highlight_language = 'none'
|
highlight_language = 'none'
|
||||||
|
|
||||||
|
# default single quotes to attempt auto reference, or fallback to code
|
||||||
|
default_role = 'autoref'
|
||||||
|
|
||||||
extensions = ['sphinx.ext.autosectionlabel', 'sphinxcontrib.bibtex']
|
extensions = ['sphinx.ext.autosectionlabel', 'sphinxcontrib.bibtex']
|
||||||
|
|
||||||
if os.getenv("READTHEDOCS"):
|
if os.getenv("READTHEDOCS"):
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# based on https://github.com/ofosos/sphinxrecipes/blob/master/sphinxrecipes/sphinxrecipes.py
|
# based on https://github.com/ofosos/sphinxrecipes/blob/master/sphinxrecipes/sphinxrecipes.py
|
||||||
|
|
||||||
from docutils.parsers.rst import directives
|
from docutils.parsers.rst import directives
|
||||||
|
from docutils.parsers.rst.states import Inliner
|
||||||
|
from sphinx.application import Sphinx
|
||||||
from sphinx.domains import Domain, Index
|
from sphinx.domains import Domain, Index
|
||||||
from sphinx.domains.std import StandardDomain
|
from sphinx.domains.std import StandardDomain
|
||||||
from sphinx.roles import XRefRole
|
from sphinx.roles import XRefRole
|
||||||
|
@ -228,7 +230,12 @@ class CellDomain(CommandDomain):
|
||||||
TagIndex
|
TagIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
def setup(app):
|
def autoref(name, rawtext, text, lineno, inliner: Inliner,
|
||||||
|
options=None, content=None):
|
||||||
|
role = 'cell:ref' if text[0] == '$' else 'cmd:ref'
|
||||||
|
return inliner.interpreted(rawtext, text, role, lineno)
|
||||||
|
|
||||||
|
def setup(app: Sphinx):
|
||||||
app.add_domain(CommandDomain)
|
app.add_domain(CommandDomain)
|
||||||
app.add_domain(CellDomain)
|
app.add_domain(CellDomain)
|
||||||
|
|
||||||
|
@ -249,5 +256,7 @@ def setup(app):
|
||||||
('cell-cell', '')
|
('cell-cell', '')
|
||||||
StandardDomain.initial_data['anonlabels']['tagindex'] =\
|
StandardDomain.initial_data['anonlabels']['tagindex'] =\
|
||||||
('cell-tag', '')
|
('cell-tag', '')
|
||||||
|
|
||||||
|
app.add_role('autoref', autoref)
|
||||||
|
|
||||||
return {'version': '0.2'}
|
return {'version': '0.2'}
|
||||||
|
|
Loading…
Reference in New Issue