wikitext.py 1.1 KB

123456789101112131415161718192021
  1. # SPDX-License-Identifier: Apache-2.0
  2. """Read a wiki page without its generated navigation blocks (issue #417).
  3. scripts/gen_wiki_nav.py writes a navigation block at the top and the bottom of every page: links to the
  4. page's track, its previous and next page and related pages. That is navigation, not lesson content, so a test that
  5. counts the links a page makes, names pages it must NOT link, or looks at the first lines of a page reads the page
  6. through this helper and sees what the author wrote. Since issue #441 the longest pages also carry a generated
  7. contents block (links to the page's own headings); it is stripped too. The stripping itself is
  8. gen_wiki_nav.strip_generated, tested in tests/test_wiki_page_nav.py and tests/test_wiki_page_contents.py.
  9. """
  10. import sys
  11. from pathlib import Path
  12. sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts"))
  13. import gen_wiki_nav
  14. def page_text(path: Path) -> str:
  15. """The text of a wiki page file with the generated navigation blocks and the contents block removed."""
  16. return gen_wiki_nav.strip_generated(Path(path).read_text(encoding="utf-8"))