Skip to content

ENH: Allowing inline elements in sidenotes and marginnotes #641

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

Merged
merged 5 commits into from
Nov 8, 2022
Merged
Changes from 2 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
12 changes: 8 additions & 4 deletions src/sphinx_book_theme/_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,30 @@ def run(self, **kwargs: Any) -> None:
):
parent = foot_node.parent
# second children of footnote node is the content text
text = foot_node.children[1].astext()
foot_node_content = foot_node.children[1].children

sidenote = SideNoteNode()
para = docutil_nodes.inline()
# first children of footnote node is the label
label = foot_node.children[0].astext()

if text.startswith("{-}"):
if foot_node_content[0].astext().startswith("{-}"):
# marginnotes will have content starting with {-}
# remove the number so it doesn't show
para.attributes["classes"].append("marginnote")
para.append(docutil_nodes.Text(text.replace("{-}", "")))
foot_node_content[0] = docutil_nodes.Text(
foot_node_content[0].replace("{-}", "")
)
para.children = foot_node_content

sidenote.attributes["names"].append(f"marginnote-role-{label}")
else:
# sidenotes are the default behavior if no {-}
# in this case we keep the number
superscript = docutil_nodes.superscript("", label)
para.attributes["classes"].append("sidenote")
para.extend([superscript, docutil_nodes.Text(text)])
parachildren = [superscript] + foot_node_content
para.children = parachildren

sidenote.attributes["names"].append(f"sidenote-role-{label}")
sidenote.append(superscript)
Expand Down