|
|
|
@@ -6,7 +6,7 @@ class Converter(nixos_render_docs.md.Converter):
|
|
|
|
|
# actual renderer doesn't matter, we're just parsing.
|
|
|
|
|
__renderer__ = nixos_render_docs.docbook.DocBookRenderer
|
|
|
|
|
|
|
|
|
|
def test_inline_anchor_simple() -> None:
|
|
|
|
|
def test_attr_span_parsing() -> None:
|
|
|
|
|
c = Converter({})
|
|
|
|
|
assert c._parse("[]{#test}") == [
|
|
|
|
|
Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[0, 1], level=0, children=None,
|
|
|
|
@@ -14,14 +14,71 @@ def test_inline_anchor_simple() -> None:
|
|
|
|
|
Token(type='inline', tag='', nesting=0, attrs={}, map=[0, 1], level=1, content='[]{#test}',
|
|
|
|
|
markup='', info='', meta={}, block=True, hidden=False,
|
|
|
|
|
children=[
|
|
|
|
|
Token(type='inline_anchor', tag='', nesting=0, attrs={'id': 'test'}, map=None, level=0,
|
|
|
|
|
Token(type='attr_span_begin', tag='span', nesting=1, attrs={'id': 'test'}, map=None, level=0,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='attr_span_end', tag='span', nesting=-1, attrs={}, map=None, level=0,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=False, hidden=False)
|
|
|
|
|
]),
|
|
|
|
|
Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=0,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=True, hidden=False)
|
|
|
|
|
]
|
|
|
|
|
assert c._parse("[]{.test}") == [
|
|
|
|
|
Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[0, 1], level=0, children=None,
|
|
|
|
|
content='', markup='', info='', meta={}, block=True, hidden=False),
|
|
|
|
|
Token(type='inline', tag='', nesting=0, attrs={}, map=[0, 1], level=1, content='[]{.test}',
|
|
|
|
|
markup='', info='', meta={}, block=True, hidden=False,
|
|
|
|
|
children=[
|
|
|
|
|
Token(type='attr_span_begin', tag='span', nesting=1, attrs={'class': 'test'}, map=None,
|
|
|
|
|
level=0, children=None, content='', markup='', info='', meta={}, block=False,
|
|
|
|
|
hidden=False),
|
|
|
|
|
Token(type='attr_span_end', tag='span', nesting=-1, attrs={}, map=None, level=0,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=False, hidden=False)
|
|
|
|
|
]),
|
|
|
|
|
Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=0,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=True, hidden=False)
|
|
|
|
|
]
|
|
|
|
|
assert c._parse("[]{.test1 .test2 #foo .test3 .test4}") == [
|
|
|
|
|
Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[0, 1], level=0, children=None,
|
|
|
|
|
content='', markup='', info='', meta={}, block=True, hidden=False),
|
|
|
|
|
Token(type='inline', tag='', nesting=0, attrs={}, map=[0, 1], level=1,
|
|
|
|
|
content='[]{.test1 .test2 #foo .test3 .test4}',
|
|
|
|
|
markup='', info='', meta={}, block=True, hidden=False,
|
|
|
|
|
children=[
|
|
|
|
|
Token(type='attr_span_begin', tag='span', nesting=1,
|
|
|
|
|
attrs={'class': 'test1 test2 test3 test4', 'id': 'foo'}, map=None, level=0,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='attr_span_end', tag='span', nesting=-1, attrs={}, map=None, level=0,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=False, hidden=False)
|
|
|
|
|
]),
|
|
|
|
|
Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=0,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=True, hidden=False)
|
|
|
|
|
]
|
|
|
|
|
assert c._parse("[]{#a #a}") == [
|
|
|
|
|
Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[0, 1], level=0, children=None,
|
|
|
|
|
content='', markup='', info='', meta={}, block=True, hidden=False),
|
|
|
|
|
Token(type='inline', tag='', nesting=0, attrs={}, map=[0, 1], level=1,
|
|
|
|
|
content='[]{#a #a}', markup='', info='', meta={}, block=True, hidden=False,
|
|
|
|
|
children=[
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
content='[]{#a #a}', markup='', info='', meta={}, block=False, hidden=False)
|
|
|
|
|
]),
|
|
|
|
|
Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
content='', markup='', info='', meta={}, block=True, hidden=False)
|
|
|
|
|
]
|
|
|
|
|
assert c._parse("[]{foo}") == [
|
|
|
|
|
Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[0, 1], level=0, children=None,
|
|
|
|
|
content='', markup='', info='', meta={}, block=True, hidden=False),
|
|
|
|
|
Token(type='inline', tag='', nesting=0, attrs={}, map=[0, 1], level=1,
|
|
|
|
|
content='[]{foo}', markup='', info='', meta={}, block=True, hidden=False,
|
|
|
|
|
children=[
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
content='[]{foo}', markup='', info='', meta={}, block=False, hidden=False)
|
|
|
|
|
]),
|
|
|
|
|
Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
content='', markup='', info='', meta={}, block=True, hidden=False)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
def test_inline_anchor_formatted() -> None:
|
|
|
|
|
def test_attr_span_formatted() -> None:
|
|
|
|
|
c = Converter({})
|
|
|
|
|
assert c._parse("a[b c `d` ***e***]{#test}f") == [
|
|
|
|
|
Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[0, 1], level=0,
|
|
|
|
@@ -31,28 +88,30 @@ def test_inline_anchor_formatted() -> None:
|
|
|
|
|
children=[
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0,
|
|
|
|
|
children=None, content='a', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='inline_anchor', tag='', nesting=0, attrs={'id': 'test'}, map=None, level=0,
|
|
|
|
|
Token(type='attr_span_begin', tag='span', nesting=1, attrs={'id': 'test'}, map=None, level=0,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
content='b c ', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='code_inline', tag='code', nesting=0, attrs={}, map=None, level=0,
|
|
|
|
|
children=None, content='d', markup='`', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
content=' ', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='em_open', tag='em', nesting=1, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
content='', markup='*', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=1, children=None,
|
|
|
|
|
content='b c ', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='code_inline', tag='code', nesting=0, attrs={}, map=None, level=1,
|
|
|
|
|
children=None, content='d', markup='`', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=1, children=None,
|
|
|
|
|
content=' ', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='em_open', tag='em', nesting=1, attrs={}, map=None, level=1, children=None,
|
|
|
|
|
content='', markup='*', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=2, children=None,
|
|
|
|
|
content='', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='strong_open', tag='strong', nesting=1, attrs={}, map=None, level=1,
|
|
|
|
|
Token(type='strong_open', tag='strong', nesting=1, attrs={}, map=None, level=2,
|
|
|
|
|
children=None, content='', markup='**', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=3, children=None,
|
|
|
|
|
content='e', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='strong_close', tag='strong', nesting=-1, attrs={}, map=None, level=2,
|
|
|
|
|
children=None, content='', markup='**', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=2, children=None,
|
|
|
|
|
content='e', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='strong_close', tag='strong', nesting=-1, attrs={}, map=None, level=1,
|
|
|
|
|
children=None, content='', markup='**', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=1, children=None,
|
|
|
|
|
content='', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='em_close', tag='em', nesting=-1, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
Token(type='em_close', tag='em', nesting=-1, attrs={}, map=None, level=1, children=None,
|
|
|
|
|
content='', markup='*', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='attr_span_end', tag='span', nesting=-1, attrs={}, map=None, level=0,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
content='f', markup='', info='', meta={}, block=False, hidden=False)
|
|
|
|
|
]),
|
|
|
|
@@ -60,7 +119,7 @@ def test_inline_anchor_formatted() -> None:
|
|
|
|
|
content='', markup='', info='', meta={}, block=True, hidden=False)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
def test_inline_anchor_in_heading() -> None:
|
|
|
|
|
def test_attr_span_in_heading() -> None:
|
|
|
|
|
c = Converter({})
|
|
|
|
|
# inline anchors in headers are allowed, but header attributes should be preferred
|
|
|
|
|
assert c._parse("# foo []{#bar} baz") == [
|
|
|
|
@@ -71,8 +130,10 @@ def test_inline_anchor_in_heading() -> None:
|
|
|
|
|
children=[
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
content='foo ', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='inline_anchor', tag='', nesting=0, attrs={'id': 'bar'}, map=None, level=0,
|
|
|
|
|
Token(type='attr_span_begin', tag='span', nesting=1, attrs={'id': 'bar'}, map=None, level=0,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='attr_span_end', tag='span', nesting=-1, attrs={}, map=None, level=0,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
content=' baz', markup='', info='', meta={}, block=False, hidden=False)
|
|
|
|
|
]),
|
|
|
|
@@ -80,7 +141,7 @@ def test_inline_anchor_in_heading() -> None:
|
|
|
|
|
content='', markup='#', info='', meta={}, block=True, hidden=False)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
def test_inline_anchor_on_links() -> None:
|
|
|
|
|
def test_attr_span_on_links() -> None:
|
|
|
|
|
c = Converter({})
|
|
|
|
|
assert c._parse("[ [a](#bar) ]{#foo}") == [
|
|
|
|
|
Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[0, 1], level=0, children=None,
|
|
|
|
@@ -88,24 +149,26 @@ def test_inline_anchor_on_links() -> None:
|
|
|
|
|
Token(type='inline', tag='', nesting=0, attrs={}, map=[0, 1], level=1, content='[ [a](#bar) ]{#foo}',
|
|
|
|
|
markup='', info='', meta={}, block=True, hidden=False,
|
|
|
|
|
children=[
|
|
|
|
|
Token(type='inline_anchor', tag='', nesting=0, attrs={'id': 'foo'}, map=None, level=0,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
content=' ', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='link_open', tag='a', nesting=1, attrs={'href': '#bar'}, map=None, level=0,
|
|
|
|
|
Token(type='attr_span_begin', tag='span', nesting=1, attrs={'id': 'foo'}, map=None, level=0,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=1, children=None,
|
|
|
|
|
content=' ', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='link_open', tag='a', nesting=1, attrs={'href': '#bar'}, map=None, level=1,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=2, children=None,
|
|
|
|
|
content='a', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='link_close', tag='a', nesting=-1, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
Token(type='link_close', tag='a', nesting=-1, attrs={}, map=None, level=1, children=None,
|
|
|
|
|
content='', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
content=' ', markup='', info='', meta={}, block=False, hidden=False)
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=1, children=None,
|
|
|
|
|
content=' ', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='attr_span_end', tag='span', nesting=-1, attrs={}, map=None, level=0,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=False, hidden=False)
|
|
|
|
|
]),
|
|
|
|
|
Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
content='', markup='', info='', meta={}, block=True, hidden=False)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
def test_inline_anchor_nested() -> None:
|
|
|
|
|
def test_attr_span_nested() -> None:
|
|
|
|
|
# inline anchors may contain more anchors (even though this is a bit pointless)
|
|
|
|
|
c = Converter({})
|
|
|
|
|
assert c._parse("[ [a]{#bar} ]{#foo}") == [
|
|
|
|
@@ -114,20 +177,26 @@ def test_inline_anchor_nested() -> None:
|
|
|
|
|
Token(type='inline', tag='', nesting=0, attrs={}, map=[0, 1], level=1,
|
|
|
|
|
content='[ [a]{#bar} ]{#foo}', markup='', info='', meta={}, block=True, hidden=False,
|
|
|
|
|
children=[
|
|
|
|
|
Token(type='inline_anchor', tag='', nesting=0, attrs={'id': 'foo'}, map=None, level=0,
|
|
|
|
|
Token(type='attr_span_begin', tag='span', nesting=1, attrs={'id': 'foo'}, map=None, level=0,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=1, children=None,
|
|
|
|
|
content=' ', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='inline_anchor', tag='', nesting=0, attrs={'id': 'bar'}, map=None, level=0,
|
|
|
|
|
Token(type='attr_span_begin', tag='span', nesting=1, attrs={'id': 'bar'}, map=None, level=1,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
content='a ', markup='', info='', meta={}, block=False, hidden=False)
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=2, children=None,
|
|
|
|
|
content='a', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='attr_span_end', tag='span', nesting=-1, attrs={}, map=None, level=1,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=1, children=None,
|
|
|
|
|
content=' ', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='attr_span_end', tag='span', nesting=-1, attrs={}, map=None, level=0,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=False, hidden=False)
|
|
|
|
|
]),
|
|
|
|
|
Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
content='', markup='', info='', meta={}, block=True, hidden=False)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
def test_inline_anchor_escaping() -> None:
|
|
|
|
|
def test_attr_span_escaping() -> None:
|
|
|
|
|
c = Converter({})
|
|
|
|
|
assert c._parse("\\[a]{#bar}") == [
|
|
|
|
|
Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[0, 1], level=0, children=None,
|
|
|
|
@@ -149,10 +218,12 @@ def test_inline_anchor_escaping() -> None:
|
|
|
|
|
children=[
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
content='\\', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='inline_anchor', tag='', nesting=0, attrs={'id': 'bar'}, map=None, level=0,
|
|
|
|
|
Token(type='attr_span_begin', tag='span', nesting=1, attrs={'id': 'bar'}, map=None, level=0,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
content='a', markup='', info='', meta={}, block=False, hidden=False)
|
|
|
|
|
Token(type='text', tag='', nesting=0, attrs={}, map=None, level=1, children=None,
|
|
|
|
|
content='a', markup='', info='', meta={}, block=False, hidden=False),
|
|
|
|
|
Token(type='attr_span_end', tag='span', nesting=-1, attrs={}, map=None, level=0,
|
|
|
|
|
children=None, content='', markup='', info='', meta={}, block=False, hidden=False)
|
|
|
|
|
]),
|
|
|
|
|
Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=0, children=None,
|
|
|
|
|
content='', markup='', info='', meta={}, block=True, hidden=False)
|
|
|
|
|