nixos-render-docs: move list-is-compact attr to meta
Token.attr is a dict[str, str | int | float], meta has no restriction on the value type. attrs is ostensibly meant for html attributes, meta for any information whatsoever.
This commit is contained in:
@@ -103,7 +103,7 @@ class DocBookRenderer(Renderer):
|
||||
# HACK open and close para for docbook change size. remove soon.
|
||||
def bullet_list_open(self, token: Token, tokens: Sequence[Token], i: int, options: OptionsDict,
|
||||
env: MutableMapping[str, Any]) -> str:
|
||||
spacing = ' spacing="compact"' if token.attrs.get('compact', False) else ''
|
||||
spacing = ' spacing="compact"' if token.meta.get('compact', False) else ''
|
||||
return f"<para><itemizedlist{spacing}>\n"
|
||||
def bullet_list_close(self, token: Token, tokens: Sequence[Token], i: int, options: OptionsDict,
|
||||
env: MutableMapping[str, Any]) -> str:
|
||||
@@ -218,7 +218,7 @@ class DocBookRenderer(Renderer):
|
||||
def ordered_list_open(self, token: Token, tokens: Sequence[Token], i: int, options: OptionsDict,
|
||||
env: MutableMapping[str, Any]) -> str:
|
||||
start = f' startingnumber="{token.attrs["start"]}"' if 'start' in token.attrs else ""
|
||||
spacing = ' spacing="compact"' if token.attrs.get('compact', False) else ''
|
||||
spacing = ' spacing="compact"' if token.meta.get('compact', False) else ''
|
||||
return f"<orderedlist{start}{spacing}>"
|
||||
def ordered_list_close(self, token: Token, tokens: Sequence[Token], i: int, options: OptionsDict,
|
||||
env: MutableMapping[str, Any]) -> str:
|
||||
|
||||
@@ -376,7 +376,7 @@ class Converter(ABC):
|
||||
end_stack.append([i, cast(int, tokens[i].attrs.get('start', 1))])
|
||||
elif tokens[i].type in [ 'bullet_list_close', 'ordered_list_close' ]:
|
||||
(idx, compact) = wide_stack.pop()
|
||||
tokens[idx].attrs['compact'] = compact
|
||||
tokens[idx].meta['compact'] = compact
|
||||
(idx, end) = end_stack.pop()
|
||||
if tokens[i].type == 'ordered_list_close':
|
||||
tokens[idx].meta['end'] = end - 1
|
||||
|
||||
@@ -166,11 +166,11 @@ class OptionsDocBookRenderer(DocBookRenderer):
|
||||
# TODO keep optionsDocBook diff small. remove soon if rendering is still good.
|
||||
def ordered_list_open(self, token: Token, tokens: Sequence[Token], i: int, options: OptionsDict,
|
||||
env: MutableMapping[str, Any]) -> str:
|
||||
token.attrs['compact'] = False
|
||||
token.meta['compact'] = False
|
||||
return super().ordered_list_open(token, tokens, i, options, env)
|
||||
def bullet_list_open(self, token: Token, tokens: Sequence[Token], i: int, options: OptionsDict,
|
||||
env: MutableMapping[str, Any]) -> str:
|
||||
token.attrs['compact'] = False
|
||||
token.meta['compact'] = False
|
||||
return super().bullet_list_open(token, tokens, i, options, env)
|
||||
|
||||
class DocBookConverter(BaseConverter):
|
||||
|
||||
@@ -14,8 +14,9 @@ def test_list_wide(ordered: bool) -> None:
|
||||
)
|
||||
c = Converter({})
|
||||
meta = { 'end': int(e2[:-1]) } if ordered else {}
|
||||
meta['compact'] = False
|
||||
assert c._parse(f"{e1} a\n\n{e2} b") == [
|
||||
Token(type=f'{t}_list_open', tag=tag, nesting=1, attrs={'compact': False}, map=[0, 3], level=0,
|
||||
Token(type=f'{t}_list_open', tag=tag, nesting=1, attrs={}, map=[0, 3], level=0,
|
||||
children=None, content='', markup=m, info='', meta=meta, block=True, hidden=False),
|
||||
Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[0, 2], level=1, children=None,
|
||||
content='', markup=m, info=i1, meta={}, block=True, hidden=False),
|
||||
@@ -56,8 +57,9 @@ def test_list_narrow(ordered: bool) -> None:
|
||||
)
|
||||
c = Converter({})
|
||||
meta = { 'end': int(e2[:-1]) } if ordered else {}
|
||||
meta['compact'] = True
|
||||
assert c._parse(f"{e1} a\n{e2} b") == [
|
||||
Token(type=f'{t}_list_open', tag=tag, nesting=1, attrs={'compact': True}, map=[0, 2], level=0,
|
||||
Token(type=f'{t}_list_open', tag=tag, nesting=1, attrs={}, map=[0, 2], level=0,
|
||||
children=None, content='', markup=m, info='', meta=meta, block=True, hidden=False),
|
||||
Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[0, 1], level=1, children=None,
|
||||
content='', markup=m, info=i1, meta={}, block=True, hidden=False),
|
||||
@@ -91,12 +93,12 @@ def test_list_narrow(ordered: bool) -> None:
|
||||
content='', markup=m, info='', meta={}, block=True, hidden=False)
|
||||
]
|
||||
assert c._parse(f"{e1} - a\n{e2} b") == [
|
||||
Token(type=f'{t}_list_open', tag=tag, nesting=1, attrs={'compact': True}, map=[0, 2], level=0,
|
||||
Token(type=f'{t}_list_open', tag=tag, nesting=1, attrs={}, map=[0, 2], level=0,
|
||||
children=None, content='', markup=m, info='', meta=meta, block=True, hidden=False),
|
||||
Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[0, 1], level=1, children=None,
|
||||
content='', markup=m, info=i1, meta={}, block=True, hidden=False),
|
||||
Token(type='bullet_list_open', tag='ul', nesting=1, attrs={'compact': True}, map=[0, 1], level=2,
|
||||
children=None, content='', markup='-', info='', meta={}, block=True, hidden=False),
|
||||
Token(type='bullet_list_open', tag='ul', nesting=1, attrs={}, map=[0, 1], level=2,
|
||||
children=None, content='', markup='-', info='', meta={'compact': True}, block=True, hidden=False),
|
||||
Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[0, 1], level=3, children=None,
|
||||
content='', markup='-', info='', meta={}, block=True, hidden=False),
|
||||
Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[0, 1], level=4, children=None,
|
||||
@@ -133,12 +135,12 @@ def test_list_narrow(ordered: bool) -> None:
|
||||
content='', markup=m, info='', meta={}, block=True, hidden=False)
|
||||
]
|
||||
assert c._parse(f"{e1} - a\n{e2} - b") == [
|
||||
Token(type=f'{t}_list_open', tag=tag, nesting=1, attrs={'compact': True}, map=[0, 2], level=0,
|
||||
Token(type=f'{t}_list_open', tag=tag, nesting=1, attrs={}, map=[0, 2], level=0,
|
||||
children=None, content='', markup=m, info='', meta=meta, block=True, hidden=False),
|
||||
Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[0, 1], level=1, children=None,
|
||||
content='', markup=m, info=i1, meta={}, block=True, hidden=False),
|
||||
Token(type='bullet_list_open', tag='ul', nesting=1, attrs={'compact': True}, map=[0, 1], level=2,
|
||||
children=None, content='', markup='-', info='', meta={}, block=True, hidden=False),
|
||||
Token(type='bullet_list_open', tag='ul', nesting=1, attrs={}, map=[0, 1], level=2,
|
||||
children=None, content='', markup='-', info='', meta={'compact': True}, block=True, hidden=False),
|
||||
Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[0, 1], level=3, children=None,
|
||||
content='', markup='-', info='', meta={}, block=True, hidden=False),
|
||||
Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[0, 1], level=4, children=None,
|
||||
@@ -159,8 +161,8 @@ def test_list_narrow(ordered: bool) -> None:
|
||||
content='', markup=m, info='', meta={}, block=True, hidden=False),
|
||||
Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[1, 2], level=1, children=None,
|
||||
content='', markup=m, info=i2, meta={}, block=True, hidden=False),
|
||||
Token(type='bullet_list_open', tag='ul', nesting=1, attrs={'compact': True}, map=[1, 2], level=2,
|
||||
children=None, content='', markup='-', info='', meta={}, block=True, hidden=False),
|
||||
Token(type='bullet_list_open', tag='ul', nesting=1, attrs={}, map=[1, 2], level=2,
|
||||
children=None, content='', markup='-', info='', meta={'compact': True}, block=True, hidden=False),
|
||||
Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[1, 2], level=3, children=None,
|
||||
content='', markup='-', info='', meta={}, block=True, hidden=False),
|
||||
Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[1, 2], level=4, children=None,
|
||||
|
||||
Reference in New Issue
Block a user