Skip to content

Commit 30d3366

Browse files
committed
Add 'options' to more directives
1 parent 4691b2f commit 30d3366

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

snooty/parser.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,18 @@ def handle_directive(self, node: docutils.nodes.Node, doc: Dict[str, Serializabl
130130
name = node['name']
131131
doc['name'] = name
132132

133+
options = node['options'] or {}
134+
if options:
135+
doc['options'] = options
136+
133137
if node.children and node.children[0].__class__.__name__ == 'directive_argument':
134138
visitor = self.__make_child_visitor()
135139
node.children[0].walkabout(visitor)
136140
argument = visitor.state[-1]['children']
137141
doc['argument'] = argument
138-
options = node['options']
139-
doc['options'] = options
140142
node.children = node.children[1:]
141143
else:
142144
argument = []
143-
options = {}
144145
doc['argument'] = argument
145146

146147
argument_text = None

snooty/test_parser.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ def test_tabs() -> None:
1515
assert ast_to_testing_string(page.ast) == ''.join((
1616
'<root>',
1717

18-
'<directive name="tabs"><directive name="tab"><text>bionic</text>',
18+
'<directive name="tabs" hidden="True"><directive name="tab"><text>bionic</text>',
1919
'<paragraph><text>Bionic content</text></paragraph></directive>',
20-
2120
'<directive name="tab"><text>xenial</text><paragraph><text>',
2221
'Xenial content</text></paragraph></directive>',
23-
2422
'<directive name="tab"><text>trusty</text><paragraph><text>',
2523
'Trusty content</text></paragraph></directive></directive>',
2624

27-
'<directive name="tabs"><directive name="tab"><text>trusty</text><paragraph><text>',
25+
'<directive name="tabs" tabset="platforms"><directive name="tab"><text>windows</text>',
26+
'<paragraph><text>Windows content</text></paragraph></directive></directive>',
27+
28+
'<directive name="tabs" hidden="true"><directive name="tab">',
29+
'<text>trusty</text><paragraph><text>',
2830
'Trusty content</text></paragraph></directive>',
2931

3032
'<directive name="tab"><text>xenial</text><paragraph><text>',
@@ -35,7 +37,7 @@ def test_tabs() -> None:
3537

3638
assert len(diagnostics) == 1 and \
3739
diagnostics[0].message.startswith('Unexpected field') and \
38-
diagnostics[0].start[0] == 36
40+
diagnostics[0].start[0] == 44
3941

4042

4143
def test_codeblock() -> None:

snooty/util.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ def line_of_node(node: docutils.nodes.Node) -> Optional[int]:
5151
def ast_to_testing_string(ast: Any) -> str:
5252
value = ast.get('value', '')
5353
children = ast.get('children', [])
54+
attr_pairs = [(k, v) for k, v in ast.items() if k not in (
55+
'argument', 'value', 'children', 'type', 'position', 'options') and v]
56+
attr_pairs.extend((k, v) for k, v in ast.get('options', {}).items())
5457
attrs = ' '.join(
55-
'{}="{}"'.format(k, v) for k, v in ast.items() if k not in (
56-
'argument', 'value', 'children', 'type', 'position') and v)
58+
'{}="{}"'.format(k, v) for k, v in attr_pairs)
5759
contents = value if value else (''.join(
5860
ast_to_testing_string(child) for child in children)
5961
if children else '')

test_data/test_tabs.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020

2121
Trusty content
2222

23+
.. tabs-platforms::
24+
25+
tabs:
26+
- id: windows
27+
content: |
28+
29+
Windows content
30+
2331
.. tabs::
2432
:hidden: true
2533

0 commit comments

Comments
 (0)