Skip to content
Open
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
29 changes: 19 additions & 10 deletions sphinx_panels/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,34 @@ def setup_link_button(app):

def create_ref_node(link_type, uri, text, tooltip):
innernode = nodes.inline(text, text)
if link_type == "ref":
if link_type == "url":
ref_node = nodes.reference()
ref_node["refuri"] = uri
if tooltip:
ref_node["reftitle"] = tooltip
else:
if link_type == "ref":
link_type = "any"
if ":" in link_type:
refdomain, reftype = link_type.split(":", 1)
classes = ['xref', refdomain, "{0}-{1}".format(refdomain, reftype)]
else:
refdomain, reftype = "", link_type
classes = ['xref', reftype]
# breakpoint()
ref_node = addnodes.pending_xref(
reftarget=unquote(uri),
reftype="any",
reftype=reftype,
# refdoc=self.env.docname,
refdomain="",
refdomain=refdomain,
refexplicit=True,
refwarn=True,
)
innernode["classes"] = ["xref", "any"]
innernode["classes"] = classes
# if tooltip:
# ref_node["reftitle"] = tooltip
# ref_node["title"] = tooltip
# TODO this doesn't work
else:
ref_node = nodes.reference()
ref_node["refuri"] = uri
if tooltip:
ref_node["reftitle"] = tooltip
ref_node += innernode
return ref_node

Expand All @@ -48,7 +57,7 @@ class LinkButton(SphinxDirective):
required_arguments = 1
final_argument_whitespace = True
option_spec = {
"type": lambda arg: directives.choice(arg, ("url", "ref")),
"type": lambda arg: directives.choice(arg, ("url", "ref", "any", "doc", "std:ref")),
Copy link
Author

@jorisvandenbossche jorisvandenbossche Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is of course not robust to list all options when going this way (as it could also be "py:func", etc), but was just for trying it out.

"text": directives.unchanged,
"tooltip": directives.unchanged,
"classes": directives.unchanged,
Expand Down