From 22c1ddb9686d9d9ffa26f61d6218512b88c36edd Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 18 Nov 2024 02:57:38 +0000 Subject: [PATCH] fix: Restore hide_lines plugin with proper type annotations --- docs/_hooks/hide_lines/__init__.py | 4 ++++ docs/_hooks/hide_lines/plugin.py | 36 ++++++++++++++++++++++++++++++ docs/_hooks/setup.py | 15 +++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 docs/_hooks/hide_lines/__init__.py create mode 100644 docs/_hooks/hide_lines/plugin.py create mode 100644 docs/_hooks/setup.py diff --git a/docs/_hooks/hide_lines/__init__.py b/docs/_hooks/hide_lines/__init__.py new file mode 100644 index 000000000..27685601d --- /dev/null +++ b/docs/_hooks/hide_lines/__init__.py @@ -0,0 +1,4 @@ +"""Hide Lines Plugin for MkDocs.""" +from .plugin import HideLinesPlugin + +__all__ = ['HideLinesPlugin'] diff --git a/docs/_hooks/hide_lines/plugin.py b/docs/_hooks/hide_lines/plugin.py new file mode 100644 index 000000000..60c6df43c --- /dev/null +++ b/docs/_hooks/hide_lines/plugin.py @@ -0,0 +1,36 @@ +from typing import Any, Dict, List +from mkdocs.config import Config +from mkdocs.structure.files import Files +from mkdocs.structure.pages import Page +from mkdocs.plugins import BasePlugin + +class HideLinesPlugin(BasePlugin): + def on_page_markdown(self, markdown: str, page: Page, config: Config, files: Files) -> str: + """Process the markdown content to hide specified lines. + + Args: + markdown: The markdown content of the page + page: The page object + config: The global configuration object + files: The files collection + + Returns: + str: The processed markdown content + """ + lines = markdown.split('\n') + result: List[str] = [] + skip_next = False + + for line in lines: + if skip_next: + skip_next = False + continue + + if '# hide_next' in line.lower(): + skip_next = True + continue + + if not any(marker in line.lower() for marker in ['# hide', '']): + result.append(line) + + return '\n'.join(result) diff --git a/docs/_hooks/setup.py b/docs/_hooks/setup.py new file mode 100644 index 000000000..61adb0ec4 --- /dev/null +++ b/docs/_hooks/setup.py @@ -0,0 +1,15 @@ +from setuptools import setup, find_packages + +setup( + name='hide_lines', + version='0.1', + packages=find_packages(), + entry_points={ + 'mkdocs.plugins': [ + 'hide_lines = hide_lines.plugin:HideLinesPlugin', + ] + }, + install_requires=[ + 'mkdocs>=1.0.4' + ] +)