mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #9225 from doerwalter/typehint-html
Add HTML markup to method/function return typehint
This commit is contained in:
commit
f40c2837dc
@ -174,10 +174,12 @@ class HTMLTranslator(SphinxTranslator, BaseTranslator):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def visit_desc_returns(self, node: Element) -> None:
|
def visit_desc_returns(self, node: Element) -> None:
|
||||||
self.body.append(' → ')
|
self.body.append(' <span class="sig-return">')
|
||||||
|
self.body.append('<span class="sig-return-icon">→</span>')
|
||||||
|
self.body.append(' <span class="sig-return-typehint">')
|
||||||
|
|
||||||
def depart_desc_returns(self, node: Element) -> None:
|
def depart_desc_returns(self, node: Element) -> None:
|
||||||
pass
|
self.body.append('</span></span>')
|
||||||
|
|
||||||
def visit_desc_parameterlist(self, node: Element) -> None:
|
def visit_desc_parameterlist(self, node: Element) -> None:
|
||||||
self.body.append('<span class="sig-paren">(</span>')
|
self.body.append('<span class="sig-paren">(</span>')
|
||||||
|
@ -145,10 +145,12 @@ class HTML5Translator(SphinxTranslator, BaseTranslator):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def visit_desc_returns(self, node: Element) -> None:
|
def visit_desc_returns(self, node: Element) -> None:
|
||||||
self.body.append(' → ')
|
self.body.append(' <span class="sig-return">')
|
||||||
|
self.body.append('<span class="sig-return-icon">→</span>')
|
||||||
|
self.body.append(' <span class="sig-return-typehint">')
|
||||||
|
|
||||||
def depart_desc_returns(self, node: Element) -> None:
|
def depart_desc_returns(self, node: Element) -> None:
|
||||||
pass
|
self.body.append('</span></span>')
|
||||||
|
|
||||||
def visit_desc_parameterlist(self, node: Element) -> None:
|
def visit_desc_parameterlist(self, node: Element) -> None:
|
||||||
self.body.append('<span class="sig-paren">(</span>')
|
self.body.append('<span class="sig-paren">(</span>')
|
||||||
|
1
tests/roots/test-html_signaturereturn_icon/conf.py
Normal file
1
tests/roots/test-html_signaturereturn_icon/conf.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
extensions = ['sphinx.ext.autodoc']
|
4
tests/roots/test-html_signaturereturn_icon/index.rst
Normal file
4
tests/roots/test-html_signaturereturn_icon/index.rst
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
test-html_signaturereturn_icon
|
||||||
|
==============================
|
||||||
|
|
||||||
|
.. py:function:: foo(a: bool, b: int) -> str
|
@ -1635,3 +1635,11 @@ def test_html_permalink_icon(app):
|
|||||||
assert ('<h1>The basic Sphinx documentation for testing<a class="headerlink" '
|
assert ('<h1>The basic Sphinx documentation for testing<a class="headerlink" '
|
||||||
'href="#the-basic-sphinx-documentation-for-testing" '
|
'href="#the-basic-sphinx-documentation-for-testing" '
|
||||||
'title="Permalink to this headline"><span>[PERMALINK]</span></a></h1>' in content)
|
'title="Permalink to this headline"><span>[PERMALINK]</span></a></h1>' in content)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.sphinx('html', testroot='html_signaturereturn_icon')
|
||||||
|
def test_html_signaturereturn_icon(app):
|
||||||
|
app.build()
|
||||||
|
content = (app.outdir / 'index.html').read_text()
|
||||||
|
|
||||||
|
assert ('<span class="sig-return-icon">→</span>' in content)
|
||||||
|
Loading…
Reference in New Issue
Block a user