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 @@ +

#49

+

!87

+

6a09fde

+

fake-user/fake-repository#538

+

fake-user/fake-repository!539

+

fake-user/fake-repository@594b25d

+

fake-user/fake-repository#538

+

fake-user/fake-repository!539

+

fake-user/fake-repository@594b25d5

+

fake-user/fake-repository#538

+

fake-user/fake-repository!539

+

fake-user/fake-repository#538

+

fake-user/fake-repository!539

+

fake-user/fake-repository@594b25d

+

#49

+

fake-repository#87

\ 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 + + + +https://github.com/facelessuser/fake-repository/issues/87 diff --git a/tests/extensions/magiclink/magiclink.html b/tests/extensions/magiclink/magiclink.html index 92a77db81..9891e7b25 100644 --- a/tests/extensions/magiclink/magiclink.html +++ b/tests/extensions/magiclink/magiclink.html @@ -123,4 +123,5 @@

Repo Links

fake-user/fake-repository#538

fake-user/fake-repository!539

fake-user/fake-repository@594b25d

-

#49

\ No newline at end of file +

#49

+

fake-repository#87

\ 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 + +https://github.com/facelessuser/fake-repository/issues/87 diff --git a/tests/extensions/magiclink/tests.yml b/tests/extensions/magiclink/tests.yml index 3951b9e23..02c0c3d37 100644 --- a/tests/extensions/magiclink/tests.yml +++ b/tests/extensions/magiclink/tests.yml @@ -41,6 +41,13 @@ magiclink (gitlab): user: facelessuser repo: pymdown-extensions +magiclink (legacy): + extensions: + pymdownx.magiclink: + hide_protocol: false + repo_url_shortener: true + base_repo_url: https://github.com/facelessuser/pymdown-extensions + magiclink (shorthand): extensions: pymdownx.magiclink: