diff --git a/docs/use/glue.md b/docs/use/glue.md index 5352d7ce..4a40b826 100644 --- a/docs/use/glue.md +++ b/docs/use/glue.md @@ -232,12 +232,13 @@ For example, the following: ``My rounded mean: {glue:text}`boot_mean:.2f` `` wil ### The `glue:figure` directive With `glue:figure` you can apply more formatting to figure like objects, -such as giving them a caption and referencable label: +such as giving them a caption, referencable label, and alt text: ````md ```{glue:figure} boot_fig :figwidth: 300px :name: "fig-boot" +:alt: "A histogram of the bootstrapped samples." This is a **caption**, with an embedded `{glue:text}` element: {glue:text}`boot_mean:.2f`! ``` @@ -246,6 +247,7 @@ This is a **caption**, with an embedded `{glue:text}` element: {glue:text}`boot_ ```{glue:figure} boot_fig :figwidth: 300px :name: "fig-boot" +:alt: "A histogram of the bootstrapped samples." This is a **caption**, with an embedded `{glue:text}` element: {glue:text}`boot_mean:.2f`! ``` diff --git a/myst_nb/nb_glue/domain.py b/myst_nb/nb_glue/domain.py index df2bec77..440d8a0f 100644 --- a/myst_nb/nb_glue/domain.py +++ b/myst_nb/nb_glue/domain.py @@ -170,12 +170,14 @@ def figwidth_value(argument): option_spec["figclass"] = directives.class_option option_spec["align"] = align option_spec["name"] = directives.unchanged + option_spec["alt"] = directives.unchanged has_content = True def run(self): figwidth = self.options.pop("figwidth", None) figclasses = self.options.pop("figclass", None) align = self.options.pop("align", None) + alt = self.options.pop("alt", None) # On the Paste node we should add an attribute to specify that only image # type mimedata is allowed, then this would be used by # PasteNodesToDocutils -> CellOutputsToNodes to alter the render priority @@ -192,6 +194,8 @@ def run(self): figure_node["classes"] += figclasses if align: figure_node["align"] = align + if alt: + figure_node["alt"] = alt self.add_name(figure_node) # note: this is copied directly from sphinx.Figure if self.content: diff --git a/tests/notebooks/with_glue.ipynb b/tests/notebooks/with_glue.ipynb index c0006fcc..f9e8ea17 100644 --- a/tests/notebooks/with_glue.ipynb +++ b/tests/notebooks/with_glue.ipynb @@ -207,6 +207,7 @@ "\n", "```{glue:figure} key_plt\n", ":name: abc\n", + ":alt: alt-text for glued figure\n", "\n", "A caption....\n", "```", diff --git a/tests/test_glue/test_parser.sphinx3.xml b/tests/test_glue/test_parser.sphinx3.xml index af80e267..71c57914 100644 --- a/tests/test_glue/test_parser.sphinx3.xml +++ b/tests/test_glue/test_parser.sphinx3.xml @@ -139,7 +139,7 @@ undisplayed inline… -
+
diff --git a/tests/test_glue/test_parser.sphinx4.xml b/tests/test_glue/test_parser.sphinx4.xml index eff7afc6..bb173c65 100644 --- a/tests/test_glue/test_parser.sphinx4.xml +++ b/tests/test_glue/test_parser.sphinx4.xml @@ -139,7 +139,7 @@ undisplayed inline… -
+