Exemplo n.º 1
0
def test_footnote_definition():
    v = HTMLVisitor()

    result = v._visit_footnote_def({
        "type":
        "footnote_def",
        "number":
        1,
        "refanchor":
        "refXYZ",
        "defanchor":
        "defXYZ",
        "content": [{
            "type": "sentence",
            "content": [
                {
                    "type": "text",
                    "value": "Some text 1"
                },
            ],
        }],
    })

    assert result == {
        "defanchor": "defXYZ",
        "number": 1,
        "refanchor": "refXYZ",
        "text": "Some text 1",
    }
Exemplo n.º 2
0
def test_sentence():
    v = HTMLVisitor()

    output = v.visit(
        {"type": "sentence", "content": [{"type": "text", "value": "This is text"}]}
    )

    assert output == "This is text"
Exemplo n.º 3
0
def test_macro_template():
    v = HTMLVisitor()
    v.default_templates["macro.html"] = "whatever"

    ast = init_ast("[unknown](This is an unknown macro)")

    output = [v.visit(node) for node in ast]

    assert output == ["<p>whatever</p>"]
Exemplo n.º 4
0
def test_text():
    v = HTMLVisitor()

    output = v.visit({
        "type": "text",
        "value": "This is text",
    })

    assert output == "This is text"
Exemplo n.º 5
0
def test_footnotes():
    v = HTMLVisitor()

    result = v.visit_footnotes([
        {
            "type":
            "footnote_def",
            "number":
            1,
            "refanchor":
            "refXYZ1",
            "defanchor":
            "defXYZ1",
            "content": [{
                "type":
                "sentence",
                "content": [
                    {
                        "type": "text",
                        "value": "Some text 1"
                    },
                ],
            }],
        },
        {
            "type":
            "footnote_def",
            "number":
            2,
            "refanchor":
            "refXYZ2",
            "defanchor":
            "defXYZ2",
            "content": [{
                "type":
                "sentence",
                "content": [
                    {
                        "type": "text",
                        "value": "Some text 2"
                    },
                ],
            }],
        },
    ])

    assert result == remove_indentation("""
        <div id="_footnotes">
          <div id="defXYZ1">
            <a href="#refXYZ1">1</a> Some text 1
          </div>
          <div id="defXYZ2">
            <a href="#refXYZ2">2</a> Some text 2
          </div>
        </div>
        """)
Exemplo n.º 6
0
def test_macro_alias_value_for_first_unnamed_arg():
    v = HTMLVisitor()
    v.default_templates["macro.html"] = "whatever"
    v.default_templates["macro-unknown.html"] = "{{ value }} - {{ kwargs.name}}"

    ast = init_ast('[unknown]("some text", name=mau)')

    output = [v.visit(node) for node in ast]

    assert output == ["<p>some text - mau</p>"]
Exemplo n.º 7
0
def test_macro_provides_args_and_kwargs():
    v = HTMLVisitor()
    v.default_templates["macro.html"] = "whatever"
    v.default_templates["macro-unknown.html"] = "{{ args[0] }} - {{ kwargs.name}}"

    ast = init_ast('[unknown]("some text", name=mau)')

    output = [v.visit(node) for node in ast]

    assert output == ["<p>some text - mau</p>"]
Exemplo n.º 8
0
def test_macro_uses_specific_template():
    v = HTMLVisitor()
    v.default_templates["macro.html"] = "whatever"
    v.default_templates["macro-unknown.html"] = "the right one"

    ast = init_ast("[unknown](This is an unknown macro)")

    output = [v.visit(node) for node in ast]

    assert output == ["<p>the right one</p>"]
Exemplo n.º 9
0
def test_footnote():
    v = HTMLVisitor()

    result = v.visit({
        "type": "footnote_ref",
        "number": 6,
        "refanchor": "refXYZ",
        "defanchor": "defXYZ",
    })

    assert result == '<sup>[<a id="refXYZ" href="#defXYZ">6</a>]</sup>'
