Skip to content

Commit

Permalink
Add domain config option to support GES.
Browse files Browse the repository at this point in the history
Fixes #15.
  • Loading branch information
waylan committed Dec 22, 2023
1 parent 24242b5 commit c0e911d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ a GitHub link, then the value of this option will be used.
A GitHub repository. If no repository is specified in a GitHub link, then the
value of this option will be used.

### domain

The domain of the host server for the repository. Defaults to
`https://github.com`, but may be set to the root of a GitHub Enterprise Server.

## Syntax

This extension implements shorthand to specify links to GitHub in various ways.
Expand Down Expand Up @@ -142,6 +147,10 @@ defined in `LICENSE`.

## Change Log

### Version 0.4 (unreleased)

Add `domain` configuration option in order to support GitHub Enterprise Servers.

### Version 0.3.1 (2023/07/28)

Include README in release.
Expand Down
10 changes: 5 additions & 5 deletions mdx_gh_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from xml.etree import ElementTree


URL_BASE = 'https://github.com'
RE_PARTS = dict(
USER=r'[-_\w]{1,39}\b',
REPO=r'[-_.\w]+\b'
Expand Down Expand Up @@ -65,10 +64,10 @@ def handleMatch(self, m):
repo = m.group(4)
if repo:
title = 'GitHub Repository: @{0}/{1}'.format(user, repo)
href = '{0}/{1}/{2}'.format(URL_BASE, user, repo)
href = '{0}/{1}/{2}'.format(self.config['domain'], user, repo)
else:
title = 'GitHub User: @{0}'.format(user)
href = '{0}/{1}'.format(URL_BASE, user)
href = '{0}/{1}'.format(self.config['domain'], user)
return _build_link(label, title, href, 'gh-link gh-mention')


Expand All @@ -86,7 +85,7 @@ def handleMatch(self, m):
repo = m.group(4) or self.config['repo']
num = m.group(5).lstrip('0')
title = 'GitHub Issue {0}/{1} #{2}'.format(user, repo, num)
href = '{0}/{1}/{2}/issues/{3}'.format(URL_BASE, user, repo, num)
href = '{0}/{1}/{2}/issues/{3}'.format(self.config['domain'], user, repo, num)
return _build_link(label, title, href, 'gh-link gh-issue')


Expand All @@ -109,13 +108,14 @@ def handleMatch(self, m):
label = short
user = self.config['user']
title = 'GitHub Commit: {0}/{1}@{2}'.format(user, repo, commit)
href = '{0}/{1}/{2}/commit/{3}'.format(URL_BASE, user, repo, commit)
href = '{0}/{1}/{2}/commit/{3}'.format(self.config['domain'], user, repo, commit)
return _build_link(label, title, href, 'gh-link gh-commit')


class GithubLinks(Extension):
def __init__(self, *args, **kwargs):
self.config = {
'domain': ['https://github.com', 'GitHub domain or Enterprise Server domain'],
'user': ['', 'GitHub user or organization.'],
'repo': ['', 'Repository name.']
}
Expand Down

0 comments on commit c0e911d

Please sign in to comment.