Skip to content

Commit

Permalink
Add slash space between type xrefs and surrounding text
Browse files Browse the repository at this point in the history
These escapes make sure that any rst in the xrefs renders as expected
  • Loading branch information
hoodmane committed Sep 28, 2023
1 parent 7d9916b commit 81ad279
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions sphinx_js/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,14 @@ def strs() -> Iterator[str]:
s = "".join(strs())
if escape:
s = rst.escape(s)
res.append(s)
if s:
res.append(s)
if not xref:
break
res.append(self.render_xref(xref[0], escape))

return "".join(res)
print(res)
return r"\ ".join(res)

def render_xref(self, s: TypeXRef, escape: bool = False) -> str:
result = self._xref_formatter(s)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ def test_render_xref(function_renderer: AutoFunctionRenderer):
function_renderer.render_type([TypeXRefInternal(name="A", path=["a.", "A"])])
== ":js:class:`A`"
)
assert (
function_renderer.render_type(
[TypeXRefInternal(name="A", path=["a.", "A"]), "[]"]
)
== r":js:class:`A`\ []"
)
xref_external = TypeXRefExternal("A", "blah", "a.ts", "a.A")
assert function_renderer.render_type([xref_external]) == "A"
res = []
Expand Down

0 comments on commit 81ad279

Please sign in to comment.