File tree 5 files changed +71
-5
lines changed
5 files changed +71
-5
lines changed Original file line number Diff line number Diff line change 49
49
50
50
from myst_parser .warnings_ import MystWarnings
51
51
52
- from .options import TokenizeError
53
- from .options import to_items as options_to_items
52
+ from .options import TokenizeError , options_to_items
54
53
55
54
56
55
@dataclass
Original file line number Diff line number Diff line change @@ -168,7 +168,7 @@ class State:
168
168
has_comments : bool = False
169
169
170
170
171
- def to_items (
171
+ def options_to_items (
172
172
text : str , line_offset : int = 0 , column_offset : int = 0
173
173
) -> tuple [list [tuple [str , str ]], State ]:
174
174
"""Parse a directive option block into (key, value) tuples.
@@ -211,6 +211,8 @@ def _to_tokens(
211
211
raise TokenizeError ("expected key before value" , token .start )
212
212
yield key_token , token
213
213
key_token = None
214
+ if key_token is not None :
215
+ yield key_token , None
214
216
except TokenizeError as exc :
215
217
if line_offset or column_offset :
216
218
raise exc .clone (line_offset , column_offset ) from exc
Original file line number Diff line number Diff line change @@ -257,3 +257,47 @@ error: missing argument
257
257
.
258
258
error: 1 argument(s) required, 0 supplied
259
259
.
260
+
261
+ option_flags_std
262
+ .
263
+ ```{code-block}
264
+ :linenos:
265
+ :lineno-start: 2
266
+ :force:
267
+
268
+ body
269
+ ```
270
+ .
271
+ arguments: []
272
+ body:
273
+ - body
274
+ content_offset: 4
275
+ options:
276
+ force: null
277
+ lineno-start: 2
278
+ linenos: null
279
+ warnings: []
280
+ .
281
+
282
+ option_flags_delimited
283
+ .
284
+ ```{code-block}
285
+ ---
286
+ linenos:
287
+ lineno-start: 2
288
+ force:
289
+ ---
290
+
291
+ body
292
+ ```
293
+ .
294
+ arguments: []
295
+ body:
296
+ - body
297
+ content_offset: 6
298
+ options:
299
+ force: null
300
+ lineno-start: 2
301
+ linenos: null
302
+ warnings: []
303
+ .
Original file line number Diff line number Diff line change @@ -182,3 +182,22 @@ folded values:
182
182
],
183
183
"comments": false
184
184
}
185
+
186
+ empty_final_value :
187
+ content : |-
188
+ key1: val1
189
+ key2:
190
+ expected : |-
191
+ {
192
+ "dict": [
193
+ [
194
+ "key1",
195
+ "val1"
196
+ ],
197
+ [
198
+ "key2",
199
+ ""
200
+ ]
201
+ ],
202
+ "comments": false
203
+ }
Original file line number Diff line number Diff line change 6
6
from docutils .parsers .rst .directives .admonitions import Admonition , Note
7
7
from docutils .parsers .rst .directives .body import Rubric
8
8
from markdown_it import MarkdownIt
9
+ from sphinx .directives .code import CodeBlock
9
10
10
11
from myst_parser .parsers .directives import MarkupError , parse_directive_text
11
- from myst_parser .parsers .options import TokenizeError
12
- from myst_parser .parsers .options import to_items as options_to_items
12
+ from myst_parser .parsers .options import TokenizeError , options_to_items
13
13
14
14
FIXTURE_PATH = Path (__file__ ).parent .joinpath ("fixtures" )
15
15
@@ -50,6 +50,8 @@ def test_parsing(file_params):
50
50
klass = Note
51
51
elif name == "{admonition}" :
52
52
klass = Admonition
53
+ elif name == "{code-block}" :
54
+ klass = CodeBlock
53
55
else :
54
56
raise AssertionError (f"Unknown directive: { name } " )
55
57
try :
You can’t perform that action at this time.
0 commit comments