def test_option_in_cell_meta():

    out_str = jinja_filter(
        "+@label", "rst", create_ipub_meta({"use_numref": False}),
        create_ipub_meta({"use_numref": True})
    )
    assert out_str == ":numref:`label`"
Exemple #2
0
def test_complex_equation():

    in_source = [
        "$$\\begin{equation*}\n",
        "f(x) = \\left\\{\n",
        "\\begin{array}{ll}\n",
        "\\; x \\qquad x \\geq 0 \\\\\n",
        "\\; 0 \\qquad else\n",
        "\\end{array}\n",
        "\\right.\n",
        "\\end{equation*}$$",
    ]

    out_string = jinja_filter("".join(in_source), "rst", create_ipub_meta({}),
                              {})
    expected = [
        ".. math::",
        "   :nowrap:",
        "",
        "   \\begin{equation*}",
        "   f(x) = \\left\\{",
        "   \\begin{array}{ll}",
        "   \\; x \\qquad x \\geq 0 \\\\",
        "   \\; 0 \\qquad else",
        "   \\end{array}",
        "   \\right.",
        "   \\end{equation*}",
    ]
    assert out_string.strip() == "\n".join(expected)
Exemple #3
0
def test_option_in_top_matter():
    # TODO create ipub yaml from IPUB_META_ROUTE

    in_str = "\n".join([
        "---", "ipub:", "  pandoc:", "    use_numref: true", "", "...", "",
        "+@label"
    ])

    out_str = jinja_filter(in_str, "rst",
                           create_ipub_meta({"use_numref": False}), {})
    assert out_str == ":numref:`label`"
Exemple #4
0
def create_git_releases(app):

    this_folder = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))

    git_history = (
        urllib.request.urlopen(
            "https://api.github.com/repos/chrisjsewell/ipypublish/releases"
        )
        .read()
        .decode("utf-8")
    )
    # NOTE on vscode this could fail with urllib.error.HTTPError
    git_history_json = json.loads(git_history)
    # NOTE on vscode this was failing unless encoding='utf8' was present
    with io.open(os.path.join(this_folder, "releases.rst"), "w", encoding="utf8") as f:
        f.write(".. _releases:\n\n")
        f.write("Releases\n")
        f.write("========\n\n")
        for i, r in enumerate(git_history_json):
            if r["tag_name"].split(".")[-1] == "0":
                level = 2
            elif i == 0:
                f.write("Current Version\n")
                f.write("---------------\n\n")
                level = 3
            else:
                level = 3
            subtitle = " ".join([r["tag_name"], "-", r["name"].rstrip(), "\n"])
            f.write(subtitle)
            if level == 2:
                f.write("-" * (len(subtitle) - 1) + "\n")
            else:
                f.write("~" * (len(subtitle) - 1) + "\n")
            f.write("\n")
            source = jinja_filter(r["body"], "rst", {}, {})
            for line in source.split("\n"):
                f.write(" ".join([line.rstrip(), "\n"]))
            f.write("\n")
Exemple #5
0
def test_remove_filter():

    out_str = jinja_filter("+@label", "rst",
                           create_ipub_meta({"apply_filters": False}), {})
    assert out_str == "+@label"
Exemple #6
0
def test_at_notation_false():

    out_str = jinja_filter("+@label", "rst",
                           create_ipub_meta({"at_notation": False}), {})
    assert out_str == "+ :cite:`label`"
Exemple #7
0
def test_basic():

    out_str = jinja_filter("a", "rst", {}, {})
    assert out_str == "a"
Exemple #8
0
def test_reference_prefix():

    out_str = jinja_filter("+@label", "rst", {}, {})
    assert out_str == ":numref:`label`"
Exemple #9
0
def test_reference():

    out_str = jinja_filter("@label", "rst", {}, {})
    assert out_str == ":cite:`label`"