From b20357aee4768a2b5c9cdc777249bc36b8915834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar?= Date: Fri, 4 Dec 2020 14:27:12 +0100 Subject: [PATCH] Separate 'mkdocs_include_markdown_plugin' from project --- docs/index.md | 2 +- .../__init__.py | 0 .../mkdocs_include_markdown_plugin/plugin.py | 84 ------------------- docs/mkdocs_include_markdown_plugin/setup.py | 15 ---- mkdocs.yml | 2 +- requirements-dev.txt | 2 +- 6 files changed, 3 insertions(+), 102 deletions(-) delete mode 100644 docs/mkdocs_include_markdown_plugin/mkdocs_include_markdown_plugin/__init__.py delete mode 100644 docs/mkdocs_include_markdown_plugin/mkdocs_include_markdown_plugin/plugin.py delete mode 100644 docs/mkdocs_include_markdown_plugin/setup.py diff --git a/docs/index.md b/docs/index.md index 627209b01..6cc7ccfd5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -3,7 +3,7 @@ title: Home --- {% - includemarkdown "../README.md" + include-markdown "../README.md" start="" end="" %} diff --git a/docs/mkdocs_include_markdown_plugin/mkdocs_include_markdown_plugin/__init__.py b/docs/mkdocs_include_markdown_plugin/mkdocs_include_markdown_plugin/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/docs/mkdocs_include_markdown_plugin/mkdocs_include_markdown_plugin/plugin.py b/docs/mkdocs_include_markdown_plugin/mkdocs_include_markdown_plugin/plugin.py deleted file mode 100644 index f12ea4698..000000000 --- a/docs/mkdocs_include_markdown_plugin/mkdocs_include_markdown_plugin/plugin.py +++ /dev/null @@ -1,84 +0,0 @@ -import cgi -import re -from pathlib import Path - -import mkdocs - -INCLUDE_TAG_REGEX = re.compile( - r''' - {% # opening tag - \s* - include # directive name - \s+ - "(?P[^"]+)" # "filename" - \s* - %} # closing tag - ''', - flags=re.VERBOSE, -) - -INCLUDEMARKDOWN_TAG_REGEX = re.compile( - r''' - {% # opening tag - \s* - includemarkdown # directive name - \s+ - "(?P[^"]+)" # "filename" - (?:\s+start="(?P[^"]+)")? # optional start expression - (?:\s+end="(?P[^"]+)")? # optional end expression - \s* - %} # closing tag - ''', - flags=re.VERBOSE, -) - - -class ImportMarkdownPlugin(mkdocs.plugins.BasePlugin): - def on_page_markdown(self, markdown, page, **kwargs): - page_src_path = page.file.abs_src_path - - def found_include_tag(match): - filename = match.group('filename') - - file_path_abs = Path(page_src_path).parent / filename - - if not file_path_abs.exists(): - raise ValueError('file not found', filename) - - text_to_include = file_path_abs.read_text(encoding='utf8') - - # Allow good practice of having a final newline in the file - if text_to_include.endswith('\n'): - text_to_include = text_to_include[:-1] - - return text_to_include - - def found_includemarkdown_tag(match): - filename = match.group('filename') - start = match.group('start') - end = match.group('end') - - file_path_abs = Path(page_src_path).parent / filename - - if not file_path_abs.exists(): - raise ValueError('file not found', filename) - - text_to_include = file_path_abs.read_text(encoding='utf8') - - if start: - _, _, text_to_include = text_to_include.partition(start) - - if end: - text_to_include, _, _ = text_to_include.partition(end) - - return ( - '\n' % ( - filename, cgi.escape(start or ''), cgi.escape(end or '') - ) - + text_to_include - + '\n' - ) - - markdown = re.sub(INCLUDE_TAG_REGEX, found_include_tag, markdown) - markdown = re.sub(INCLUDEMARKDOWN_TAG_REGEX, found_includemarkdown_tag, markdown) - return markdown diff --git a/docs/mkdocs_include_markdown_plugin/setup.py b/docs/mkdocs_include_markdown_plugin/setup.py deleted file mode 100644 index 0f8b6a186..000000000 --- a/docs/mkdocs_include_markdown_plugin/setup.py +++ /dev/null @@ -1,15 +0,0 @@ -from setuptools import setup - -setup( - name='mkdocs_include_markdown_plugin', - version='1.0', - author='Joe Rickerby', - license='Apache 2', - packages=['mkdocs_include_markdown_plugin'], - entry_points={ - 'mkdocs.plugins': [ - 'importmarkdown = mkdocs_include_markdown_plugin.plugin:ImportMarkdownPlugin', - ] - }, - zip_safe=False -) diff --git a/mkdocs.yml b/mkdocs.yml index 4a10a6d9e..928c1116a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -32,4 +32,4 @@ markdown_extensions: repo_url_shortener: True plugins: - - importmarkdown + - include-markdown diff --git a/requirements-dev.txt b/requirements-dev.txt index e61296843..52bc8edb5 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,7 +1,7 @@ -e . --e ./docs/mkdocs_include_markdown_plugin pytest mkdocs==1.0.4 +mkdocs-include-markdown-plugin==1.0.0 pymdown-extensions pip-tools requests