Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ A plane through the point $P$.

## Parameters for an applet

Some parameters can be set for an applet. Only the `url`, `fig` and `name` parameters are required; the rest is optional. It is recommended to add a `status` to the applet, which can be `unreviewed`, `in-review` or `reviewed`.
Some parameters can be set for an applet. Only the `url` and `name` parameters are required; the rest is optional. It is recommended to add a `status` to the applet, which can be `unreviewed`, `in-review` or `reviewed`.

````md
```{applet}
Expand All @@ -76,11 +76,15 @@ A title that describes the applet

| Parameter | Description | Default |
| ----------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | ------------ |
| `fig` | The path to an image that will be shown in the print version of the document | None |
| `title` | A string that will be shown as the title of the applet when the applet is in fullscreen mode | "" |
| `status` | The status of the applet. Can be `unreviewed`, `in-review` or `reviewed` | `unreviewed` |
| `width` | The width of the applet in pixels | 100% |
| `height` | The height of the applet in pixels | 400px |

> [!NOTE]
> If the `fig` parameter is not defined, the code will insert the image provided by the applet itself as a fallback.

### Control parameters

> [!WARNING]
Expand Down
22 changes: 20 additions & 2 deletions src/sphinx_prime_applets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ def run(self):
fig = self.options.get("fig")

assert url is not None
assert fig is not None

if "?" in url:
url, url_params = url.split("?", 1)
else:
url_params = ""
if fig is None:
fig = DEFAULT_BASE_URL + url + "/image.png"

iframe_class = self.options.get("class") # expect a list/string of classes

if iframe_class is None:
Expand All @@ -86,10 +91,23 @@ def run(self):
(figure_node,) = Figure.run(self)

# Generate GET params and inline styling
# we do not perform validation or sanitization
params_dict = parse_options(self.options)
params_dict["iframe"] = (
"true" # To let the applet know its being run in an iframe
)
if url_params != "":
for param in url_params.split("&"):
if "=" in param:
key, value = param.split("=", 1)
params_dict[key] = value
else:
params_dict[param] = "true"
# overwrite language based on document language
lang = self.state.document.settings.env.config.language
if lang is None:
lang = "en"
params_dict["lang"] = lang # language is always overwritten
params = "&".join(
[f"{key}={quote(value)}" for key, value in params_dict.items()]
)
Expand Down