Skip to content

Commit 5380377

Browse files
committed
Add mkdocs-htmlproofer-plugin
0 parents  commit 5380377

File tree

6 files changed

+167
-0
lines changed

6 files changed

+167
-0
lines changed

CONTRIBUTING.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Contribution Guidelines
2+
3+
Thank you for considering to contribute to this project. These guidelines will help you get going with development and outline the most important rules to follow when submitting pull requests for this project.
4+
5+
<br/>
6+
7+
## Development
8+
9+
#### Setup
10+
11+
##### Prerequisites
12+
13+
- [Python 3]
14+
- [virtualenv]
15+
16+
##### Steps
17+
18+
1. Clone the (forked) repository
19+
1. Create a virtualenv with `virtualenv env`
20+
1. Activate virtualenv `source env/bin/activate` or `env/Scripts/activate` on Windows
21+
1. Run `pip install -r requirements.txt` in the project directory
22+
23+
#### Running Tests
24+
25+
```bash
26+
pytest
27+
```
28+
29+
<br/>
30+
31+
32+
## Submitting Changes
33+
34+
To get changes merged, create a pull request. Here are a few things to pay attention to when doing so:
35+
36+
#### Commit Messages
37+
38+
The summary of a commit should be concise and worded in an imperative mood.
39+
...a *what* mood? This should clear things up: *[How to Write a Git Commit Message][git-commit-message]*
40+
41+
#### Code Style
42+
43+
Make sure your code follows [PEP-8](https://www.python.org/dev/peps/pep-0008/) and keeps things consistent with the rest of the code.
44+
45+
#### Tests
46+
47+
If it makes sense, writing tests for your PRs is always appreciated and will help get them merged.
48+
49+
[Python 3]: https://www.python.org/
50+
[virtualenv]: https://virtualenv.pypa.io/
51+
[git-commit-message]: https://chris.beams.io/posts/git-commit/

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# MIT License
2+
3+
Copyright (c) 2018 Lukas Geiter
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# mkdocs-htmlproofer-plugin
2+
3+
*A MkDocs plugin that checks URL*
4+
5+
6+
7+
## Installation
8+
9+
> **Note:** This package requires MkDocs version 0.17 or higher.
10+
11+
Install the package with pip:
12+
13+
```bash
14+
pip install mkdocs-htmlproofer-plugin
15+
```
16+
17+
Enable the plugin in your `mkdocs.yml`:
18+
19+
```yaml
20+
plugins:
21+
- search
22+
- htmlproofer
23+
```
24+
25+
> **Note:** If you have no `plugins` entry in your config file yet, you'll likely also want to add the `search` plugin. MkDocs enables it by default if there is no `plugins` entry set, but now you have to enable it explicitly.
26+
27+
More information about plugins in the [MkDocs documentation][mkdocs-plugins]
28+

htmlproofer/__init__.py

Whitespace-only changes.

htmlproofer/plugin.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from mkdocs.plugins import BasePlugin
2+
3+
from bs4 import BeautifulSoup
4+
import urllib.request
5+
6+
7+
class HtmlProoferPlugin(BasePlugin):
8+
9+
def on_post_page(self, output_content, config, **kwargs):
10+
soup = BeautifulSoup(output_content, 'html.parser')
11+
local = ['localhost', '127.0.0.1']
12+
for a in soup.find_all('a', href=True):
13+
url = a['href']
14+
for local in ('localhost', '127.0.0.1', 'app_server'):
15+
if url.startswith('http://' + local):
16+
return
17+
if url.startswith('http'):
18+
print('Checking url ' + url)
19+
try:
20+
status = urllib.request.urlopen(url, timeout=10).getcode()
21+
if status != 200:
22+
print('Bad url ' + url)
23+
except:
24+
print('Failed to open url ' + url)
25+
26+
27+

setup.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import os
2+
from setuptools import setup, find_packages
3+
4+
5+
def read(fname):
6+
return open(os.path.join(os.path.dirname(__file__), fname)).read()
7+
8+
9+
setup(
10+
name='mkdocs-htmlproofer-plugin',
11+
version='0.0.1',
12+
description='A MkDocs plugin that injects the mkdocs.yml extra variables into the markdown template',
13+
long_description=read('README.md'),
14+
keywords='mkdocs python markdown extra values',
15+
url='https://github.com/manuzhang/mkdocs-htmlproofer-plugin',
16+
author='Manu Zhang',
17+
author_email='[email protected]',
18+
license='MIT',
19+
python_requires='>=3.5',
20+
install_requires=[
21+
'mkdocs>=0.17'
22+
],
23+
classifiers=[
24+
'Development Status :: 5 - Production/Stable',
25+
'Intended Audience :: Developers',
26+
'Intended Audience :: Information Technology',
27+
'License :: OSI Approved :: MIT License',
28+
'Programming Language :: Python',
29+
'Programming Language :: Python :: 3 :: Only',
30+
'Programming Language :: Python :: 3.5',
31+
'Programming Language :: Python :: 3.6',
32+
'Programming Language :: Python :: 3.7'
33+
],
34+
packages=find_packages(exclude=['*.tests']),
35+
entry_points={
36+
'mkdocs.plugins': [
37+
'htmlproofer = htmlproofer.plugin:HtmlProoferPlugin'
38+
]
39+
}
40+
)

0 commit comments

Comments
 (0)