Skip to content

Commit

Permalink
Ensure legacy repo links still works (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
facelessuser authored Nov 13, 2017
1 parent fe6adfc commit 7222253
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 5 deletions.
14 changes: 10 additions & 4 deletions pymdownx/magiclink.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from .util import PymdownxDeprecationWarning
import warnings
import re
import os

MAGIC_LINK = 1
MAGIC_AUTO_LINK = 2
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions tests/extensions/magiclink/magiclink (legacy).html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<p><a class="magiclink magiclink-issue" href="https://github.com/facelessuser/pymdown-extensions/issues/49" title="GitHub Issue: facelessuser/pymdown-extensions#49">#49</a></p>
<p><a class="magiclink magiclink-pull" href="https://github.com/facelessuser/pymdown-extensions/pull/87" title="GitHub Pull Request: facelessuser/pymdown-extensions!87">!87</a></p>
<p><a class="magiclink magiclink-commit" href="https://github.com/facelessuser/pymdown-extensions/commit/6a09fde5c1cad66c660c3aa7792385c52c49e819" title="GitHub Commit: facelessuser/pymdown-extensions@6a09fde">6a09fde</a></p>
<p><a class="magiclink magiclink-issue" href="https://github.com/fake-user/fake-repository/issues/538" title="GitHub Issue: fake-user/fake-repository#538">fake-user/fake-repository#538</a></p>
<p><a class="magiclink magiclink-pull" href="https://github.com/fake-user/fake-repository/pull/539" title="GitHub Pull Request: fake-user/fake-repository!539">fake-user/fake-repository!539</a></p>
<p><a class="magiclink magiclink-commit" href="https://github.com/fake-user/fake-repository/commit/594b25d53798c30735da5a9be19c06cc94052a16" title="GitHub Commit: fake-user/fake-repository@594b25d">fake-user/fake-repository@594b25d</a></p>
<p><a class="magiclink magiclink-issue" href="https://gitlab.com/fake-user/fake-repository/issues/538" title="GitLab Issue: fake-user/fake-repository#538">fake-user/fake-repository#538</a></p>
<p><a class="magiclink magiclink-pull" href="https://gitlab.com/fake-user/fake-repository/merge_requests/539" title="GitLab Pull Request: fake-user/fake-repository!539">fake-user/fake-repository!539</a></p>
<p><a class="magiclink magiclink-commit" href="https://gitlab.com/fake-user/fake-repository/commit/594b25d53798c30735da5a9be19c06cc94052a16" title="GitLab Commit: fake-user/fake-repository@594b25d5">fake-user/fake-repository@594b25d5</a></p>
<p><a class="magiclink magiclink-issue" href="https://bitbucket.org/fake-user/fake-repository/issues/538/" title="Bitbucket Issue: fake-user/fake-repository#538">fake-user/fake-repository#538</a></p>
<p><a class="magiclink magiclink-pull" href="https://bitbucket.org/fake-user/fake-repository/pull-requests/539/" title="Bitbucket Pull Request: fake-user/fake-repository!539">fake-user/fake-repository!539</a></p>
<p><a class="magiclink magiclink-issue" href="https://bitbucket.org/fake-user/fake-repository/issues/538/optional-title" title="Bitbucket Issue: fake-user/fake-repository#538">fake-user/fake-repository#538</a></p>
<p><a class="magiclink magiclink-pull" href="https://bitbucket.org/fake-user/fake-repository/pull-requests/539/optional-title" title="Bitbucket Pull Request: fake-user/fake-repository!539">fake-user/fake-repository!539</a></p>
<p><a class="magiclink magiclink-commit" href="https://bitbucket.org/fake-user/fake-repository/commits/commit/594b25d53798c30735da5a9be19c06cc94052a16" title="Bitbucket Commit: fake-user/fake-repository@594b25d">fake-user/fake-repository@594b25d</a></p>
<p><a class="magiclink magiclink-issue" href="https://github.com/facelessuser/pymdown-extensions/issues/49" title="GitHub Issue: facelessuser/pymdown-extensions#49">#49</a></p>
<p><a class="magiclink magiclink-issue" href="https://github.com/facelessuser/fake-repository/issues/87" title="GitHub Issue: facelessuser/fake-repository#87">fake-repository#87</a></p>
31 changes: 31 additions & 0 deletions tests/extensions/magiclink/magiclink (legacy).txt
Original file line number Diff line number Diff line change
@@ -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/pymdown-extensions/issues/49>

https://github.com/facelessuser/fake-repository/issues/87
3 changes: 2 additions & 1 deletion tests/extensions/magiclink/magiclink.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,5 @@ <h1>Repo Links</h1>
<p><a class="magiclink magiclink-issue" href="https://bitbucket.org/fake-user/fake-repository/issues/538/optional-title" title="Bitbucket Issue: fake-user/fake-repository#538">fake-user/fake-repository#538</a></p>
<p><a class="magiclink magiclink-pull" href="https://bitbucket.org/fake-user/fake-repository/pull-requests/539/optional-title" title="Bitbucket Pull Request: fake-user/fake-repository!539">fake-user/fake-repository!539</a></p>
<p><a class="magiclink magiclink-commit" href="https://bitbucket.org/fake-user/fake-repository/commits/commit/594b25d53798c30735da5a9be19c06cc94052a16" title="Bitbucket Commit: fake-user/fake-repository@594b25d">fake-user/fake-repository@594b25d</a></p>
<p><a class="magiclink magiclink-issue" href="https://github.com/facelessuser/pymdown-extensions/issues/49" title="GitHub Issue: facelessuser/pymdown-extensions#49">#49</a></p>
<p><a class="magiclink magiclink-issue" href="https://github.com/facelessuser/pymdown-extensions/issues/49" title="GitHub Issue: facelessuser/pymdown-extensions#49">#49</a></p>
<p><a class="magiclink magiclink-issue" href="https://github.com/facelessuser/fake-repository/issues/87" title="GitHub Issue: facelessuser/fake-repository#87">fake-repository#87</a></p>
2 changes: 2 additions & 0 deletions tests/extensions/magiclink/magiclink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/pymdown-extensions/issues/49>

https://github.com/facelessuser/fake-repository/issues/87
7 changes: 7 additions & 0 deletions tests/extensions/magiclink/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7222253

Please sign in to comment.