diff --git a/mkdocs_literate_nav/plugin.py b/mkdocs_literate_nav/plugin.py index 0423b42..3581d5e 100644 --- a/mkdocs_literate_nav/plugin.py +++ b/mkdocs_literate_nav/plugin.py @@ -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(