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

[docs-beta] Fix duplicate text when reference also contains an inline literal #26875

Merged
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 @@ -576,15 +576,35 @@ def depart_paragraph(self, node: Element) -> None:
self.end_state(wrap=False)

def visit_reference(self, node: Element) -> None:
ref_text = node.astext()
if "refuri" in node:
self.reference_uri = node["refuri"]
elif "refid" in node:
self.reference_uri = f"#{node['refid']}"
else:
self.messages.append('References must have "refuri" or "refid" attribute.')
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"]
elif "refid" in node:
self.reference_uri = f"#{node['refid']}"
else:
self.messages.append('References must have "refuri" or "refid" attribute.')
raise nodes.SkipNode
# 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
self.add_text(f"[{ref_text}]({self.reference_uri})")
else:
# Handle regular references
ref_text = node.astext()
if "refuri" in node:
self.reference_uri = node["refuri"]
elif "refid" in node:
self.reference_uri = f"#{node['refid']}"
else:
self.messages.append('References must have "refuri" or "refid" attribute.')
raise nodes.SkipNode
self.add_text(f"[{ref_text}]({self.reference_uri})")

def depart_reference(self, node: Element) -> None:
self.reference_uri = ""
Expand Down Expand Up @@ -803,7 +823,6 @@ def depart_block_quote(self, node: Element) -> None:

def visit_transition(self, node: Element) -> None:
self.new_state(0)
self.add_text("-----")

def depart_transition(self, node: Element) -> None:
self.end_state(wrap=False)
Expand Down
Loading