diff --git a/book/_config.yml b/book/_config.yml index 02e26d1..99ea80d 100644 --- a/book/_config.yml +++ b/book/_config.yml @@ -11,6 +11,8 @@ html: baseurl : "https://teachbooks.io/manual/" sphinx: + local_extensions: + include_remove_yaml: _ext/ extra_extensions: - sphinx_inline_tabs - sphinx.ext.imgconverter diff --git a/book/_ext/include_remove_yaml/__init__.py b/book/_ext/include_remove_yaml/__init__.py new file mode 100644 index 0000000..a6181f5 --- /dev/null +++ b/book/_ext/include_remove_yaml/__init__.py @@ -0,0 +1,33 @@ +from __future__ import annotations +from sphinx.util import logging +logger = logging.getLogger(__name__) + +def _strip_yaml(lines: list[str]) -> list[str]: + + if not lines: + return lines + for ix,lines_set in enumerate(lines): + new_lines = lines_set.splitlines() + if new_lines[0].strip() != "---": + continue + # yaml front matter detected + # find closing delimiter + index_end = 1 + for i in range(1, len(new_lines)): + tok = new_lines[i].strip() + if tok == "---": + index_end = i + break + new_lines = new_lines[index_end+1 :] + lines[ix] = "\n".join(new_lines) + return lines # no closing delimiter -> leave unchanged + +def on_include_read(app, docname, path, content): + # content is a list[str]; modify in-place + new = _strip_yaml(content) + if new is not content: + content[:] = new + +def setup(app): + app.connect("include-read", on_include_read) + return {} diff --git a/book/intro.md b/book/intro.md index 165c9f7..c2739e3 100644 --- a/book/intro.md +++ b/book/intro.md @@ -1,3 +1,8 @@ +--- +file_format: mystnb +kernelspec: + name: python3 +--- # TeachBooks Manual This manual is primarily designed for and by teachers for use in education, but should be a useful resource for anyone interested in creating and collaborating on a TeachBook: a Jupyter book v1 v1 using the Sphinx logo Sphinx backend with additional editing tools and book features. Our aim is to provide a simple way to start book-making for new users (it only takes 10 clicks!), ease the editing process for anyone, and provide additional features developed for education-purposes. We hope you find this resource useful and refer back to it often.