Skip to content

Commit

Permalink
Fix types and compatibility with MkDocs 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed Apr 27, 2024
1 parent 9c05649 commit 6cc020a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions mkdocs_literate_nav/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,15 @@ def get_nav_for_dir(path: str) -> tuple[str, str] | None:
# https://github.com/mkdocs/mkdocs/blob/ff0b726056/mkdocs/structure/nav.py#L113
Page(None, file, {}) # type: ignore[arg-type]

# https://github.com/mkdocs/mkdocs/blob/fa5aa4a26e/mkdocs/structure/pages.py#L120
with open(file.abs_src_path, encoding="utf-8-sig") as f:
return nav_file_name, f.read()
try: # MkDocs 1.6+
content = file.content_string
except AttributeError:
# https://github.com/mkdocs/mkdocs/blob/fa5aa4a26e/mkdocs/structure/pages.py#L120
assert file.abs_src_path is not None
with open(file.abs_src_path, encoding="utf-8-sig") as f:
content = f.read()

return nav_file_name, content

globber = MkDocsGlobber(files)
nav_parser = parser.NavParser(
Expand Down

0 comments on commit 6cc020a

Please sign in to comment.