mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Use Docutils 0.19 footnote styles (#10599)
This commit is contained in:
3
CHANGES
3
CHANGES
@@ -26,6 +26,9 @@ Features added
|
||||
Pradyun Gedam.
|
||||
* #10619: LaTeX: new ``shadowShadowColor`` and ``shadowBorderColor`` configurations
|
||||
for :ref:`'sphinxsetup' <latexsphinxsetup>` key of :confval:`latex_elements`
|
||||
* #10599: HTML Theme: Wrap consecutive footnotes in an ``<aside>`` element when
|
||||
using Docutils 0.18 or later, to allow for easier styling. This matches the
|
||||
behaviour introduced in Docutils 0.19. Patch by Adam Turner.
|
||||
|
||||
Bugs fixed
|
||||
----------
|
||||
|
||||
@@ -629,7 +629,7 @@ ul.simple p {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
/* Docutils 0.17 and older (footnotes & citations) */
|
||||
{%- if docutils_version_info[:2] < (0, 18) %}
|
||||
dl.footnote > dt,
|
||||
dl.citation > dt {
|
||||
float: left;
|
||||
@@ -646,8 +646,7 @@ dl.citation > dd:after {
|
||||
content: "";
|
||||
clear: both;
|
||||
}
|
||||
|
||||
/* Docutils 0.18+ (footnotes & citations) */
|
||||
{%- elif docutils_version_info[:2] >= (0, 18) %}
|
||||
aside.footnote > span,
|
||||
div.citation > span {
|
||||
float: left;
|
||||
@@ -671,8 +670,7 @@ div.citation > p:last-of-type:after {
|
||||
content: "";
|
||||
clear: both;
|
||||
}
|
||||
|
||||
/* Footnotes & citations ends */
|
||||
{%- endif %}
|
||||
|
||||
dl.field-list {
|
||||
display: grid;
|
||||
|
||||
@@ -18,6 +18,7 @@ from docutils.parsers.rst import Directive, directives, roles
|
||||
from docutils.parsers.rst.states import Inliner
|
||||
from docutils.statemachine import State, StateMachine, StringList
|
||||
from docutils.utils import Reporter, unescape
|
||||
from docutils.writers._html_base import HTMLTranslator # NoQA
|
||||
|
||||
from sphinx.deprecation import RemovedInSphinx70Warning, deprecated_alias
|
||||
from sphinx.errors import SphinxError
|
||||
@@ -182,10 +183,46 @@ def using_user_docutils_conf(confdir: Optional[str]) -> Generator[None, None, No
|
||||
os.environ['DOCUTILSCONFIG'] = docutilsconfig
|
||||
|
||||
|
||||
@contextmanager
|
||||
def du19_footnotes() -> Generator[None, None, None]:
|
||||
def visit_footnote(self, node):
|
||||
label_style = self.settings.footnote_references
|
||||
if not isinstance(node.previous_sibling(), type(node)):
|
||||
self.body.append(f'<aside class="footnote-list {label_style}">\n')
|
||||
self.body.append(self.starttag(node, 'aside',
|
||||
classes=[node.tagname, label_style],
|
||||
role="note"))
|
||||
|
||||
def depart_footnote(self, node):
|
||||
self.body.append('</aside>\n')
|
||||
if not isinstance(node.next_node(descend=False, siblings=True),
|
||||
type(node)):
|
||||
self.body.append('</aside>\n')
|
||||
|
||||
old_visit_footnote = HTMLTranslator.visit_footnote
|
||||
old_depart_footnote = HTMLTranslator.depart_footnote
|
||||
|
||||
# Only apply on Docutils 0.18 or 0.18.1, as 0.17 and earlier used a <dl> based
|
||||
# approach, and 0.19 and later use the fixed approach by default.
|
||||
if docutils.__version_info__[:2] == (0, 18):
|
||||
HTMLTranslator.visit_footnote = visit_footnote # type: ignore[assignment]
|
||||
HTMLTranslator.depart_footnote = depart_footnote # type: ignore[assignment]
|
||||
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
if docutils.__version_info__[:2] == (0, 18):
|
||||
HTMLTranslator.visit_footnote = old_visit_footnote # type: ignore[assignment]
|
||||
HTMLTranslator.depart_footnote = old_depart_footnote # type: ignore[assignment]
|
||||
|
||||
|
||||
@contextmanager
|
||||
def patch_docutils(confdir: Optional[str] = None) -> Generator[None, None, None]:
|
||||
"""Patch to docutils temporarily."""
|
||||
with patched_get_language(), patched_rst_get_language(), using_user_docutils_conf(confdir):
|
||||
with patched_get_language(), \
|
||||
patched_rst_get_language(), \
|
||||
using_user_docutils_conf(confdir), \
|
||||
du19_footnotes():
|
||||
yield
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user