def test_text_and_meta(): text, meta = text_and_meta( io.StringIO(''' [[!meta title="Frequently asked questions"]] [[!meta herp="derp"]] hello world ''')) assert text.strip() == 'hello world' assert meta == { 'title': 'Frequently asked questions', 'herp': 'derp', }
def test_text_and_meta(): text, meta = text_and_meta( io.StringIO(''' [[!meta title="Frequently asked questions"]] [[!meta herp="derp"]] hello world '''), ) assert text.strip() == 'hello world' assert meta == { 'title': 'Frequently asked questions', 'herp': 'derp', }
def get_markdown_docs() -> Generator[Document, None, None]: for path in DOCS_DIR.glob('**/*.md'): name, _ = os.path.splitext(str(path.relative_to(DOCS_DIR))) # sanity check that the file is under the directory we expect assert DOCS_DIR in path.parents with path.open() as f: text, meta = text_and_meta(f) if 'title' not in meta: raise ValueError(f'Document {name} lacks required title meta variable.') yield Document( name='/' + name, title=meta['title'], render=partial(render_markdown_doc, path, meta, text), )
def get_markdown_docs(): for path in DOCS_DIR.glob('**/*.md'): name, _ = os.path.splitext(str(path.relative_to(DOCS_DIR))) # sanity check that the file is under the directory we expect assert DOCS_DIR in path.parents with path.open() as f: text, meta = text_and_meta(f) if 'title' not in meta: raise ValueError('Document {} lacks required title meta variable.'.format(name)) yield Document( name='/' + name, title=meta['title'], render=partial(render_markdown_doc, path, meta, text), )
def render_markdown_doc(path, meta, text, doc, request): # Reload markdown docs if in development if settings.DEBUG: with path.open() as f: text, meta = text_and_meta(f) html, toc = markdown_and_toc(text) return render( request, meta.get('template', 'docs/doc.html'), { 'title': meta['title'], 'doc': doc, 'html': html, 'toc': toc, }, )
def render_markdown_doc(path: Path, meta: Dict[str, Any], text: str, doc: Document, request: Any) -> HttpResponse: # Reload markdown docs if in development if settings.DEBUG: with path.open() as f: text, meta = text_and_meta(f) html, toc = markdown_and_toc(text) return render( request, meta.get('template', 'docs/doc.html'), { 'title': meta['title'], 'doc': doc, 'html': html, 'toc': toc, }, )