Exemplo n.º 10
0
def test_footnotes():
    v = HTMLVisitor()

    nodes = [
        {
            "type": "footnote_def",
            "number": 1,
            "refanchor": "refXYZ1",
            "defanchor": "defXYZ1",
            "content": [
                {
                    "type": "sentence",
                    "content": [
                        {"type": "text", "value": "Some text 1"},
                    ],
                }
            ],
        },
        {
            "type": "footnote_def",
            "number": 2,
            "refanchor": "refXYZ2",
            "defanchor": "defXYZ2",
            "content": [
                {
                    "type": "sentence",
                    "content": [
                        {"type": "text", "value": "Some text 2"},
                    ],
                }
            ],
        },
    ]

    result = v._render(
        "footnotes",
        entries="".join([v.visit(i) for i in nodes]),
    )

    assert result == remove_indentation(
        """
        <div id="_footnotes">
          <div id="defXYZ1">
            <a href="#refXYZ1">1</a> Some text 1
          </div>
          <div id="defXYZ2">
            <a href="#refXYZ2">2</a> Some text 2
          </div>
        </div>
        """
    )
Exemplo n.º 11
0
Arquivo: test_toc.py Projeto: xrmx/mau
def test_toc_entry():
    v = HTMLVisitor()

    result = v._visit_toc_entry({
        "type": "toc_entry",
        "level": 1,
        "text": "Header 1",
        "anchor": "Header 1-XXXXXX",
        "children": [],
    })

    assert result == {
        "text": "Header 1",
        "anchor": "Header 1-XXXXXX",
        "children": "",
    }
Exemplo n.º 12
0
def test_block_template():
    v = HTMLVisitor()
    v.default_templates["block.html"] = "whatever"

    ast = init_ast(
        dedent(
            """
            [block]
            ----
            Primary content
            ----
            Secondary content
            """
        )
    )

    output = [v.visit(node) for node in ast]

    assert output == ["whatever"]
Exemplo n.º 13
0
def test_block_supports_kwargs():
    v = HTMLVisitor()
    v.default_templates["block.html"] = "whatever"
    v.default_templates[
        "block-unknown.html"
    ] = "{{ kwargs.name }} - {{ kwargs.colour }}"

    ast = init_ast(
        dedent(
            """
            [unknown, name=myblock, colour=green]
            ----
            ----
            """
        )
    )

    output = [v.visit(node) for node in ast]

    assert output == ["myblock - green"]
Exemplo n.º 14
0
def test_block_uses_specific_template():
    v = HTMLVisitor()
    v.default_templates["block.html"] = "whatever"
    v.default_templates["block-unknown.html"] = "the right one"

    ast = init_ast(
        dedent(
            """
            [unknown]
            ----
            Primary content
            ----
            Secondary content
            """
        )
    )

    output = [v.visit(node) for node in ast]

    assert output == ["the right one"]
Exemplo n.º 15
0
def test_toc_entry():
    v = HTMLVisitor()

    node = nodes.TocEntryNode(nodes.HeaderNode("Header 1", 1,
                                               "Header 1-XXXXXX"),
                              children=[])

    v._visit_toc_entry(node.asdict())

    assert node.asdict() == {
        "type": "toc_entry",
        "header": {
            "type": "header",
            "value": "Header 1",
            "level": 1,
            "anchor": "Header 1-XXXXXX",
            "kwargs": {},
            "tags": [],
        },
        "children": [],
    }
Exemplo n.º 16
0
def test_block_does_not_support_args():
    v = HTMLVisitor()
    v.default_templates["block.html"] = "whatever"
    v.default_templates["block-unknown.html"] = ""

    with pytest.raises(ParserError):
        ast = init_ast(
            dedent(
                """
                [unknown, value1, value2]
                ----
                Primary content
                ----
                Secondary content
                """
            )
        )