Exemplo n.º 1
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.º 2
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.º 3
0
def test_text():
    v = HTMLVisitor()

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

    assert output == "This is text"
Exemplo n.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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"]