Skip to content

Commit 8b3b575

Browse files
committed
Ignore within Markdown links.
1 parent df8a4fa commit 8b3b575

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ defined in `LICENSE`.
142142

143143
## Change Log
144144

145+
### Dev Version
146+
147+
Ignore mentions/issues/commits within Markdown links.
148+
145149
### Version 0.1 (2017/11/10)
146150

147151
The initial release.

mdx_gh_links.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def _build_link(label, title, href, classes):
5252

5353

5454
class MentionPattern(Pattern):
55+
ANCESTOR_EXCLUDES = ('a',)
56+
5557
def __init__(self, config, md):
5658
MENTION_RE = r'(@({USER})(?:\/({REPO}))?)'.format(**RE_PARTS)
5759
super(MentionPattern, self).__init__(MENTION_RE, md)
@@ -71,6 +73,8 @@ def handleMatch(self, m):
7173

7274

7375
class IssuePattern(Pattern):
76+
ANCESTOR_EXCLUDES = ('a',)
77+
7478
def __init__(self, config, md):
7579
ISSUE_RE = r'((?:({USER})\/({REPO}))?#([0-9]+))'.format(**RE_PARTS)
7680
super(IssuePattern, self).__init__(ISSUE_RE, md)
@@ -87,6 +91,8 @@ def handleMatch(self, m):
8791

8892

8993
class CommitPattern(Pattern):
94+
ANCESTOR_EXCLUDES = ('a',)
95+
9096
def __init__(self, config, md):
9197
COMMIT_RE = r'((?:({USER})(?:\/({REPO}))?@|\b)([a-f0-9]{{40}})\b)'.format(**RE_PARTS)
9298
super(CommitPattern, self).__init__(COMMIT_RE, md)
@@ -122,5 +128,5 @@ def extendMarkdown(self, md, md_globals):
122128
md.inlinePatterns['commit'] = CommitPattern(self.getConfigs(), md)
123129

124130

125-
def makeExtension(*args, **kwargs):
131+
def makeExtension(*args, **kwargs): # pragma: no cover
126132
return GithubLinks(*args, **kwargs)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
url='https://github.com/Python-Markdown/github-links/',
4545
license='BSD License',
4646
py_modules=['mdx_gh_links'],
47-
install_requires=['markdown>=2.5'],
47+
install_requires=['markdown>=2.6.11'],
4848
classifiers=[
4949
'Development Status :: 4 - Beta',
5050
'License :: OSI Approved :: BSD License',

test_gh_links.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ def test_escaped_issue_with_repo(self):
102102
'<p>Issue Organization/Repo#123.</p>',
103103
)
104104

105+
def test_issue_in_link(self):
106+
self.assertMarkdownRenders(
107+
'[Issue #123](#).',
108+
'<p><a href="#">Issue #123</a>.</p>',
109+
)
110+
105111
# Mention Tests
106112
def test_mention_user(self):
107113
self.assertMarkdownRenders(
@@ -147,6 +153,12 @@ def test_escape_mention_repo(self):
147153
'<p>User @foo/bar.</p>',
148154
)
149155

156+
def test_mention_in_link(self):
157+
self.assertMarkdownRenders(
158+
'User [@foo](#).',
159+
'<p>User <a href="#">@foo</a>.</p>',
160+
)
161+
150162
# Commit Tests
151163
def test_commit(self):
152164
self.assertMarkdownRenders(
@@ -179,6 +191,12 @@ def test_escape_commit(self):
179191
'<p>Commit <code>83fb46b3b7ab8ad4316681fc4637c521da265f1d</code>.</p>',
180192
)
181193

194+
def test_commit_in_link(self):
195+
self.assertMarkdownRenders(
196+
'Commit [83fb46b3b7ab8ad4316681fc4637c521da265f1d](#).',
197+
'<p>Commit <a href="#">83fb46b3b7ab8ad4316681fc4637c521da265f1d</a>.</p>',
198+
)
199+
182200

183201
if __name__ == '__main__':
184202
unittest.main()

0 commit comments

Comments
 (0)