Skip to content

Commit 1b81e2b

Browse files
committed
Add support for image and tabs-pillstrip; and ignore raw
1 parent 9d61262 commit 1b81e2b

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

snooty/parser.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,18 +211,17 @@ def handle_directive(self, node: docutils.nodes.Node, doc: Dict[str, Serializabl
211211
except (IndexError, KeyError):
212212
pass
213213

214-
if name == 'figure':
214+
if name in {'figure', 'image'}:
215215
if argument_text is None:
216216
self.diagnostics.append(
217-
Diagnostic.error('"figure" expected a path argument', util.get_line(node)))
217+
Diagnostic.error(f'"{name}" expected a path argument', util.get_line(node)))
218218
return
219219

220220
try:
221221
static_asset = self.add_static_asset(Path(argument_text))
222222
options['checksum'] = static_asset.checksum
223223
except OSError as err:
224-
msg = '"figure" could not open "{}": {}'.format(
225-
argument_text, os.strerror(err.errno))
224+
msg = f'"{name}" could not open "{argument_text}": {os.strerror(err.errno)}'
226225
self.diagnostics.append(Diagnostic.error(msg, util.get_line(node)))
227226
elif name == 'literalinclude':
228227
if argument_text is None:

snooty/rstparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def run(self) -> List[docutils.nodes.Node]:
180180
node.append(argument)
181181

182182
# Parse the content
183-
if self.name in {'include', 'only'}:
183+
if self.name in {'include', 'only', 'raw'}:
184184
raw = docutils.nodes.FixedTextElement()
185185
raw.document = self.state.document
186186
raw.source, raw.line = source, line

snooty/rstspec.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ options.width = "length"
9191
options.align = "alignment"
9292
options.lightbox = "flag"
9393

94+
[directive.image]
95+
inherit = "figure"
96+
9497
[directive.example]
9598
help = """A section providing an example related to the surrounding text."""
9699
content_type = "block"
@@ -125,6 +128,10 @@ content_type = "block"
125128
options.titlesonly = "flag"
126129
options.hidden = "flag"
127130

131+
[directive.tabs-pillstrip]
132+
deprecated = true
133+
argument_type = "string"
134+
128135
[directive.tabs]
129136
content_type = "block"
130137
argument_type = "string"

snooty/specparser.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ class LinkRoleType:
7070
None]
7171

7272

73+
class MissingDict(Dict[str, ArgumentType]):
74+
pass
75+
76+
7377
@checked
7478
@dataclass
7579
class Meta:
@@ -88,7 +92,7 @@ class Directive:
8892
argument_type: ArgumentType
8993
required_context: Optional[str]
9094
deprecated: bool = field(default=False)
91-
options: Dict[str, ArgumentType] = field(default_factory=dict)
95+
options: Dict[str, ArgumentType] = field(default_factory=MissingDict)
9296

9397

9498
@checked
@@ -211,9 +215,14 @@ def resolve_value(key: str, inheritable: _T) -> _T:
211215
msg = f'Cannot inherit from non-existent directive {inheritable.inherit}'
212216
raise ValueError(msg)
213217

214-
inheritable = dataclasses.replace(base, **{
215-
k: v for k, v in dataclasses.asdict(inheritable).items() if v is not None
216-
})
218+
inheritable = dataclasses.replace(
219+
base,
220+
**{
221+
k: v
222+
for k, v in dataclasses.asdict(inheritable).items()
223+
if v is not None and not isinstance(v, MissingDict)
224+
},
225+
)
217226
inheritable_index[key] = inheritable
218227
pending.remove(key)
219228

snooty/test_specparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ def test_load() -> None:
1212
1313
[directive._parent]
1414
content_type = "block"
15+
options.foo = ["path", "uri"]
1516
1617
[directive.child]
1718
inherit = "_parent"
1819
argument_type = "user_level"
1920
deprecated = true
20-
options.foo = ["path", "uri"]
2121
2222
[role._parent]
2323
help = "test-role"

0 commit comments

Comments
 (0)