Exemplo n.º 1
0
def test_section():
    s = """
= Title =

== H 1 ==

@alfa

== H 2 ==

@bravo
    """.strip()

    rule = p.Star(wg.context["blocks"])
    out, i = rule.accept(s, 0, wg.context)
    # pprint.pprint(out)
    assert i == len(s)
    util.dump_tree(out)
    assert out == [
        {"indent": 0, "level": 0, "text": ["Title"], "type": "title"},
        {"indent": 0, "container": True, "level": 2, "text": ["H 1"], "type": "h", "id": None},
        {"indent": 0, "container": True, "type": "alfa_section", "level": 1, "role": "section", "id": "alfa"},
        {"indent": 0, "container": True, "level": 2, "text": ["H 2"], "type": "h", "id": None},
        {"indent": 0, "container": True, "type": "bravo_section", "level": 1, "role": "section", "id": "bravo"},
    ]
Exemplo n.º 2
0
def test_item2():
    s = """
:foo:
:bar:baz
::qux
    """.strip()

    rule = p.Star(wg.context["blocks"])
    out, i = rule.accept(s, 0, wg.context)
    util.dump_tree(out)
    assert i == len(s)
    assert out == [
        {"indent": 0, "type": "foo", "role": "item"},
        {"indent": 0, "type": "bar", "role": "item", "text": ["baz"]},
        {"indent": 0, "type": "item", "role": "item", "text": ["qux"]},
    ]
Exemplo n.º 3
0
def test_missing_include():
    doc1 = snippet("""
    [Include:b]
    """)

    ds = stores.DictionaryStore({
        "/a.txt": doc1,
    })
    s = stores.OverlayStore(ds, common_store())
    wp = WikiPages(s, None, caching=False)

    data = wp.json("/a.txt")
    util.dump_tree(data)
    assert data == {
        "type": "root", "included": ["/b.txt"], "attrs": {}, "parents": [],
        "body": []
    }
Exemplo n.º 4
0
def test_item():
    s = """
Alfa:
    Bravo
:Charlie:Delta:
    Echo
Foxtrot
:Golf::
::Hotel:
    """.strip()

    rule = p.Star(wg.context["blocks"])
    out, i = rule.accept(s, 0, wg.context)
    util.dump_tree(out)
    assert i == len(s)
    assert out == [
        {"indent": 0, "text": ["Alfa"], "type": "dt"},
        {"indent": 4, "text": ["Bravo"], "type": "para"},
        {"indent": 0, "role": "item", "text": ["Delta"], "type": "Charlie"},
        {"indent": 4, "text": ["Echo"], "type": "para"},
        {"indent": 0, "text": ["Foxtrot"], "type": "para"},
        {"indent": 0, "role": "item", "type": "Golf"},
        {"indent": 0, "role": "item", "text": ["Hotel"], "type": "item"},
    ]
Exemplo n.º 5
0
def dump(path):
    from bookish.util import dump_tree

    jsondata = parse_page(path, process=False, conditional=False)
    dump_tree(jsondata)