Skip to content

Commit

Permalink
feat: add markers (#2)
Browse files Browse the repository at this point in the history
* 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
timmeinerzhagen authored Feb 2, 2023
1 parent d8cf605 commit 88ded9c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 10 deletions.
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# mkdocs-external-link-marker
# mkdocs-link-marker

MkDocs plugin for marking external links

![comparison](docs/comparison.png)
## Setup

1. Install the plugin:
```bash
pip install mkdocs-external-link-marker
pip install mkdocs-link-marker
```
2. Add the plugin to your `mkdocs.yml`
```bash
plugins:
- search
- external-link-marker
- link-marker
```

## Usage
Expand All @@ -21,5 +22,18 @@ Run the build!

## Options

`external_link_icon`
Change the default icon for marking external links.
`enable_external_link`
Change the default icon for marking external links.
Default: True

`icon_external_link`
Change the default icon for marking external links.
Default: ⧉

`enable_mail`
Change the default icon for marking external links.
Default: True

`icon_mail`
Change the default icon for marking external links.
Default: ✉
Binary file added docs/comparison.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
30 changes: 30 additions & 0 deletions mkdocs_link_marker_plugin/plugin.py
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
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'
]
}
)

0 comments on commit 88ded9c

Please sign in to comment.