diff --git a/sphinx_mdinclude/render.py b/sphinx_mdinclude/render.py index df4a999..75ca587 100644 --- a/sphinx_mdinclude/render.py +++ b/sphinx_mdinclude/render.py @@ -241,6 +241,17 @@ def link(self, text: str, url: str, title: Optional[str] = None) -> str: text = re.sub(r":target: (.*)\n", f":target: {url}\n", text) return text + if text.startswith("``") and text.endswith("``"): + # Return raw HTML for inline code: + html = ( + '' + '{}' + "".format(text[2:-2].replace("`", "`")) + ) + return self._raw_html( + '{text}'.format(url=url, text=html) + ) + underscore = "_" if title: return self._raw_html( diff --git a/sphinx_mdinclude/tests/test_renderer.py b/sphinx_mdinclude/tests/test_renderer.py index ac7ba5f..fed4edf 100644 --- a/sphinx_mdinclude/tests/test_renderer.py +++ b/sphinx_mdinclude/tests/test_renderer.py @@ -147,6 +147,17 @@ def test_inline_code_with_opening_and_closing_space_and_backtick(self) -> None: '`a``', ) + def test_inline_code_within_link(self) -> None: + src = "[`foobar`](https://example.com)" + out = self.conv(src) + self.assertEqual( + out.strip(), + ".. role:: raw-html-md(raw)\n" + " :format: html\n\n\n" + ':raw-html-md:`' + 'foobar`', + ) + def test_strikethrough(self) -> None: src = "~~a~~" self.conv(src)