-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: initial commit * feat: hook * fix: path * fix: param * fix: replace * feat: move to `on_page_content` * feat: update replace regex * feat: add mail * fix: params * chore: move dir * docs: pic
- Loading branch information
1 parent
d8cf605
commit 88ded9c
Showing
5 changed files
with
54 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import re | ||
import yaml | ||
from pathlib import Path | ||
import logging | ||
|
||
from mkdocs.config import config_options | ||
from mkdocs.plugins import BasePlugin | ||
|
||
class LinkMarkerPlugin(BasePlugin): | ||
config_scheme = ( | ||
('enable_external_link', config_options.Type(bool, default=True)), | ||
('icon_external_link', config_options.Type(str, default='⧉')), | ||
|
||
('enable_mail', config_options.Type(bool, default=True)), | ||
('icon_mail', config_options.Type(str, default='✉')), | ||
) | ||
|
||
def __init__(self): | ||
self.enabled = True | ||
|
||
def on_page_content(self, html, page, config, files): | ||
if self.config['enable_external_link']: | ||
p_external_link = re.compile('<a href="(http.*)">(.*)</a>') | ||
html = p_external_link.sub('<a href="\\1">\\2 ' + self.config['icon_external_link'] + '</a>', html) | ||
|
||
if self.config['enable_mail']: | ||
p_mail = re.compile('<a href="(mailto:.*)">(.*)</a>') | ||
html = p_mail.sub('<a href="\\1">\\2 ' + self.config['icon_mail'] + '</a>', html) | ||
|
||
return html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,13 @@ | |
long_description = fh.read() | ||
|
||
setup( | ||
name='mkdocs-external-link-marker', | ||
version='0.1.2', | ||
description='MkDocs plugin for marking external links.', | ||
name='mkdocs-link-marker', | ||
version='0.1.0', | ||
description='MkDocs plugin for marking links.', | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
keywords='mkdocs link external', | ||
url='https://github.com/timmeinerzhagen/mkdocs-external-link-marker', | ||
url='https://github.com/timmeinerzhagen/mkdocs-link-marker', | ||
author='Tim Jonas Meinerzhagen', | ||
author_email='[email protected]', | ||
license='MIT', | ||
|
@@ -36,7 +36,7 @@ | |
packages=find_packages(), | ||
entry_points={ | ||
'mkdocs.plugins': [ | ||
'external-link-marker = mkdocs_external-link-marker_plugin.plugin:ExternalLinkMarkerPlugin' | ||
'link-marker = mkdocs_link_marker_plugin.plugin:LinkMarkerPlugin' | ||
] | ||
} | ||
) |