-
-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Restore hide_lines plugin with proper type annotations
- Loading branch information
1 parent
5284163
commit 22c1ddb
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
] | ||
) |