Files
markitect-main/tests/test_parser.py

121 lines
2.6 KiB
Python

import pytest
from markitect.parser import parse_markdown_to_ast
def test_parse_basic_markdown():
md_content = "# Heading\nThis is a paragraph."
expected_ast = [
{
'type': 'heading_open',
'tag': 'h1',
'attrs': {},
'map': [0, 1],
'nesting': 1,
'level': 0,
'content': '',
'markup': '#',
'info': '',
'meta': {},
'block': True,
'hidden': False
},
{
'type': 'inline',
'tag': '',
'attrs': {},
'map': [0, 1],
'nesting': 0,
'level': 1,
'children': [
{
'type': 'text',
'tag': '',
'attrs': {},
'nesting': 0,
'level': 0,
'content': 'Heading',
'markup': '',
'info': '',
'meta': {},
'block': False,
'hidden': False
}
],
'content': 'Heading',
'markup': '',
'info': '',
'meta': {},
'block': True,
'hidden': False
},
{
'type': 'heading_close',
'tag': 'h1',
'attrs': {},
'nesting': -1,
'level': 0,
'content': '',
'markup': '#',
'info': '',
'meta': {},
'block': True,
'hidden': False
},
{
'type': 'paragraph_open',
'tag': 'p',
'attrs': {},
'map': [1, 2],
'nesting': 1,
'level': 0,
'content': '',
'markup': '',
'info': '',
'meta': {},
'block': True,
'hidden': False
},
{
'type': 'inline',
'tag': '',
'attrs': {},
'map': [1, 2],
'nesting': 0,
'level': 1,
'children': [
{
'type': 'text',
'tag': '',
'attrs': {},
'nesting': 0,
'level': 0,
'content': 'This is a paragraph.',
'markup': '',
'info': '',
'meta': {},
'block': False,
'hidden': False
}
],
'content': 'This is a paragraph.',
'markup': '',
'info': '',
'meta': {},
'block': True,
'hidden': False
},
{
'type': 'paragraph_close',
'tag': 'p',
'attrs': {},
'nesting': -1,
'level': 0,
'content': '',
'markup': '',
'info': '',
'meta': {},
'block': True,
'hidden': False
}
]
assert parse_markdown_to_ast(md_content) == expected_ast