11diff --git a/asciinema.py b/asciinema.py
2- index 8644220..44dad26 100644
2+ index 8644220..0b73d80 100644
33--- a/asciinema.py
44+++ b/asciinema.py
55@@ -2,20 +2,20 @@ import os
@@ -29,39 +29,17 @@ index 8644220..44dad26 100644
2929
3030
3131 class Asciinema(nodes.General, nodes.Element):
32- @@ -24,22 +24,37 @@ class Asciinema(nodes.General, nodes.Element):
33-
34- def visit_html(self, node):
35- rst_to_js_option_names: dict[str, str] = {
36- + "autoplay": "autoPlay",
37- + "idle-time-limit": "idleTimeLimit",
38- "terminalfontsize": "terminalFontSize",
39- - "terminallineheigth": "terminalLineHeigth",
40- + "terminallineheight": "terminalLineHeight",
41- "terminalfontfamily": "terminalFontFamily",
32+ @@ -30,16 +30,17 @@ def visit_html(self, node):
4233 "audiourl": "audioUrl",
4334 }
4435
4536- options_raw = ['markers']
46- -
37+ + options_raw = ["markers"]
38+
4739- gen = ((rst_option_name, js_option_name)
4840- for (rst_option_name,
4941- js_option_name) in rst_to_js_option_names.items()
5042- if rst_option_name in node["options"])
51- + options_raw = [
52- + "markers",
53- + "loop",
54- + "autoPlay",
55- + "preload",
56- + "pauseOnMarkers",
57- + "cols",
58- + "rows",
59- + "speed",
60- + ]
61- +
62- + for option, value in node["options"].items():
63- + node["options"][option] = ASCIINemaDirective.option_spec[option](value)
64- +
6543+ gen = (
6644+ (rst_option_name, js_option_name)
6745+ for (rst_option_name, js_option_name) in rst_to_js_option_names.items()
@@ -75,7 +53,7 @@ index 8644220..44dad26 100644
7553 template = """<div id="asciicast-{id}"></div>
7654 <script>
7755 document.addEventListener("DOMContentLoaded", function() {{
78- @@ -50,7 +65 ,7 @@ def visit_html(self, node):
56+ @@ -50,7 +51 ,7 @@ def visit_html(self, node):
7957 }});
8058 </script>"""
8159 option_template = '{}: "{}", '
@@ -84,7 +62,7 @@ index 8644220..44dad26 100644
8462 else:
8563 template = """<script async id="asciicast-{src}" {options}
8664 src="https://asciinema.org/a/{src}.js"></script>"""
87- @@ -58,14 +73 ,17 @@ def visit_html(self, node):
65+ @@ -58,14 +59 ,17 @@ def visit_html(self, node):
8866 option_template_raw = 'data-{}="{}" '
8967 options = ""
9068 for n, v in node["options"].items():
@@ -105,55 +83,7 @@ index 8644220..44dad26 100644
10583 raise nodes.SkipNode
10684
10785
108- @@ -73,15 +91,35 @@ def depart(self, node):
109- pass
110-
111-
112- + def bool_parse(argument):
113- + """Parse the option as boolean."""
114- + if argument is None:
115- + raise ValueError("Boolean option must have a value")
116- +
117- + val = str(argument).strip().lower()
118- +
119- + if val in ("true", "false"):
120- + return val
121- + raise ValueError("Must be boolean; True or False")
122- +
123- +
124- + def bool_or_positive_int(argument):
125- + """Parse the option as boolean or positive integer."""
126- + try:
127- + return bool_parse(argument)
128- + except ValueError:
129- + return directives.positive_int(argument)
130- +
131- +
132- class ASCIINemaDirective(SphinxDirective):
133- has_content = True
134- final_argument_whitespace = False
135- option_spec = {
136- "cols": directives.positive_int,
137- "rows": directives.positive_int,
138- - "autoplay": directives.unchanged,
139- - "preload": directives.unchanged,
140- - "loop": directives.unchanged,
141- + "autoplay": bool_parse,
142- + "preload": bool_parse,
143- + "loop": bool_or_positive_int,
144- "start-at": directives.unchanged,
145- "speed": directives.unchanged,
146- "idle-time-limit": directives.unchanged,
147- @@ -90,7 +128,7 @@ class ASCIINemaDirective(SphinxDirective):
148- "fit": directives.unchanged,
149- "controls": directives.unchanged,
150- "markers": directives.unchanged,
151- - "pauseOnMarkers": directives.unchanged,
152- + "pauseOnMarkers": bool_parse,
153- "terminalfontsize": directives.unchanged,
154- "terminalfontfamily": directives.unchanged,
155- "terminallineheight": directives.unchanged,
156- @@ -102,25 +140,25 @@ class ASCIINemaDirective(SphinxDirective):
86+ @@ -102,25 +106,25 @@ class ASCIINemaDirective(SphinxDirective):
15787
15888 def run(self):
15989 arg = self.arguments[0]
@@ -195,7 +125,7 @@ index 8644220..44dad26 100644
195125 return [Asciinema(**kw)]
196126
197127 def is_file(self, rel_file):
198- @@ -129,17 +167 ,18 @@ class ASCIINemaDirective(SphinxDirective):
128+ @@ -129,17 +133 ,18 @@ class ASCIINemaDirective(SphinxDirective):
199129
200130 def to_b64(self, filename):
201131 import base64
0 commit comments