From 2ddb321740355cb9470245f0bc1d8b8515d7a143 Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Wed, 23 Feb 2022 17:49:52 -0800 Subject: [PATCH 1/3] Add test for alt option in glue:figure directive. --- tests/notebooks/with_glue.ipynb | 1 + tests/test_glue/test_parser.sphinx3.xml | 2 +- tests/test_glue/test_parser.sphinx4.xml | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) 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… -
+
From 6f7a30fdf0f349ee1c4c296e5453df9db152bc85 Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Wed, 23 Feb 2022 17:52:54 -0800 Subject: [PATCH 2/3] Add alt to glue figure. --- myst_nb/nb_glue/domain.py | 4 ++++ 1 file changed, 4 insertions(+) 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: From 89e7778d8b126abb3e6b4ad7f9c8d7403925d197 Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Wed, 23 Feb 2022 21:20:33 -0800 Subject: [PATCH 3/3] Update documentation. --- docs/use/glue.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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`! ```