diff --git a/README.md b/README.md index 5ece593..07215ba 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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. diff --git a/mdx_gh_links.py b/mdx_gh_links.py index 399c490..f4c7b4a 100644 --- a/mdx_gh_links.py +++ b/mdx_gh_links.py @@ -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' @@ -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') @@ -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') @@ -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.'] }