Skip to content

Commit

Permalink
fix: Restore hide_lines plugin with proper type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
devin-ai-integration[bot] committed Nov 18, 2024
1 parent 5284163 commit 22c1ddb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/_hooks/hide_lines/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Hide Lines Plugin for MkDocs."""
from .plugin import HideLinesPlugin

__all__ = ['HideLinesPlugin']
36 changes: 36 additions & 0 deletions docs/_hooks/hide_lines/plugin.py
Original file line number Diff line number Diff line change
@@ -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', '<!-- hide -->']):
result.append(line)

return '\n'.join(result)
15 changes: 15 additions & 0 deletions docs/_hooks/setup.py
Original file line number Diff line number Diff line change
@@ -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'
]
)

0 comments on commit 22c1ddb

Please sign in to comment.