Skip to content

Commit

Permalink
Also fix literal_emphasis nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
PedramNavid committed Jan 7, 2025
1 parent 49d6ca3 commit 592471e
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,10 @@ def depart_paragraph(self, node: Element) -> None:
self.end_state(wrap=False)

def visit_reference(self, node: Element) -> None:
if len(node.children) == 1 and isinstance(node.children[0], nodes.literal):
# For references containing only a literal, use the literal text
if len(node.children) == 1 and isinstance(
node.children[0], (nodes.literal, addnodes.literal_emphasis)
):
# For references containing only a literal or literal_emphasis, use the literal text
ref_text = node.children[0].astext()
if "refuri" in node:
self.reference_uri = node["refuri"]
Expand All @@ -586,7 +588,11 @@ def visit_reference(self, node: Element) -> None:
else:
self.messages.append('References must have "refuri" or "refid" attribute.')
raise nodes.SkipNode
self.add_text(f"[`{ref_text}`]({self.reference_uri})")
# Use _emphasis for literal_emphasis nodes
if isinstance(node.children[0], addnodes.literal_emphasis):
self.add_text(f"[*{ref_text}*]({self.reference_uri})")
else:
self.add_text(f"[`{ref_text}`]({self.reference_uri})")
raise nodes.SkipNode
else:
# Handle regular references
Expand Down

0 comments on commit 592471e

Please sign in to comment.