diff options
author | pennae <github@quasiparticle.net> | 2023-02-07 07:14:12 +0100 |
---|---|---|
committer | pennae <82953136+pennae@users.noreply.github.com> | 2023-02-08 15:23:34 +0100 |
commit | b2a5b4d7899138eb9cc8af31fc1f296af582a4ce (patch) | |
tree | 68818aed7619cc166ec631b8d2a42849bfabe2f1 | |
parent | 09411102f60e241a65d5ce708d369fdfcad3e977 (diff) |
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.
4 files changed, 17 insertions, 15 deletions
diff --git a/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/docbook.py b/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/docbook.py index bad36e57a2f32..28c4425d8c080 100644 --- a/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/docbook.py +++ b/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/docbook.py @@ -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: diff --git a/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/md.py b/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/md.py index 104a43d9edfd5..16e473e97adeb 100644 --- a/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/md.py +++ b/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/md.py @@ -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 diff --git a/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/options.py b/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/options.py index 8550dc26809d5..68c753507e99d 100644 --- a/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/options.py +++ b/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/options.py @@ -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): diff --git a/pkgs/tools/nix/nixos-render-docs/src/tests/test_lists.py b/pkgs/tools/nix/nixos-render-docs/src/tests/test_lists.py index af284c9d3abeb..660c410a85cca 100644 --- a/pkgs/tools/nix/nixos-render-docs/src/tests/test_lists.py +++ b/pkgs/tools/nix/nixos-render-docs/src/tests/test_lists.py @@ -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, |