Skip to content

Commit 0a2899b

Browse files
committed
project => repo
1 parent aa0df06 commit 0a2899b

File tree

4 files changed

+71
-69
lines changed

4 files changed

+71
-69
lines changed

README.md

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Python-Markdown Github-Links Extension
22

3-
An extension to Python-Markdown which adds support for a shorthand for GitHub
4-
specific links.
3+
An extension to Python-Markdown which adds support for shorthand links to GitHub
4+
users, repositories, issues and commits.
55

66
## Installation
77

@@ -31,7 +31,7 @@ markdown.markdown(
3131
src,
3232
extensions=['mdx_gh_links'],
3333
extension_configs={
34-
'mdx_gh_links': {'user': 'foo', 'project': 'bar'}
34+
'mdx_gh_links': {'user': 'foo', 'repo': 'bar'}
3535
}
3636
)
3737
```
@@ -41,7 +41,7 @@ markdown.markdown(
4141

4242
```python
4343
from mdx_gh_links import GithubLinks
44-
markdown.markdown(src, extensions=[GithubLinks(user='foo', project='bar')])
44+
markdown.markdown(src, extensions=[GithubLinks(user='foo', repo='bar')])
4545
```
4646

4747
The following configuration options are available:
@@ -51,10 +51,10 @@ The following configuration options are available:
5151
A GitHub user name or organization. If no user or organization is specified in
5252
a GitHub link, then the value of this option will be used.
5353

54-
#### project
54+
#### repo
5555

56-
A GitHub project. If no project is specified in a GitHub link, then the value
57-
of this option will be used.
56+
A GitHub repository. If no repository is specified in a GitHub link, then the
57+
value of this option will be used.
5858

5959
## Syntax
6060

@@ -65,14 +65,14 @@ unique to that type of link. See each type for the specific class assigned.
6565

6666
### Mentions
6767

68-
Link directly to a GitHub user, organization or project. Note that no
69-
verification is made that an actual user, organization or project exists. As the
70-
syntax does not differentiate between users and organizations, all organizations
71-
are assumed to be users. However, this assumption is only reflected in the
72-
title of a link.
68+
Link directly to a GitHub user, organization or repository. Note that no
69+
verification is made that an actual user, organization or repository exists. As
70+
the syntax does not differentiate between users and organizations, all
71+
organizations are assumed to be users. However, this assumption is only
72+
reflected in the title of a link.
7373

7474
Mentions use the format `@{user}` to link to a user or organization and
75-
`@{user}/{project}` to link to a project. The defaults defined in the
75+
`@{user}/{repo}` to link to a repository. The defaults defined in the
7676
configuration options are ignored by mentions. A mention may be escaped by
7777
adding a backslash immediately before the at sign (`@`).
7878

@@ -81,11 +81,11 @@ All mentions are assigned the `gh-mention` class.
8181
The following table provides some examples:
8282

8383
| shorthand | href | rendered result |
84-
| ----------- | ---------------------------- | ------------------------------------------------------------------|
85-
| `@foo` | `https://github.com/foo` | [@foo](https://github.com/foo "GitHub User: @foo") |
86-
| `@foo/bar` | `https://github.com/foo/bar` | [@foo/bar](https://github.com/foo/bar "GitHub Project: @foo/bar") |
87-
| `\@123` | | @foo |
88-
| `\@foo/bar` | | @foo/bar |
84+
| ----------- | ---------------------------- | -------------------------------------------------------------------- |
85+
| `@foo` | `https://github.com/foo` | [@foo](https://github.com/foo "GitHub User: @foo") |
86+
| `@foo/bar` | `https://github.com/foo/bar` | [@foo/bar](https://github.com/foo/bar "GitHub Repository: @foo/bar") |
87+
| `\@123` | | @foo |
88+
| `\@foo/bar` | | @foo/bar |
8989

9090
### Issues
9191

@@ -94,19 +94,19 @@ is made that an actual issue or PR exists. As the syntax does not differentiate
9494
between Issues and PRs, all URLs point to "issues". Fortunately, GitHub will
9595
properly redirect an issue URL to a PR URL if appropriate.
9696

97-
Issue links use the format `#{num}` or `{user}/{project}#{num}`. `{num}` is the
98-
number assigned to the issue or PR. `{user}` and `{project}` will use the
97+
Issue links use the format `#{num}` or `{user}/{repo}#{num}`. `{num}` is the
98+
number assigned to the issue or PR. `{user}` and `{repo}` will use the
9999
defaults defined in the configuration options if not provided. An issue link may
100100
be escaped by adding a backslash immediately before the hash mark (`#`).
101101

102102
All issue links are assigned the `gh-issue` class.
103103

104104
The following table provides various examples (with the defaults set as
105-
`user='user', project='project'`):
105+
`user='user', repo='repo'`):
106106

107107
| shorthand | href | rendered result |
108108
| -------------- | -------------------------------------------- | ----------------------------------------------------------------------------------- |
109-
| `#123` | `https://github.com/user/project/issues/123` | [#123](https://github.com/user/project/issues/123 "GitHub Issue user/project #123") |
109+
| `#123` | `https://github.com/user/repo/issues/123` | [#123](https://github.com/user/repo/issues/123 "GitHub Issue user/repo #123") |
110110
| `foo/bar#123` | `https://github.com/foo/bar/issues/123` | [foo/bar#123](https://github.com/foo/bar/issues/123 "GitHub Issue foo/bar #123") |
111111
| `\#123` | | #123 |
112112
| `foo/bar\#123` | | foo/bar#123 |
@@ -117,21 +117,21 @@ Link directly to a GitHub Commit. Note that no verification is made that an
117117
actual commit exists.
118118

119119
Commit links consist of a complete 40 character SHA hash and may optionally be
120-
prefaced by `{user}@` or `{user/project}@`. `{user}` and `{project}` will use
121-
the defaults defined in the configuration options if not provided. To avoid a 40
120+
prefaced by `{user}@` or `{user/repo}@`. `{user}` and `{repo}` will use the
121+
defaults defined in the configuration options if not provided. To avoid a 40
122122
character hash from being linked, wrap it in a code span.
123123

124-
All issue links are assigned the `gh-commit` class.
124+
All commit links are assigned the `gh-commit` class.
125125

126126
The following table provides various examples (with the defaults set as
127-
`user='user', project='project'`):
128-
129-
| shorthand | href | rendered result |
130-
| -------------------------------------------------- | --------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------|
131-
| `72df691791fb36f00cf5363fefe757c8d3042656` | `https://github.com/user/project/commit/72df691791fb36f00cf5363fefe757c8d3042656` | [72df691](https://github.com/user/project/commit/72df691791fb36f00cf5363fefe757c8d3042656 "GitHub Commit: user/project@72df691791fb36f00cf5363fefe757c8d3042656") |
132-
| `foo@72df691791fb36f00cf5363fefe757c8d3042656` | `https://github.com/foo/project/commit/72df691791fb36f00cf5363fefe757c8d3042656` | [foo@72df691](https://github.com/foo/project/commit/72df691791fb36f00cf5363fefe757c8d3042656 "GitHub Commit: foo/project@72df691791fb36f00cf5363fefe757c8d3042656") |
133-
| `foo/bar@72df691791fb36f00cf5363fefe757c8d3042656` | `https://github.com/foo/bar/commit/72df691791fb36f00cf5363fefe757c8d3042656` | [foo/bar@72df691](https://github.com/foo/bar/commit/72df691791fb36f00cf5363fefe757c8d3042656 "GitHub Commit: foo/bar@72df691791fb36f00cf5363fefe757c8d3042656") |
134-
| `` `72df691791fb36f00cf5363fefe757c8d3042656` `` | | `72df691791fb36f00cf5363fefe757c8d3042656` |
127+
`user='user', repo='repo'`):
128+
129+
| shorthand | href | rendered result |
130+
| -------------------------------------------------- | --------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------|
131+
| `72df691791fb36f00cf5363fefe757c8d3042656` | `https://github.com/user/repo/commit/72df691791fb36f00cf5363fefe757c8d3042656` | [72df691](https://github.com/user/repo/commit/72df691791fb36f00cf5363fefe757c8d3042656 "GitHub Commit: user/repo@72df691791fb36f00cf5363fefe757c8d3042656") |
132+
| `foo@72df691791fb36f00cf5363fefe757c8d3042656` | `https://github.com/foo/repo/commit/72df691791fb36f00cf5363fefe757c8d3042656` | [foo@72df691](https://github.com/foo/repo/commit/72df691791fb36f00cf5363fefe757c8d3042656 "GitHub Commit: foo/repo@72df691791fb36f00cf5363fefe757c8d3042656") |
133+
| `foo/bar@72df691791fb36f00cf5363fefe757c8d3042656` | `https://github.com/foo/bar/commit/72df691791fb36f00cf5363fefe757c8d3042656` | [foo/bar@72df691](https://github.com/foo/bar/commit/72df691791fb36f00cf5363fefe757c8d3042656 "GitHub Commit: foo/bar@72df691791fb36f00cf5363fefe757c8d3042656") |
134+
| `` `72df691791fb36f00cf5363fefe757c8d3042656` `` | | `72df691791fb36f00cf5363fefe757c8d3042656` |
135135

136136
## License
137137

mdx_gh_links.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
URL_BASE = 'https://github.com'
3939
RE_PARTS = dict(
4040
USER=r'[-_\w]{1,39}\b',
41-
PROJECT=r'[-_.\w]+\b'
41+
REPO=r'[-_.\w]+\b'
4242
)
4343

4444

@@ -53,17 +53,17 @@ def _build_link(label, title, href, classes):
5353

5454
class MentionPattern(Pattern):
5555
def __init__(self, config, md):
56-
MENTION_RE = r'(@({USER})(?:\/({PROJECT}))?)'.format(**RE_PARTS)
56+
MENTION_RE = r'(@({USER})(?:\/({REPO}))?)'.format(**RE_PARTS)
5757
super(MentionPattern, self).__init__(MENTION_RE, md)
5858
self.config = config
5959

6060
def handleMatch(self, m):
6161
label = m.group(2)
6262
user = m.group(3)
63-
project = m.group(4)
64-
if project:
65-
title = 'GitHub Project: @{0}/{1}'.format(user, project)
66-
href = '{0}/{1}/{2}'.format(URL_BASE, user, project)
63+
repo = m.group(4)
64+
if repo:
65+
title = 'GitHub Repository: @{0}/{1}'.format(user, repo)
66+
href = '{0}/{1}/{2}'.format(URL_BASE, user, repo)
6767
else:
6868
title = 'GitHub User: @{0}'.format(user)
6969
href = '{0}/{1}'.format(URL_BASE, user)
@@ -72,46 +72,46 @@ def handleMatch(self, m):
7272

7373
class IssuePattern(Pattern):
7474
def __init__(self, config, md):
75-
ISSUE_RE = r'((?:({USER})\/({PROJECT}))?#([0-9]+))'.format(**RE_PARTS)
75+
ISSUE_RE = r'((?:({USER})\/({REPO}))?#([0-9]+))'.format(**RE_PARTS)
7676
super(IssuePattern, self).__init__(ISSUE_RE, md)
7777
self.config = config
7878

7979
def handleMatch(self, m):
8080
label = m.group(2)
8181
user = m.group(3) or self.config['user']
82-
project = m.group(4) or self.config['project']
82+
repo = m.group(4) or self.config['repo']
8383
num = m.group(5).lstrip('0')
84-
title = 'GitHub Issue {0}/{1} #{2}'.format(user, project, num)
85-
href = '{0}/{1}/{2}/issues/{3}'.format(URL_BASE, user, project, num)
84+
title = 'GitHub Issue {0}/{1} #{2}'.format(user, repo, num)
85+
href = '{0}/{1}/{2}/issues/{3}'.format(URL_BASE, user, repo, num)
8686
return _build_link(label, title, href, 'gh-link gh-issue')
8787

8888

8989
class CommitPattern(Pattern):
9090
def __init__(self, config, md):
91-
COMMIT_RE = r'((?:({USER})(?:\/({PROJECT}))?@|\b)([a-f0-9]{{40}})\b)'.format(**RE_PARTS)
91+
COMMIT_RE = r'((?:({USER})(?:\/({REPO}))?@|\b)([a-f0-9]{{40}})\b)'.format(**RE_PARTS)
9292
super(CommitPattern, self).__init__(COMMIT_RE, md)
9393
self.config = config
9494

9595
def handleMatch(self, m):
9696
user = m.group(3)
97-
project = m.group(4) or self.config['project']
97+
repo = m.group(4) or self.config['repo']
9898
commit = m.group(5)
9999
short = commit[:7]
100100
if user:
101101
label = '{0}@{1}'.format(m.group(2).split('@')[0], short)
102102
else:
103103
label = short
104104
user = self.config['user']
105-
title = 'GitHub Commit: {0}/{1}@{2}'.format(user, project, commit)
106-
href = '{0}/{1}/{2}/commit/{3}'.format(URL_BASE, user, project, commit)
105+
title = 'GitHub Commit: {0}/{1}@{2}'.format(user, repo, commit)
106+
href = '{0}/{1}/{2}/commit/{3}'.format(URL_BASE, user, repo, commit)
107107
return _build_link(label, title, href, 'gh-link gh-commit')
108108

109109

110110
class GithubLinks(Extension):
111111
def __init__(self, *args, **kwargs):
112112
self.config = {
113113
'user': ['', 'GitHub user or organization.'],
114-
'project': ['', 'Project name.']
114+
'repo': ['', 'Repository name.']
115115
}
116116
super(GithubLinks, self).__init__(*args, **kwargs)
117117

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
setup(
3838
name='Python-Markdown Github Links',
39+
description='An extension to Python-Markdown which adds support for '
40+
'shorthand links to GitHub users, repositories, issues and commits.',
3941
version='0.1',
4042
author='Waylan Limberg',
4143
author_email='waylan.limberg@icloud.com',

test_gh_links.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class TestGithubLinks(unittest.TestCase):
4040

4141
def assertMarkdownRenders(self, source, expected, **kwargs):
4242
'Test that source Markdown text renders to expected output.'
43-
configs = {'user': 'Python-Markdown', 'project': 'github-links'}
43+
configs = {'user': 'Python-Markdown', 'repo': 'github-links'}
4444
configs.update(kwargs)
4545
output = markdown(source, extensions=[GithubLinks(**configs)])
4646
self.assertMultiLineEqual(output, expected)
@@ -68,26 +68,26 @@ def test_non_issue(self):
6868
'<p>Issue #notanissue.</p>',
6969
)
7070

71-
def test_issue_with_project(self):
71+
def test_issue_with_repo(self):
7272
self.assertMarkdownRenders(
73-
'Issue Organization/Project#123.',
73+
'Issue Organization/Repo#123.',
7474
'<p>Issue <a class="gh-link gh-issue" '
75-
'href="/Organization/Project/issues/123" '
76-
'title="GitHub Issue Organization/Project #123">Organization/Project#123</a>.</p>',
75+
'href="/Organization/Repo/issues/123" '
76+
'title="GitHub Issue Organization/Repo #123">Organization/Repo#123</a>.</p>',
7777
)
7878

79-
def test_issue_leading_zero_with_project(self):
79+
def test_issue_leading_zero_with_repo(self):
8080
self.assertMarkdownRenders(
81-
'Issue Organization/Project#012.',
81+
'Issue Organization/Repo#012.',
8282
'<p>Issue <a class="gh-link gh-issue" '
83-
'href="/Organization/Project/issues/12" '
84-
'title="GitHub Issue Organization/Project #12">Organization/Project#012</a>.</p>',
83+
'href="/Organization/Repo/issues/12" '
84+
'title="GitHub Issue Organization/Repo #12">Organization/Repo#012</a>.</p>',
8585
)
8686

87-
def test_non_issue_with_project(self):
87+
def test_non_issue_with_repo(self):
8888
self.assertMarkdownRenders(
89-
'Issue Organization/Project#notanissue.',
90-
'<p>Issue Organization/Project#notanissue.</p>',
89+
'Issue Organization/Repo#notanissue.',
90+
'<p>Issue Organization/Repo#notanissue.</p>',
9191
)
9292

9393
def test_escaped_issue(self):
@@ -96,10 +96,10 @@ def test_escaped_issue(self):
9696
'<p>Issue #123.</p>',
9797
)
9898

99-
def test_escaped_issue_with_project(self):
99+
def test_escaped_issue_with_repo(self):
100100
self.assertMarkdownRenders(
101-
'Issue Organization/Project\#123.',
102-
'<p>Issue Organization/Project#123.</p>',
101+
'Issue Organization/Repo\#123.',
102+
'<p>Issue Organization/Repo#123.</p>',
103103
)
104104

105105
# Mention Tests
@@ -125,23 +125,23 @@ def test_escape_mention_user(self):
125125
'<p>User @foo.</p>',
126126
)
127127

128-
def test_mention_project(self):
128+
def test_mention_repo(self):
129129
self.assertMarkdownRenders(
130130
'User @foo/bar.',
131131
'<p>User <a class="gh-link gh-mention" '
132132
'href="https://github.com/foo/bar" '
133-
'title="GitHub Project: @foo/bar">@foo/bar</a>.</p>',
133+
'title="GitHub Repository: @foo/bar">@foo/bar</a>.</p>',
134134
)
135135

136-
def test_mention_project_complex(self):
136+
def test_mention_repo_complex(self):
137137
self.assertMarkdownRenders(
138138
'User @foo/bar_baz-42.0.',
139139
'<p>User <a class="gh-link gh-mention" '
140140
'href="https://github.com/foo/bar_baz-42.0" '
141-
'title="GitHub Project: @foo/bar_baz-42.0">@foo/bar_baz-42.0</a>.</p>',
141+
'title="GitHub Repository: @foo/bar_baz-42.0">@foo/bar_baz-42.0</a>.</p>',
142142
)
143143

144-
def test_escape_mention_project(self):
144+
def test_escape_mention_repo(self):
145145
self.assertMarkdownRenders(
146146
'User \@foo/bar.',
147147
'<p>User @foo/bar.</p>',
@@ -165,7 +165,7 @@ def test_commit_user(self):
165165
'title="GitHub Commit: foo/github-links@15abb8b3b02df0e380e9b4c71f3bd206c9751a93"''>foo@15abb8b</a>.</p>',
166166
)
167167

168-
def test_commit_user_project(self):
168+
def test_commit_user_repo(self):
169169
self.assertMarkdownRenders(
170170
'Commit foo/bar@a75944f869d728ca9bc5472daf3f249b6c341308.',
171171
'<p>Commit <a class="gh-link gh-commit" '

0 commit comments

Comments
 (0)