コード例 #1
0
def test_encoding():
    html_tag = ext.draw_bob(BASIC_BLOCK_TXT,
                            default_options={'tag_type': "inline_svg"})
    assert "xmlns" in html_tag
    assert "<svg" in html_tag
    assert "%3Csvg" not in html_tag
    assert "svg+xml;base64" not in html_tag
    assert "svg+xml;utf-8" not in html_tag
    assert "<img" not in html_tag

    html_tag = ext.draw_bob(BASIC_BLOCK_TXT,
                            default_options={'tag_type': "img_base64_svg"})
    assert "xmlns" not in html_tag
    assert "<svg" not in html_tag
    assert "%3Csvg" not in html_tag
    assert "svg+xml;base64" in html_tag
    assert "svg+xml;utf-8" not in html_tag
    assert '<img class="bob" src=' in html_tag

    html_tag = ext.draw_bob(BASIC_BLOCK_TXT,
                            default_options={'tag_type': "img_utf8_svg"})
    assert "xmlns" in html_tag
    assert "<svg" not in html_tag
    assert "%3Csvg" in html_tag
    assert "svg+xml;base64" not in html_tag
    assert "svg+xml;utf-8" in html_tag
    assert '<img class="bob" src=' in html_tag
コード例 #2
0
def test_postproc():
    html_tag = ext.draw_bob(BASIC_BLOCK_TXT, {'tag_type': "img_base64_svg"})
    assert '<img class="bob"' in html_tag
    html_tag = ext.draw_bob(BASIC_BLOCK_TXT)

    # TODO (mb 2021-07-22): brittle test, perhaps switch to image diff
    #   based testing.
    return

    assert '<svg class="bob"' in html_tag

    assert re.search(r"\.bg_fill\s*\{\s*fill:\s*white;", html_tag)
    # NOTE (mb 2020-06-05): Some versions of svgbob produce
    #   a backdrop rect with a class, some with an inline fill.
    backdrop_rect = re.search(
        r'</style>\s*<rect\s+fill="white"', html_tag) or (
            re.search(r'</style>\s*<rect\s+class="backdrop"', html_tag)
            and re.search(r"rect\.backdrop\s*\{\s*fill:\s*white", html_tag))
    assert backdrop_rect
    assert re.search(r"\.fg_fill\s*\{\s*fill:\s*black;", html_tag)

    html_tag = ext.draw_bob(BASIC_BLOCK_TXT, {
        'bg_color': "red",
        'fg_color': "green"
    })

    assert '<svg class="bob"' in html_tag
    assert re.search(r"\.bg_fill\s*\{\s*fill:\s*red;", html_tag)
    backdrop_rect = re.search(r'</style>\s*<rect\s+fill="red"', html_tag) or (
        re.search(r'</style>\s*<rect\s+class="backdrop"', html_tag)
        and re.search(r"rect\.backdrop\s*\{\s*fill:\s*red", html_tag))
    assert backdrop_rect
    assert re.search(r"\.fg_fill\s*\{\s*fill:\s*green;", html_tag)
コード例 #3
0
def test_trailing_whitespace():
    default_output = ext.draw_bob(BASIC_BLOCK_TXT)

    trailing_space_result = md.markdown(BASIC_BLOCK_TXT + "  ",
                                        extensions=['markdown_svgbob'])
    assert default_output in trailing_space_result
    assert "```" not in trailing_space_result
コード例 #4
0
def test_svgbob_config():
    result = md.markdown(
        BASIC_BLOCK_TXT,
        extensions=['markdown_svgbob'],
        extension_configs={'markdown_svgbob': {
            'stroke-width': 3
        }},
    )

    html_tag = ext.draw_bob(BASIC_BLOCK_TXT)
    unexpected = "<p>{}</p>".format(html_tag)
    assert result != unexpected

    html_tag = ext.draw_bob(BASIC_BLOCK_TXT, {'stroke-width': 3})
    expected = "<p>{}</p>".format(html_tag)

    assert result == expected
コード例 #5
0
def test_extended_svgbob():
    extensions = DEFAULT_MKDOCS_EXTENSIONS + ['markdown_svgbob']
    result = md.markdown(EXTENDED_BLOCK_TXT, extensions=extensions)

    html_tag = ext.draw_bob(BASIC_BLOCK_TXT)
    expected = EXTENDED_HTML_TEMPLATE.format(html_tag)
    expected = expected.replace("\n", "")
    result = result.replace("\n", "")

    assert result == expected
コード例 #6
0
def test_basic_svg():
    fig_data = markdown_svgbob.text2svg(BASIC_FIG_TXT)

    # with open("debug_img_output_svgbob.svg", mode='wb') as fobj:
    #     fobj.write(fig_data)

    assert b"<svg" in fig_data
    assert b"</svg>" in fig_data

    inline_svg = ext.draw_bob(BASIC_BLOCK_TXT,
                              default_options={'tag_type': "inline_svg"})
    default_output = ext.draw_bob(BASIC_BLOCK_TXT)
    assert inline_svg == default_output
    assert inline_svg
    assert inline_svg.startswith("<svg")
    expected = "<p>{}</p>".format(inline_svg)

    assert "xmlns" in inline_svg

    result = md.markdown(BASIC_BLOCK_TXT, extensions=['markdown_svgbob'])

    assert inline_svg in result

    assert result == expected
コード例 #7
0
def test_svgbob_options():
    fig_data_default = markdown_svgbob.text2svg(BASIC_FIG_TXT)
    fig_text_default = fig_data_default.decode("utf-8")

    assert re.search(r"stroke-width:\s*2", fig_text_default)
    assert not re.search(r"stroke-width:\s*4", fig_text_default)

    options = {'stroke-width': 4}
    fig_data = markdown_svgbob.text2svg(BASIC_FIG_TXT, options)
    fig_text = fig_data.decode("utf-8")

    assert not re.search(r"stroke-width:\s*2", fig_text)
    assert re.search(r"stroke-width:\s*4", fig_text)

    assert "<svg" in fig_text
    assert "</svg>" in fig_text

    result = md.markdown(OPTIONS_BLOCK_TXT, extensions=['markdown_svgbob'])

    html_tag = ext.draw_bob(OPTIONS_BLOCK_TXT)
    expected = "<p>{}</p>".format(html_tag)

    assert result == expected