diff --git a/src/sphinx_book_theme/_transforms.py b/src/sphinx_book_theme/_transforms.py index 1b5dc2d1..f97aee6f 100644 --- a/src/sphinx_book_theme/_transforms.py +++ b/src/sphinx_book_theme/_transforms.py @@ -31,18 +31,21 @@ 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: @@ -50,7 +53,8 @@ def run(self, **kwargs: Any) -> None: # 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) diff --git a/tests/sites/base/page2.md b/tests/sites/base/page2.md index 42909a9f..ab500a8b 100644 --- a/tests/sites/base/page2.md +++ b/tests/sites/base/page2.md @@ -7,13 +7,13 @@ Some text to test out one sidenote[^myref] and another sidenote[^3] [^myref]: This is a sidenote. -[^3]: This is another sidenote. +[^3]: This is *another* **sidenote**. ## Marginnotes Some text to test out one marginnote[^somemargin] and another marginnote[^6] -[^somemargin]: {>} This is a marginnote. -[^6]: {>} This is another marginnote. +[^somemargin]: {-} This is a marginnote. +[^6]: {-} This is *another* **marginnote**. This is the end of Page 2. diff --git a/tests/test_build/test_marginnote.html b/tests/test_build/test_marginnote.html index c2f395c1..729b996e 100644 --- a/tests/test_build/test_marginnote.html +++ b/tests/test_build/test_marginnote.html @@ -10,34 +10,25 @@
Some text to test out one marginnote -
diff --git a/tests/test_build/test_sidenote.html b/tests/test_build/test_sidenote.html index ffaf22b7..6e6ada4f 100644 --- a/tests/test_build/test_sidenote.html +++ b/tests/test_build/test_sidenote.html @@ -37,7 +37,14 @@