blob: 3382ac9037d9b9a4dd7847b9937b06da95ad6ca5 [file] [log] [blame]
from pathlib import Path
import pytest
from markdown_it import MarkdownIt
from markdown_it.token import Token
from markdown_it.extensions.myst_role import myst_role_plugin
from markdown_it.utils import read_fixture_file
FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures", "myst_role.md")
def test_basic():
md = MarkdownIt().use(myst_role_plugin)
src = "{abc}``` a ```"
tokens = md.parse(src)
print(tokens)
assert tokens == [
Token(
type="paragraph_open",
tag="p",
nesting=1,
attrs=None,
map=[0, 1],
level=0,
children=None,
content="",
markup="",
info="",
meta={},
block=True,
hidden=False,
),
Token(
type="inline",
tag="",
nesting=0,
attrs=None,
map=[0, 1],
level=1,
children=[
Token(
type="myst_role",
tag="",
nesting=0,
attrs=None,
map=None,
level=0,
children=None,
content=" a ",
markup="",
info="",
meta={"name": "abc"},
block=False,
hidden=False,
)
],
content="{abc}``` a ```",
markup="",
info="",
meta={},
block=True,
hidden=False,
),
Token(
type="paragraph_close",
tag="p",
nesting=-1,
attrs=None,
map=None,
level=0,
children=None,
content="",
markup="",
info="",
meta={},
block=True,
hidden=False,
),
]
@pytest.mark.parametrize("line,title,input,expected", read_fixture_file(FIXTURE_PATH))
def test_all(line, title, input, expected):
md = MarkdownIt("commonmark").use(myst_role_plugin)
md.options["xhtmlOut"] = False
text = md.render(input)
print(text)
assert text.rstrip() == expected.rstrip()