Skip to content

Commit

Permalink
#26: Adds trojan horse like storage on page for markmap info
Browse files Browse the repository at this point in the history
  • Loading branch information
neatc0der committed Nov 4, 2021
1 parent 7debb32 commit e88ba65
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions mkdocs_markmap/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class MarkmapPlugin(BasePlugin):

def __init__(self):
self._markmap: Dict[str, str] = None
self._found_markmap: bool = False

@property
def markmap(self) -> Dict[str, str]:
Expand Down Expand Up @@ -93,7 +92,7 @@ def on_config(self, config: Config) -> Config:
return config

def on_post_page(self, html: str, page: Page, config: Config, **kwargs) -> str:
if not self._found_markmap:
if not getattr(page, '_found_markmap', False):
log.info(f"no markmap found: {page.file.name}")
return html

Expand All @@ -105,10 +104,10 @@ def on_post_page(self, html: str, page: Page, config: Config, **kwargs) -> str:

return str(soup)

def on_page_content(self, html: str, **kwargs) -> str:
def on_page_content(self, html: str, page: Page, **kwargs) -> str:
soup: BeautifulSoup = BeautifulSoup(html, 'html.parser')
markmaps: ResultSet = soup.find_all(class_='language-markmap')
self._found_markmap: bool = any(markmaps)
setattr(page, '_found_markmap', any(markmaps))

for index, markmap in enumerate(markmaps):
markmap: Tag
Expand Down

0 comments on commit e88ba65

Please sign in to comment.