diff --git a/pymdownx/magiclink.py b/pymdownx/magiclink.py index 3bc4ba078..ed8cab76d 100644 --- a/pymdownx/magiclink.py +++ b/pymdownx/magiclink.py @@ -32,6 +32,7 @@ from .util import PymdownxDeprecationWarning import warnings import re +import os MAGIC_LINK = 1 MAGIC_AUTO_LINK = 2 @@ -203,12 +204,12 @@ def is_my_repo(self, provider, match): """Check if link is from our specified user and repo.""" # See if these links are from the specified repo. - return match.group(provider + '_base') + '/' == self.base + return self.base and match.group(provider + '_base') + '/' == self.base def is_my_user(self, provider, match): """Check if link is from our specified user.""" - return match.group(provider + '_base').startswith(self.base_user) + return self.base_user and match.group(provider + '_base').startswith(self.base_user) def run(self, root): """Shorten popular git repository links.""" @@ -494,8 +495,13 @@ def extendMarkdown(self, md, md_globals): provider_info = self.get_provider_info(config.get('provider', 'github')) # Setup base URL - base_url = config.get('base_repo_url', '') - base_user_url = None + base_url = config.get('base_repo_url', '').rstrip('/') + base_user_url = os.path.dirname(base_url) + if base_url: + base_url += "/" + if base_user_url: + base_user_url += "/" + if base_url: # pragma: no cover warnings.warn( "'base_repo_url' is deprecated and will be removed in the future.\n" diff --git a/tests/extensions/magiclink/magiclink (legacy).html b/tests/extensions/magiclink/magiclink (legacy).html new file mode 100644 index 000000000..7a94c89e6 --- /dev/null +++ b/tests/extensions/magiclink/magiclink (legacy).html @@ -0,0 +1,16 @@ +
+ + + + +fake-user/fake-repository@594b25d
+ + +fake-user/fake-repository@594b25d5
+ + + + +fake-user/fake-repository@594b25d
+ + \ No newline at end of file diff --git a/tests/extensions/magiclink/magiclink (legacy).txt b/tests/extensions/magiclink/magiclink (legacy).txt new file mode 100644 index 000000000..556b70fc0 --- /dev/null +++ b/tests/extensions/magiclink/magiclink (legacy).txt @@ -0,0 +1,31 @@ +https://github.com/facelessuser/pymdown-extensions/issues/49 + +https://github.com/facelessuser/pymdown-extensions/pull/87 + +https://github.com/facelessuser/pymdown-extensions/commit/6a09fde5c1cad66c660c3aa7792385c52c49e819 + +https://github.com/fake-user/fake-repository/issues/538 + +https://github.com/fake-user/fake-repository/pull/539 + +https://github.com/fake-user/fake-repository/commit/594b25d53798c30735da5a9be19c06cc94052a16 + +https://gitlab.com/fake-user/fake-repository/issues/538 + +https://gitlab.com/fake-user/fake-repository/merge_requests/539 + +https://gitlab.com/fake-user/fake-repository/commit/594b25d53798c30735da5a9be19c06cc94052a16 + +https://bitbucket.org/fake-user/fake-repository/issues/538/ + +https://bitbucket.org/fake-user/fake-repository/pull-requests/539/ + +https://bitbucket.org/fake-user/fake-repository/issues/538/optional-title + +https://bitbucket.org/fake-user/fake-repository/pull-requests/539/optional-title + +https://bitbucket.org/fake-user/fake-repository/commits/commit/594b25d53798c30735da5a9be19c06cc94052a16 + +fake-user/fake-repository@594b25d
- \ No newline at end of file + + \ No newline at end of file diff --git a/tests/extensions/magiclink/magiclink.txt b/tests/extensions/magiclink/magiclink.txt index da790a6ad..76515d0e4 100644 --- a/tests/extensions/magiclink/magiclink.txt +++ b/tests/extensions/magiclink/magiclink.txt @@ -247,3 +247,5 @@ https://bitbucket.org/fake-user/fake-repository/pull-requests/539/optional-title https://bitbucket.org/fake-user/fake-repository/commits/commit/594b25d53798c30735da5a9be19c06cc94052a16