From 0c86bcb8c271692a48efea5ce62819d5e8cc8c42 Mon Sep 17 00:00:00 2001 From: Thomas Rooijakkers Date: Tue, 10 Oct 2023 17:29:30 +0200 Subject: [PATCH 1/2] Add support for directories (index.md) --- mkdocs_autolinks_plugin/plugin.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mkdocs_autolinks_plugin/plugin.py b/mkdocs_autolinks_plugin/plugin.py index 0eb306c..9db0c63 100644 --- a/mkdocs_autolinks_plugin/plugin.py +++ b/mkdocs_autolinks_plugin/plugin.py @@ -20,7 +20,7 @@ # 6. Image title (in quotation marks) AUTOLINK_RE = ( - r"(?:\!\[\]|\[([^\]]+)\])\((([^)/]+\.(md|png|jpg|jpeg|bmp|gif|svg|webp))(#[^)]*)*)(\s(\".*\"))*\)" + r"(?:\!\[\]|\[([^\]]+)\])\((([^)/]+(\.md|\.png|\.jpg|\.jpeg|\.bmp|\.gif|\.svg|\.webp|/))(#[^)]*)*)(\s(\".*\"))*\)" ) class AutoLinkReplacer: @@ -93,4 +93,6 @@ def init_filename_to_abs_path(self, files): self.filename_to_abs_path = defaultdict(list) for file_ in files: filename = os.path.basename(file_.abs_src_path) + if filename == "index.md": + filename = os.path.basename(os.path.dirname(file_.abs_src_path)) + "/" self.filename_to_abs_path[filename].append(file_.abs_src_path) From a9b804bf625d3b5d38f1bd9ffe9c40899864006a Mon Sep 17 00:00:00 2001 From: Thomas Rooijakkers Date: Tue, 10 Oct 2023 17:30:15 +0200 Subject: [PATCH 2/2] Add support for REFERENCE LINKS --- mkdocs_autolinks_plugin/plugin.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mkdocs_autolinks_plugin/plugin.py b/mkdocs_autolinks_plugin/plugin.py index 9db0c63..a80d4d4 100644 --- a/mkdocs_autolinks_plugin/plugin.py +++ b/mkdocs_autolinks_plugin/plugin.py @@ -23,6 +23,10 @@ r"(?:\!\[\]|\[([^\]]+)\])\((([^)/]+(\.md|\.png|\.jpg|\.jpeg|\.bmp|\.gif|\.svg|\.webp|/))(#[^)]*)*)(\s(\".*\"))*\)" ) +AUTOLINK_RE_REFLINKS = ( + r"(?:\[([^\]]+)\])\: (([^)/]+(\.md|\.png|\.jpg|\.jpeg|\.bmp|\.gif|\.svg|\.webp|/))(#[^)]*)*)(\s(\".*\"))*\n" +) + class AutoLinkReplacer: def __init__(self, base_docs_dir, abs_page_path, filename_to_abs_path): self.base_docs_dir = base_docs_dir @@ -86,6 +90,11 @@ def on_page_markdown(self, markdown, page, config, files, **kwargs): AutoLinkReplacer(base_docs_dir, abs_page_path, self.filename_to_abs_path), markdown, ) + markdown = re.sub( + AUTOLINK_RE_REFLINKS, + AutoLinkReplacer(base_docs_dir, abs_page_path, self.filename_to_abs_path), + markdown, + ) return markdown