.. code:: python
PLUGINS += ['m.htmlsanity', 'm.images']
+ M_IMAGES_REQUIRE_ALT_TEXT = False
`Images, figures`_
==================
`figure <{filename}/css/components.rst#figures>`_ styling.
- Removes the :rst:`:align:`, :rst:`:figwidth:` and :rst:`:scale:` options,
as this is better handled by ``m.css`` features.
+- To maintain accessibility easier, makes it possible to enforce :rst:`:alt:`
+ text for every image and figure by setting :py:`M_IMAGES_REQUIRE_ALT_TEXT`
+ to :py:`True`.
You can add `additional CSS classes <{filename}/css/components.rst#images>`_ to
images or figures via the :rst:`:class:` or :rst:`:figclass:` options,
- .m-image CSS class added
- adding a outer container for clickable image to make the clickable area
cover only the image
+ - optionally dying when alt text is not present
"""
required_arguments = 1
optional_arguments = 0
final_argument_whitespace = True
- option_spec = {'alt': directives.unchanged,
+ option_spec = {'alt': directives.unchanged_required,
'name': directives.unchanged,
'class': directives.class_option,
'target': directives.unchanged_required}
if 'classes' in self.options: del self.options['classes']
image_node = nodes.image(self.block_text, **self.options)
+ if not 'alt' in self.options and settings['M_IMAGES_REQUIRE_ALT_TEXT']:
+ error = self.state_machine.reporter.error(
+ 'Images and figures require the alt text. See the M_IMAGES_REQUIRE_ALT_TEXT option.',
+ image_node,
+ line=self.lineno)
+ return [error]
+
self.add_name(image_node)
if reference_node:
if self.image_class:
def configure(pelicanobj):
settings['PATH'] = pelicanobj.settings.get('PATH', 'content')
+ settings['M_IMAGES_REQUIRE_ALT_TEXT'] = pelicanobj.settings.get('M_IMAGES_REQUIRE_ALT_TEXT', False)
def register():
signals.initialized.connect(configure)