Skip to content

Commit 6ad7056

Browse files
carooobregoni80and
authored andcommitted
DOP-2319 - Add new quiz directives to snooty-parser (#333)
* DOP-2319 Add new quiz directives to snooty-parser
1 parent c2169cd commit 6ad7056

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

snooty/rstspec.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,26 @@ example = """.. procedure::
707707
${0: Steps content}"""
708708
content_type = "block"
709709

710+
[directive."mongodb:quiz"]
711+
content_type = "block"
712+
help = "Embed a quiz with a question argument, using the quizchoice directive to construct answer options."
713+
example = """.. quiz::
714+
:quiz-id: ${1:string}
715+
716+
${2:string}"""
717+
argument_type = "string"
718+
options.quiz-id = {type = "string", required = true}
719+
720+
[directive."mongodb:quizchoice"]
721+
content_type = "block"
722+
help = "A possible quiz answer and an explanation to be displayed after submission"
723+
example = """ .. quizchoice:: ${1:string}
724+
:is-true:
725+
726+
${3:string}"""
727+
argument_type = "string"
728+
options.is-true = "flag"
729+
710730
[directive."mongodb:step"]
711731
help = "Make a single, numbered step."
712732
example = """.. step:: ${0: Step's headline string}

snooty/test_parser.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,34 @@
2929
# does NOT include postprocessing artifacts such as nonlocal link titles and intersphinx lookups.
3030

3131

32+
def test_quiz() -> None:
33+
tabs_path = ROOT_PATH.joinpath(Path("test_quiz.rst"))
34+
project_config = ProjectConfig(ROOT_PATH, "", source="./")
35+
parser = rstparser.Parser(project_config, JSONVisitor)
36+
page, diagnostics = parse_rst(parser, tabs_path, None)
37+
page.finish(diagnostics)
38+
check_ast_testing_string(
39+
page.ast,
40+
"""<root fileid="test_quiz.rst">
41+
<directive name="quiz" domain="mongodb" quiz-id="mongoacc1">
42+
<paragraph><text>With my MongoDB account, I can now access?</text></paragraph>
43+
<directive name="quizchoice" domain="mongodb">
44+
<text>MongoDB Atlas</text>
45+
<paragraph><text>Up to 2 lines of copy here explaining why MongoDB Atlas isn’t the right answer choice</text></paragraph>
46+
</directive>
47+
<directive name="quizchoice" domain="mongodb">
48+
<text>MongoDB University</text>
49+
<paragraph><text>Up to 2 lines of copy here explaining why MongoDB University isn’t the right answer choice</text></paragraph>
50+
</directive>
51+
<directive name="quizchoice" domain="mongodb" is-true="True">
52+
<text>All of the Above</text>
53+
<paragraph><text>Your MongoDB account gives you access to all of the above: Atlas, University, Cloud Manager, etc.</text></paragraph>
54+
</directive>
55+
</directive>
56+
</root>""",
57+
)
58+
59+
3260
def test_tabs() -> None:
3361
tabs_path = ROOT_PATH.joinpath(Path("test_tabs.rst"))
3462
project_config = ProjectConfig(ROOT_PATH, "", source="./")

test_data/test_quiz.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.. quiz::
2+
:quiz-id: mongoacc1
3+
4+
With my MongoDB account, I can now access?
5+
6+
.. quizchoice:: MongoDB Atlas
7+
8+
Up to 2 lines of copy here explaining why MongoDB Atlas isn’t the right answer choice
9+
10+
.. quizchoice:: MongoDB University
11+
12+
Up to 2 lines of copy here explaining why MongoDB University isn’t the right answer choice
13+
14+
.. quizchoice:: All of the Above
15+
:is-true:
16+
17+
Your MongoDB account gives you access to all of the above: Atlas, University, Cloud Manager, etc.

0 commit comments

Comments
 (0)