-
- Downloads
mkdocs-gitlab-plugin: initial commit, simple string transform
LICENSE
0 → 100644
mkdocs_gitlab_plugin/__init__.py
0 → 100644
mkdocs_gitlab_plugin/plugin.py
0 → 100644
#!/usr/bin/python3 | ||
import re | ||
import mkdocs | ||
class GitlabLinksPlugin(mkdocs.plugins.BasePlugin): | ||
''' | ||
Transform handles such as #1234, %56, !789 into links to a gitlab repository. | ||
A space before the #/%/! is needed. | ||
''' | ||
config_scheme = ( | ||
('gitlab_url', mkdocs.config.config_options.Type(mkdocs.utils.string_types, default='http://gitlab.com/XXX')), | ||
) | ||
GITLAB_LINK = re.compile(r' [#!%]\d+', re.UNICODE) | ||
|
||
def on_page_markdown(self, markdown, page=None, config=None, **kwargs): | ||
links = re.findall(self.GITLAB_LINK, markdown) | ||
gitlab_url = self.config['gitlab_url'] | ||
tokens = { | ||
' #': 'issues', | ||
' !': 'merge_requests', | ||
' %': 'milestones', | ||
' &': 'epic', | ||
} | ||
for link in links: | ||
if len(link) < 2: | ||
continue | ||
if not link[:2] in tokens: | ||
continue | ||
|
||
token_url = gitlab_url + '/' + tokens[link[:2]] | ||
# Build the actual link | ||
link_id = link[2:] | ||
link_new = " [%s](%s/%s)" % (link[1:], token_url, link_id) | ||
# print('%s -> %s' % (link, link_new)) | ||
# Replace the link in the markdown | ||
markdown = markdown.replace(link, link_new) | ||
|
||
return markdown | ||
\ No newline at end of file |
setup.py
0 → 100644
-
mentioned in issue vidjil#4149 (closed)
-
mentioned in merge request vidjil!584 (closed)