Beispiel #1
0
def test_matches_mystnb():
    assert matches_mystnb("") is False
    assert matches_mystnb("```{code-cell}\n```") is False
    assert matches_mystnb("---\njupytext: true\n---") is False
    for ext in myst_extensions(no_md=True):
        assert matches_mystnb("", ext=ext) is True
    text = dedent("""\
        ---
        {{a
        ---
        ```{code-cell}
        :b: {{c
        ```
        """)
    assert matches_mystnb(text) is True
    text = dedent("""\
        ---
        jupytext:
            text_representation:
                format_name: myst
                extension: .md
        ---
        """)
    assert matches_mystnb(text) is True
    text = dedent("""\
        ---
        a: 1
        ---
        > ```{code-cell}
          ```
        """)
    assert matches_mystnb(text) is True
    assert guess_format(text, ".md") == ("myst", {})
Beispiel #2
0
def test_store_line_numbers():
    notebook = matches_mystnb(dedent("""\
            ---
            a: 1
            ---
            abc
            +++
            def
            ```{{{0}}}
            ---
            b: 2
            ---
            c = 3
            ```
            xyz
            """).format(CODE_DIRECTIVE),
                              store_line_numbers=True,
                              return_nb=True)
    expected = {
        "nbformat":
        4,
        "nbformat_minor":
        4,
        "metadata": {
            "a": 1
        },
        "cells": [
            {
                "cell_type": "markdown",
                "source": "abc",
                "metadata": {
                    "_source_lines": [3, 4]
                },
            },
            {
                "cell_type": "markdown",
                "source": "def",
                "metadata": {
                    "_source_lines": [5, 6]
                },
            },
            {
                "cell_type": "code",
                "metadata": {
                    "b": 2,
                    "_source_lines": [7, 12]
                },
                "execution_count": None,
                "source": "c = 3",
                "outputs": [],
            },
            {
                "cell_type": "markdown",
                "source": "xyz",
                "metadata": {
                    "_source_lines": [12, 13]
                },
            },
        ],
    }
    notebook.nbformat_minor = 4
    compare_notebooks(notebook, from_dict(expected))