Skip to content
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

Use Docutils 0.19 footnote styles #10599

Merged
merged 10 commits into from Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions sphinx/themes/basic/static/basic.css_t
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -671,8 +670,7 @@ div.citation > p:last-of-type:after {
content: "";
clear: both;
}

/* Footnotes & citations ends */
{%- endif %}

dl.field-list {
display: grid;
Expand Down
34 changes: 33 additions & 1 deletion sphinx/util/docutils.py
Expand Up @@ -18,6 +18,7 @@
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
Expand Down Expand Up @@ -182,10 +183,41 @@ def using_user_docutils_conf(confdir: Optional[str]) -> Generator[None, None, No
os.environ['DOCUTILSCONFIG'] = docutilsconfig


@contextmanager
def du19_footnotes() -> Generator[None, None, None]:
tk0miya marked this conversation as resolved.
Show resolved Hide resolved
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',
AA-Turner marked this conversation as resolved.
Show resolved Hide resolved
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

if docutils.__version_info__[:2] < (0, 19):
HTMLTranslator.visit_footnote = visit_footnote
HTMLTranslator.depart_footnote = depart_footnote

try:
yield
finally:
if docutils.__version_info__[:2] < (0, 19):
HTMLTranslator.visit_footnote = old_visit_footnote
HTMLTranslator.depart_footnote = old_depart_footnote


@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


Expand Down