コード例 #1
0
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',
    }
コード例 #2
0
ファイル: markdown_test.py プロジェクト: tmochida/ocfweb
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',
    }
コード例 #3
0
ファイル: markdown_based.py プロジェクト: sberkun/ocfweb
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),
        )
コード例 #4
0
ファイル: markdown_based.py プロジェクト: jvperrin/ocfweb
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),
        )
コード例 #5
0
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,
        },
    )
コード例 #6
0
ファイル: markdown_based.py プロジェクト: jvperrin/ocfweb
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,
        },
    )
コード例 #7
0
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,
        },
    )