def test_parse_header(): assert unwind(parse(Standard, '# Header ![img](imgurl)')) == [ 'div', [ 'h1', [ 'a.anchor', { 'id': 'header-imgimgurl' }, 'Header ', [ 'img.full-image', { 'alt': 'img', 'src': 'imgurl', 'style': { 'margin': '0 auto', 'display': 'block', 'max-width': '100%' } } ] ] ] ] assert unwind(parse(Standard, '# h1\n## h2\n### h3', Paragraphs)) == [ 'div', ['h1', ['a.anchor', { 'id': 'h1' }, 'h1']], ['h2', ['a.anchor', { 'id': 'h2' }, 'h2']], ['h3', ['a.anchor', { 'id': 'h3' }, 'h3']] ]
def test_singlegroups(s: str): assert unwind(parse(Registry(NoopBlock, Bold), '*' + s + '*', NoopBlock)) == ['div', ['strong', {}, s]] assert unwind(parse(Registry(NoopBlock, Italic), '_' + s + '_', NoopBlock)) == ['div', ['em', {}, s]] assert unwind( parse(Registry(NoopBlock, Monospace), '`' + s + '`', NoopBlock)) == ['div', ['code', {}, s]]
def test_parseblock_nestingsub_multiple(): assert unwind(parseblock(sample + [IdentityBlock], IdentityBlock, '*hello*\n---paragraphs\nhello\n---paragraphs\nhello again\n...\n...\n')) == [ 'div', ['strong', {}, 'hello'], '\n', ['div', ['p', 'hello'], ['div', ['p', 'hello again']]]] assert unwind(parseblock(sample, Paragraphs, ' *hello*\n---paragraphs\nhello\n---paragraphs\n*hello* again\n...\n...\n')) == [ 'div', ['p', ' ', ['strong', {}, 'hello']], ['div', ['p', 'hello'], ['div', ['p', ['strong', {}, 'hello'], ' again']]]]
def test_parse_header(): assert unwind(parse(Standard, '# Header ![img](imgurl)')) == [ 'div', ['h1', ['a', {'name': 'header-imgimgurl'}, 'Header ', ['img', {'alt': 'img', 'src': 'imgurl', 'style': {'margin': '0 auto', 'display': 'block', 'max-width': '100%'}}]]]] assert unwind( parse(Standard, '# h1\n## h2\n### h3', Paragraphs)) == [ 'div', ['h1', ['a', {'name': 'h1'}, 'h1']], ['h2', ['a', {'name': 'h2'}, 'h2']], ['h3', ['a', {'name': 'h3'}, 'h3']]]
def test_parseblock_nestingpost(): @block() def IdentityBlock(text): return ['div', text] assert unwind(parseblock(Registry(IdentityBlock, Paragraphs), IdentityBlock, 'hello\n---paragraphs\nhello\n...\n')) == ['div', 'hello\n', ['div', ['p', 'hello']]]
def test_parseblock_nestingsub(): # should consume paragraphs block assert unwind( parseblock(Registry(IdentityBlock, Paragraphs), IdentityBlock, 'hello\n---paragraphs\nhello\n...\n')) == [ 'div', 'hello\n', ['div', ['p', 'hello']] ]
def test_tooltip(): assert unwind( parse(Registry(NoopBlock, Tooltip), 'T[text](tooltip)', NoopBlock)) == [ 'div', ['span.tooltip', 'text', ['div.tooltip-text', 'tooltip']] ]
def test_header(s: str, n: int): assert unwind( parse(Registry(Paragraphs, Header), '#' * n + ' ' + s, Paragraphs)) == [ 'div', ['h' + str(n), ['a.anchor', { 'id': s.lower() }, s]] ]
def test_parseblock_nestingsub_multiple(): assert unwind( parseblock( sample + [IdentityBlock], IdentityBlock, '*hello*\n---paragraphs\nhello\n---paragraphs\nhello again\n...\n...\n' )) == [ 'div', ['strong', {}, 'hello'], '\n', ['div', ['p', 'hello'], ['div', ['p', 'hello again']]] ] assert unwind( parseblock( sample, Paragraphs, ' *hello*\n---paragraphs\nhello\n---paragraphs\n*hello* again\n...\n...\n' )) == [ 'div', ['p', ' ', ['strong', {}, 'hello']], [ 'div', ['p', 'hello'], ['div', ['p', ['strong', {}, 'hello'], ' again']] ] ]
def test_standard_registry(): t1 = """ # Placeholder * bold * new paragraph """ assert unwind(parse(Standard, t1)) == [ 'div', ['h1', ['a.anchor', { 'id': 'placeholder' }, 'Placeholder']], ['p', ['strong', {}, ' bold ']], ['p', 'new paragraph'] ]
def test_parseblock_nestingsub(): # should consume paragraphs block assert unwind(parseblock(Registry(IdentityBlock, Paragraphs), IdentityBlock, 'hello\n---paragraphs\nhello\n...\n')) == ['div', 'hello\n', ['div', ['p', 'hello']]]
def test_parseblock_nosub(): examples = ['test', 'k', 'a;lkjfksdfnqwenqw;eriouZN<ZMXz;lkj;sldakfjsf'] for e in examples: assert unwind(parseblock(sample, Paragraphs, e)) == ['div', ['p', e]]
def test_parseblock_empty(): assert unwind(parseblock(sample, Paragraphs, '')) == ['div']
def test_parsemacros(name: str, text: str): assert unwind(parsemacros('{} = {}'.format(name, text))) == [[name, text]]
def test_regex_clash(s: str): assert unwind(parse(Standard, '__'+s+'__')) == [ 'div', ['p', ['span', {'style': 'text-decoration:underline;'}, s]]]
def test_parseinline_empty(): assert parseinline(sample, Paragraphs, '') == [''] assert parseinline(Standard, Paragraphs, '**') == [(Bold, ['strong', {}, ''])] assert unwind(parse(Standard, '')) == ['div']
def test_criticsub(): assert unwind( parse(Registry(Paragraphs, CriticSub), '{~~a~>b~~}', Paragraphs)) == ['div', ['p', [['del', 'a'], ['ins', 'b']]]]
def test_matrix(): assert unwind(Matrix('c | x')) == [ 'div.matrix.matrix-flex', [ 'div', { 'style': { 'display': 'flex' } }, ['span', { 'style': { 'flex': 1 } }, 'c'], ['span', { 'style': { 'flex': 1 } }, 'x'] ] ] assert unwind(Matrix('c|x')) == [ 'div.matrix.matrix-flex', [ 'div', { 'style': { 'display': 'flex' } }, ['span', { 'style': { 'flex': 1 } }, 'c'], ['span', { 'style': { 'flex': 1 } }, 'x'] ] ] assert unwind(Matrix('c| x')) == [ 'div.matrix.matrix-flex', [ 'div', { 'style': { 'display': 'flex' } }, ['span', { 'style': { 'flex': 1 } }, 'c'], ['span', { 'style': { 'flex': 1 } }, 'x'] ] ] assert unwind(Matrix('c |x')) == [ 'div.matrix.matrix-flex', [ 'div', { 'style': { 'display': 'flex' } }, ['span', { 'style': { 'flex': 1 } }, 'c'], ['span', { 'style': { 'flex': 1 } }, 'x'] ] ] assert unwind(Matrix('c | x', type='matrix')) == [ 'table.matrix.matrix-table', ['tr', { 'style': {} }, ['td', {}, 'c'], ['td', {}, 'x']] ]
def test_regex_clash(s: str): assert unwind(parse(Standard, '__' + s + '__')) == [ 'div', ['p', ['span', { 'style': 'text-decoration:underline;' }, s]] ]
def test_parseblock_nestingpost(): assert unwind( parseblock(Registry(IdentityBlock, Paragraphs), IdentityBlock, 'hello\n---paragraphs\nhello\n...\n')) == [ 'div', 'hello\n', ['div', ['p', 'hello']] ]
def test_parsemacros(name: str, text: str): assert unwind(parsemacros('{} = {}'.format( name, text))) == [[name.strip(), text.strip()]]