Skip to content

Commit

Permalink
Fix 168 (#174)
Browse files Browse the repository at this point in the history
* remove commas in xref substitution
* add a couple unit tests about graphviz ext
  • Loading branch information
2bndy5 authored Oct 26, 2022
1 parent 27dae22 commit dd7fac3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sphinx_immaterial/graphviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ def _replace_resolved_xrefs(node: sphinx.ext.graphviz.graphviz, code: str) -> st
else:
url = "#" + ref_node["refid"]
title = ref_node.get("reftitle")
replacement_text += f', href="{url}"'
replacement_text += f' href="{url}"'
if title is not None:
replacement_text += f", tooltip=<{html.escape(title)}>"
replacement_text += f" tooltip=<{html.escape(title)}>"
target = ref_node.get("target")
if target is not None:
replacement_text += f', target="{target}"'
replacement_text += f' target="{target}"'

ref_replacements[xref_id] = replacement_text

Expand Down
60 changes: 60 additions & 0 deletions tests/graphviz_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""Tests related to theme's patched graphviz ext."""
import pytest
from sphinx.testing.util import SphinxTestApp

WITH_BRACKETS = """
.. graphviz::
graph {
"foo()" [xref=":py:func:`foo()`"]
}
"""

WITHOUT_BRACKETS = """
.. graphviz::
graph {
subgraph cluster_foo {
xref=":py:func:`foo()`"
A_node
}
}
"""


@pytest.mark.parametrize(
"graph", [WITH_BRACKETS, WITHOUT_BRACKETS], ids=["with", "without"]
)
def test_square_brackets(immaterial_make_app, graph: str):
"""generate a graph with attributes not enclosed in square brackets"""
app: SphinxTestApp = immaterial_make_app(
extra_conf="\n".join(
[
'extensions.append("sphinx_immaterial.graphviz")',
# tests also run on Windows in CI
"graphviz_ignore_incorrect_font_metrics = True",
]
),
files={
"index.rst": """
The Test
========
A function
----------
.. py:function:: foo()
A graph
-------
{}""".format(
graph
)
},
)

app.build()
assert not app._warning.getvalue()

0 comments on commit dd7fac3

Please sign in to comment.