Skip to content

Commit 551a587

Browse files
authored
Fix search params (#109)
* Fix the default value when there is no search parameters option * Fix the starting slash in the iframeUrl * Fix search params not set * Do not use the baseURL to generate the iframeSrc, to avoid error if iframeSrc start with '../' * Avoid duplicating the parameters
1 parent 58ea921 commit 551a587

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

jupyterlite_sphinx/jupyterlite_sphinx.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,9 @@ window.jupyterliteConcatSearchParams = (iframeSrc, params) => {
3333
}
3434
});
3535

36-
return iframeUrl.toString().replace(baseURL, '');
36+
if (iframeUrl.searchParams.size) {
37+
return `${iframeSrc.split('?')[0]}?${iframeUrl.searchParams.toString()}`;
38+
} else {
39+
return iframeSrc;
40+
}
3741
}

jupyterlite_sphinx/jupyterlite_sphinx.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(
5252
height="100%",
5353
prompt=False,
5454
prompt_color=None,
55-
search_params=[],
55+
search_params="false",
5656
**attributes,
5757
):
5858
super().__init__(
@@ -221,7 +221,7 @@ def run(self):
221221
prompt = self.options.pop("prompt", False)
222222
prompt_color = self.options.pop("prompt_color", None)
223223

224-
search_params = search_params_parser(self.options.pop("search_params", ""))
224+
search_params = search_params_parser(self.options.pop("search_params", False))
225225

226226
prefix = os.path.relpath(
227227
os.path.join(self.env.app.srcdir, JUPYTERLITE_DIR),
@@ -262,7 +262,7 @@ def run(self):
262262
prompt = self.options.pop("prompt", False)
263263
prompt_color = self.options.pop("prompt_color", None)
264264

265-
search_params = search_params_parser(self.options.pop("search_params", ""))
265+
search_params = search_params_parser(self.options.pop("search_params", False))
266266

267267
source_location = os.path.dirname(self.get_source_info()[0])
268268

@@ -504,7 +504,7 @@ def setup(app):
504504
def search_params_parser(search_params: str) -> str:
505505
pattern = re.compile(r"^\[(?:\s*[\"']{1}([^=\s\,&=\?\/]+)[\"']{1}\s*\,?)+\]$")
506506
if not search_params:
507-
return ""
507+
return "false"
508508
if search_params in ["True", "False"]:
509509
return search_params.lower()
510510
elif pattern.match(search_params):

0 commit comments

Comments
 (0)