Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
vidjil
vidjil
Commits
0b2fe9a2
Commit
0b2fe9a2
authored
Jan 22, 2020
by
Mathieu Giraud
Browse files
tools/mkdocs-issue.py
parent
1782fcf5
Changes
1
Hide whitespace changes
Inline
Side-by-side
tools/mkdocs-issues.py
0 → 100644
View file @
0b2fe9a2
import
re
import
os
from
mkdocs.config
import
Config
from
mkdocs.plugins
import
BasePlugin
class
IssueLinkPlugin
(
BasePlugin
):
MD_LINK
=
re
.
compile
(
r
']\(([^)]*)\)'
,
re
.
UNICODE
)
def
_should_ignore_link
(
self
,
link
):
return
link
.
startswith
(
u
"http"
)
or
link
.
startswith
(
u
"#"
)
or
link
.
startswith
(
u
"ftp"
)
or
link
.
startswith
(
u
"www"
)
or
link
.
startswith
(
u
"mailto"
)
or
link
.
endswith
(
u
".md"
)
def
on_page_markdown
(
self
,
markdown
,
page
=
None
,
config
=
None
,
**
kwargs
):
links
=
re
.
findall
(
self
.
MD_LINK
,
markdown
)
issue_token
=
config
.
data
.
get
(
"issue_token"
)
issue_url
=
config
.
data
.
get
(
"issue_url"
)
for
link
in
links
:
#if self._should_ignore_link(link.lstrip()):
# continue
if
not
link
.
startswith
(
issue_token
):
continue
# Build the actual link
link_base
=
link
[
len
(
issue_token
):]
link_new
=
"[GITLAB %s](%s%s)"
%
(
link
,
issue_base
,
link
)
# Replace the link in the markdown
markdown
=
markdown
.
replace
(
"({})"
.
format
(
link
),
"({})"
.
format
(
link_new
))
return
markdown
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment