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

Fix the ability to use autolinks #3

Merged
merged 2 commits into from Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 1 addition & 9 deletions sphinx_mdinclude/render.py
Expand Up @@ -190,15 +190,7 @@ def text(self, text):
"""
return text

def autolink(self, link, is_email=False):
"""Rendering a given link or email address.

:param link: link content or email address.
:param is_email: whether this is an email or not.
"""
return link

def link(self, link, text, title):
def link(self, link, text, title=None):
"""Rendering a given link with content and title.

:param link: href link for ``<a>`` tag.
Expand Down
3 changes: 2 additions & 1 deletion sphinx_mdinclude/sphinx.py
Expand Up @@ -8,6 +8,7 @@
from docutils import io, nodes, statemachine, utils
from docutils.core import ErrorString
from docutils.parsers import rst
from docutils.parsers.rst import directives as rst_directives
from docutils.utils import SafeString

from . import RestMarkdown
Expand Down Expand Up @@ -59,7 +60,7 @@ def run(self):
self.lineno - self.state_machine.input_offset - 1
)
source_dir = os.path.dirname(os.path.abspath(source))
path = rst.directives.path(self.arguments[0])
path = rst_directives.path(self.arguments[0])
path = os.path.normpath(os.path.join(source_dir, path))
path = utils.relative_path(None, path)
path = nodes.reprunicode(path)
Expand Down
7 changes: 6 additions & 1 deletion sphinx_mdinclude/tests/test_renderer.py
Expand Up @@ -132,7 +132,7 @@ def test_double_emphasis__(self):
out = self.conv(src)
self.assertEqual(out.replace("\n", ""), "**a**")

def test_autolink(self):
def test_not_an_autolink(self):
src = "link to http://example.com/ in sentence."
out = self.conv(src)
self.assertEqual(out, "\n" + src + "\n")
Expand All @@ -147,6 +147,11 @@ def test_anchor(self):
out = self.conv_no_check(src)
self.assertEqual(out, "\nthis is an :ref:`anchor link <anchor>`.\n")

def test_autolink(self):
src = "link <http://example.com>"
out = self.conv(src)
self.assertEqual(out, "\nlink `http://example.com <http://example.com>`_\n")

def test_link_title(self):
src = 'this is a [link](http://example.com/ "example").'
out = self.conv(src)
Expand Down