Skip to content

Commit 0f20bce

Browse files
committed
Use multiple patches for sphinxcontrib.asciinema
1 parent f99ed2e commit 0f20bce

4 files changed

Lines changed: 98 additions & 82 deletions

File tree

dfetch.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ manifest:
2020
repo-path: divi255/sphinxcontrib.asciinema.git
2121
dst: doc/_ext/sphinxcontrib_asciinema
2222
src: sphinxcontrib/asciinema
23-
patch: doc/_ext/sphinxcontrib_asciinema.patch
23+
patch:
24+
- doc/_ext/patches/001-autoformat-sphinxcontrib.asciinema.patch
25+
- doc/_ext/patches/002-fix-options-sphinxcontrib.asciinema.patch

doc/_ext/sphinxcontrib_asciinema.patch renamed to doc/_ext/patches/001-autoformat-sphinxcontrib.asciinema.patch

Lines changed: 8 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --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
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
diff --git a/asciinema.py b/asciinema.py
2+
index 0b73d80..44dad26 100644
3+
--- a/asciinema.py
4+
+++ b/asciinema.py
5+
@@ -24,13 +24,27 @@ class Asciinema(nodes.General, nodes.Element):
6+
7+
def visit_html(self, node):
8+
rst_to_js_option_names: dict[str, str] = {
9+
+ "autoplay": "autoPlay",
10+
+ "idle-time-limit": "idleTimeLimit",
11+
"terminalfontsize": "terminalFontSize",
12+
- "terminallineheigth": "terminalLineHeigth",
13+
+ "terminallineheight": "terminalLineHeight",
14+
"terminalfontfamily": "terminalFontFamily",
15+
"audiourl": "audioUrl",
16+
}
17+
18+
- options_raw = ["markers"]
19+
+ options_raw = [
20+
+ "markers",
21+
+ "loop",
22+
+ "autoPlay",
23+
+ "preload",
24+
+ "pauseOnMarkers",
25+
+ "cols",
26+
+ "rows",
27+
+ "speed",
28+
+ ]
29+
+
30+
+ for option, value in node["options"].items():
31+
+ node["options"][option] = ASCIINemaDirective.option_spec[option](value)
32+
33+
gen = (
34+
(rst_option_name, js_option_name)
35+
@@ -77,15 +91,35 @@ def depart(self, node):
36+
pass
37+
38+
39+
+def bool_parse(argument):
40+
+ """Parse the option as boolean."""
41+
+ if argument is None:
42+
+ raise ValueError("Boolean option must have a value")
43+
+
44+
+ val = str(argument).strip().lower()
45+
+
46+
+ if val in ("true", "false"):
47+
+ return val
48+
+ raise ValueError("Must be boolean; True or False")
49+
+
50+
+
51+
+def bool_or_positive_int(argument):
52+
+ """Parse the option as boolean or positive integer."""
53+
+ try:
54+
+ return bool_parse(argument)
55+
+ except ValueError:
56+
+ return directives.positive_int(argument)
57+
+
58+
+
59+
class ASCIINemaDirective(SphinxDirective):
60+
has_content = True
61+
final_argument_whitespace = False
62+
option_spec = {
63+
"cols": directives.positive_int,
64+
"rows": directives.positive_int,
65+
- "autoplay": directives.unchanged,
66+
- "preload": directives.unchanged,
67+
- "loop": directives.unchanged,
68+
+ "autoplay": bool_parse,
69+
+ "preload": bool_parse,
70+
+ "loop": bool_or_positive_int,
71+
"start-at": directives.unchanged,
72+
"speed": directives.unchanged,
73+
"idle-time-limit": directives.unchanged,
74+
@@ -94,7 +128,7 @@ class ASCIINemaDirective(SphinxDirective):
75+
"fit": directives.unchanged,
76+
"controls": directives.unchanged,
77+
"markers": directives.unchanged,
78+
- "pauseOnMarkers": directives.unchanged,
79+
+ "pauseOnMarkers": bool_parse,
80+
"terminalfontsize": directives.unchanged,
81+
"terminalfontfamily": directives.unchanged,
82+
"terminallineheight": directives.unchanged,

doc/_ext/sphinxcontrib_asciinema/.dfetch_data.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
# For more info see https://dfetch.rtfd.io/en/latest/getting_started.html
33
dfetch:
44
branch: master
5-
hash: c26afa0279fa96392fd7f46d516060a4
6-
last_fetch: 21/12/2025, 13:39:42
7-
patch: doc/_ext/sphinxcontrib_asciinema.patch
5+
hash: dcd1473e1a3ca613b804e3e51e7ee342
6+
last_fetch: 07/01/2026, 21:38:48
7+
patch:
8+
- doc/_ext/patches/001-autoformat-sphinxcontrib.asciinema.patch
9+
- doc/_ext/patches/002-fix-options-sphinxcontrib.asciinema.patch
810
remote_url: https://github.com/divi255/sphinxcontrib.asciinema.git
911
revision: 5ee0c5be62236a5dee0032e1d8dd59957a0c1d4c
1012
tag: ''

0 commit comments

Comments
 (0)