From 8685763ccfb29788a5471c56b1b1968cc781194a Mon Sep 17 00:00:00 2001 From: tvdboom Date: Tue, 9 Aug 2022 19:23:44 +0200 Subject: [PATCH 1/8] added scan html tags --- src/mkdocs_autorefs/plugin.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/mkdocs_autorefs/plugin.py b/src/mkdocs_autorefs/plugin.py index 5eca316..40a32e8 100644 --- a/src/mkdocs_autorefs/plugin.py +++ b/src/mkdocs_autorefs/plugin.py @@ -15,7 +15,8 @@ import contextlib import functools import logging -from typing import TYPE_CHECKING, Any, Callable, Sequence +import re +from typing import Callable, Dict, Optional, Sequence from urllib.parse import urlsplit from mkdocs.plugins import BasePlugin @@ -50,7 +51,8 @@ class AutorefsPlugin(BasePlugin): """ scan_toc: bool = True - current_page: str | None = None + scan_html_tags: bool = True + current_page: Optional[str] = None def __init__(self) -> None: """Initialize the object.""" @@ -170,6 +172,12 @@ def on_page_content(self, html: str, page: Page, **kwargs: Any) -> str: # noqa: log.debug(f"Mapping identifiers to URLs for page {page.file.src_path}") for item in page.toc.items: self.map_urls(page.url, item) + + if self.scan_html_tags: + # Matches any html tag with the name property + for match in re.findall(r"""<(\w+?) .*?name=["']([\w-]*)["'].*?>.*?""", html): + self.register_anchor(page.url, match[1]) + return html def map_urls(self, base_url: str, anchor: AnchorLink) -> None: From b36ee343815bb9573734964f1a3ef6eb50164829 Mon Sep 17 00:00:00 2001 From: tvdboom Date: Thu, 11 Aug 2022 09:12:39 +0200 Subject: [PATCH 2/8] id --- src/mkdocs_autorefs/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mkdocs_autorefs/plugin.py b/src/mkdocs_autorefs/plugin.py index 40a32e8..d20d295 100644 --- a/src/mkdocs_autorefs/plugin.py +++ b/src/mkdocs_autorefs/plugin.py @@ -175,7 +175,7 @@ def on_page_content(self, html: str, page: Page, **kwargs: Any) -> str: # noqa: if self.scan_html_tags: # Matches any html tag with the name property - for match in re.findall(r"""<(\w+?) .*?name=["']([\w-]*)["'].*?>.*?""", html): + for match in re.findall(r"""<(\w+?) .*?id=["']([\w-]*)["'].*?>.*?""", html): self.register_anchor(page.url, match[1]) return html From a7fae3998cdf35488c391550e2f3eaa86c60ff87 Mon Sep 17 00:00:00 2001 From: tvdboom Date: Thu, 18 Aug 2022 10:43:44 +0200 Subject: [PATCH 3/8] fix --- src/mkdocs_autorefs/plugin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mkdocs_autorefs/plugin.py b/src/mkdocs_autorefs/plugin.py index d20d295..37d5102 100644 --- a/src/mkdocs_autorefs/plugin.py +++ b/src/mkdocs_autorefs/plugin.py @@ -174,9 +174,9 @@ def on_page_content(self, html: str, page: Page, **kwargs: Any) -> str: # noqa: self.map_urls(page.url, item) if self.scan_html_tags: - # Matches any html tag with the name property - for match in re.findall(r"""<(\w+?) .*?id=["']([\w-]*)["'].*?>.*?""", html): - self.register_anchor(page.url, match[1]) + # Matches any html tag with the id property + for match in re.findall(r"""<\w+? .*?id=["']([_\w-]*)["'].*?>""", html): + self.register_anchor(page.url, match) return html From 03562e86238a3e7e709cdf740ea81d5d784b17a0 Mon Sep 17 00:00:00 2001 From: tvdboom Date: Mon, 22 Aug 2022 10:08:15 +0200 Subject: [PATCH 4/8] added config --- src/mkdocs_autorefs/plugin.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/mkdocs_autorefs/plugin.py b/src/mkdocs_autorefs/plugin.py index 37d5102..cf5c5af 100644 --- a/src/mkdocs_autorefs/plugin.py +++ b/src/mkdocs_autorefs/plugin.py @@ -50,8 +50,11 @@ class AutorefsPlugin(BasePlugin): for more information about its plugin system. """ + config = ( + ("scan_html_tags", mkdocs.config.config_options.Type(bool, default=False)) + ) + scan_toc: bool = True - scan_html_tags: bool = True current_page: Optional[str] = None def __init__(self) -> None: @@ -173,7 +176,7 @@ def on_page_content(self, html: str, page: Page, **kwargs: Any) -> str: # noqa: for item in page.toc.items: self.map_urls(page.url, item) - if self.scan_html_tags: + if self.config["scan_html_tags"]: # Matches any html tag with the id property for match in re.findall(r"""<\w+? .*?id=["']([_\w-]*)["'].*?>""", html): self.register_anchor(page.url, match) From a4db2d098b4ea87817d8e778360704ec143efe46 Mon Sep 17 00:00:00 2001 From: tvdboom Date: Fri, 26 Aug 2022 21:19:05 +0200 Subject: [PATCH 5/8] fix --- src/mkdocs_autorefs/plugin.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mkdocs_autorefs/plugin.py b/src/mkdocs_autorefs/plugin.py index cf5c5af..bf5a26c 100644 --- a/src/mkdocs_autorefs/plugin.py +++ b/src/mkdocs_autorefs/plugin.py @@ -19,6 +19,8 @@ from typing import Callable, Dict, Optional, Sequence from urllib.parse import urlsplit +from mkdocs.config import Config +from mkdocs.config.config_options import Type from mkdocs.plugins import BasePlugin from mkdocs_autorefs.references import AutorefsExtension, fix_refs, relative_url @@ -51,7 +53,7 @@ class AutorefsPlugin(BasePlugin): """ config = ( - ("scan_html_tags", mkdocs.config.config_options.Type(bool, default=False)) + ("scan_html_tags", Type(bool, default=False)) ) scan_toc: bool = True From b093e5d0c9904c92dfa80a2a58edf6ef407e1caa Mon Sep 17 00:00:00 2001 From: tvdboom Date: Wed, 23 Nov 2022 08:58:14 +0100 Subject: [PATCH 6/8] only --- src/mkdocs_autorefs/plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mkdocs_autorefs/plugin.py b/src/mkdocs_autorefs/plugin.py index bf5a26c..17d91d8 100644 --- a/src/mkdocs_autorefs/plugin.py +++ b/src/mkdocs_autorefs/plugin.py @@ -179,8 +179,8 @@ def on_page_content(self, html: str, page: Page, **kwargs: Any) -> str: # noqa: self.map_urls(page.url, item) if self.config["scan_html_tags"]: - # Matches any html tag with the id property - for match in re.findall(r"""<\w+? .*?id=["']([_\w-]*)["'].*?>""", html): + # Matches any html anchor with the id property () + for match in re.findall(r"""""", html): self.register_anchor(page.url, match) return html From a1ba3e27803581ea639b540cefed550c0f0dfbb2 Mon Sep 17 00:00:00 2001 From: Mavs Date: Wed, 11 Oct 2023 08:59:06 +0200 Subject: [PATCH 7/8] not only str: # noqa: self.map_urls(page.url, item) if self.config["scan_html_tags"]: - # Matches any html anchor with the id property () - for match in re.findall(r"""""", html): + # Matches any html anchors with the id property (e.g. ) + for match in re.findall(r"""<.*?id=["']([_\w-]*)["'].*?>""", html): self.register_anchor(page.url, match) return html From 1465f3b0e8d57a14dc055f3940ec29df28312e12 Mon Sep 17 00:00:00 2001 From: Mavs Date: Wed, 11 Oct 2023 09:09:38 +0200 Subject: [PATCH 8/8] only a... again --- src/mkdocs_autorefs/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mkdocs_autorefs/plugin.py b/src/mkdocs_autorefs/plugin.py index 1f4f8a0..ba333e8 100644 --- a/src/mkdocs_autorefs/plugin.py +++ b/src/mkdocs_autorefs/plugin.py @@ -180,7 +180,7 @@ def on_page_content(self, html: str, page: Page, **kwargs: Any) -> str: # noqa: if self.config["scan_html_tags"]: # Matches any html anchors with the id property (e.g. ) - for match in re.findall(r"""<.*?id=["']([_\w-]*)["'].*?>""", html): + for match in re.findall(r"""""", html): self.register_anchor(page.url, match) return html