Skip to content

Replace aside tags with div tags when converting rST to HTML #1783

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ div.admonition,
div.topic,
div.topic.contents,
// Docutils >= 0.18
nav.contents,
aside.topic {
nav.contents {
display: flex;
flex-direction: column;
background-color: var(--pst-color-surface);
Expand Down Expand Up @@ -288,7 +287,7 @@ aside.topic {
/**
* Sidebar directive
*/
aside.sidebar {
div.sidebar {
border: 1px solid var(--pst-color-border);
background-color: var(--pst-color-surface);
border-radius: $admonition-border-radius;
Expand Down
22 changes: 20 additions & 2 deletions src/pydata_sphinx_theme/assets/styles/content/_footnotes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ a.footnote-reference {
font-size: small;
}

// Docutils 0.18 uses an `aside.footnote` container with different internal structure
aside.footnote {
// Docutils 0.18 uses a container with different internal structure
div.footnote {
margin-bottom: 0.5rem;
&:last-child {
margin-bottom: 1rem;
Expand All @@ -28,4 +28,22 @@ aside.footnote {
&:target {
background-color: var(--pst-color-target);
}

// Replicate styles from Sphinx that target aside.footnote
> span {
float: left;
&:last-of-type {
padding-right: 0.5em;
}
}
> p {
margin-left: 2em;
&:last-of-type {
margin-bottom: 0em;
&:after {
content: "";
clear: both;
}
}
}
}
37 changes: 37 additions & 0 deletions src/pydata_sphinx_theme/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,43 @@ def visit_table(self, node):
tag = self.starttag(node, "table", CLASS=" ".join(classes), **atts)
self.body.append(tag)

def visit_sidebar(self, node):
"""r/aside/div copy of Docutils html5 writer method.

Link to original: https://github.com/docutils/docutils/blob/ff0b419256d6b7bfdd4363dd078c2255701de605/docutils/docutils/writers/html5_polyglot/__init__.py#L350
"""
self.body.append(self.starttag(node, "div", CLASS="sidebar"))
self.in_sidebar = True

def depart_sidebar(self, node):
"""r/aside/div copy of Docutils html5 writer method.

Link to original: https://github.com/docutils/docutils/blob/ff0b419256d6b7bfdd4363dd078c2255701de605/docutils/docutils/writers/html5_polyglot/__init__.py#L355
"""
self.body.append("</div>\n")
self.in_sidebar = False

def visit_footnote(self, node) -> None:
"""r/aside/div copy of Sphinx-patched Docutils html5 writer method.

Link to original: https://github.com/sphinx-doc/sphinx/blob/9ebc46a74fa766460c450bd60cdef46b98492939/sphinx/util/docutils.py#L185
"""
label_style = self.settings.footnote_references
if not isinstance(node.previous_sibling(), type(node)): # type: ignore[attr-defined]
self.body.append(f'<div class="footnote-list {label_style}">\n')
self.body.append(
self.starttag(node, "div", classes=[node.tagname, label_style], role="note")
)

def depart_footnote(self, node) -> None:
"""r/aside/div copy of Sphinx-patched Docutils html5 writer method.

Link to original: https://github.com/sphinx-doc/sphinx/blob/9ebc46a74fa766460c450bd60cdef46b98492939/sphinx/util/docutils.py#L193
"""
self.body.append("</div>\n")
if not isinstance(node.next_node(descend=False, siblings=True), type(node)):
self.body.append("</div>\n")


def setup_translators(app: Sphinx):
"""Add bootstrap HTML functionality if we are using an HTML translator.
Expand Down
Loading