From efa6b8d0c111985d1131b7b3e9dfa3e6bcc1a90f Mon Sep 17 00:00:00 2001 From: Duncan Lock Date: Mon, 29 Apr 2013 12:21:22 -0700 Subject: [PATCH] Added fixing alt text; updated readme Signed-off-by: Duncan Lock --- .../better_figures_and_images.py | 12 +++++++--- better_figures_and_images/readme.rst | 24 +++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/better_figures_and_images/better_figures_and_images.py b/better_figures_and_images/better_figures_and_images.py index 0b3df23..af73104 100644 --- a/better_figures_and_images/better_figures_and_images.py +++ b/better_figures_and_images/better_figures_and_images.py @@ -1,11 +1,13 @@ """ Better Figures & Images -------- +------------------------ This plugin: -- Adds a style="width: ???px;" to each image in the content +- Adds a style="width: ???px; height: auto;" to each image in the content - Also adds the width of the contained image to any parent div.figures. + - If RESPONSIVE_IMAGES == True, adds style="max-width: 100%; height: auto;" instead +- Corrects alt text: if alt == image filename, set alt = '' TODO: Need to add a test.py for this plugin. @@ -38,7 +40,7 @@ def content_object_init(instance): if 'img' in content: for img in soup('img'): if instance.settings['RESPONSIVE_IMAGES']: - extra_style = 'max-width: 100%;' + extra_style = 'max-width: 100%; height: auto;' else: # TODO: Pretty sure this isn't the right way to do this, too hard coded. # There must be a setting that I should be using? @@ -50,6 +52,10 @@ def content_object_init(instance): img['style'] += extra_style else: img['style'] = extra_style + + if img['alt'] == img['src']: + img['alt'] = '' + fig = img.find_parent('div', 'figure') if fig: if fig.get('style'): diff --git a/better_figures_and_images/readme.rst b/better_figures_and_images/readme.rst index 78270b5..389be6f 100644 --- a/better_figures_and_images/readme.rst +++ b/better_figures_and_images/readme.rst @@ -4,14 +4,16 @@ Summary This plug-in: - Adds a `style="width: ???px;"` attribute to any `` tags in the content, by checking -the dimensions of the image file and adding the appropriate style="width: ???px;" to the `` tag. +the dimensions of the image file and adding the appropriate `style="width: ???px; height: auto;"` to the `` tag. - Also finds any `div class="figures"` tags in the content, that contain images and adds the same style to them too. +- If RESPONSIVE_IMAGES setting is true, it adds `style="max-width: 100%; height: auto;"` instead. +- Corrects Alt text: If an img alt attribute = the image filename, it sets it to "" Assuming that the image is 250px wide, it turns output like this: -
- map to buried treasure +
+ /static/images/image.jpg

This is the caption of the figure.

@@ -23,8 +25,8 @@ Assuming that the image is 250px wide, it turns output like this: into output like this: -
- map to buried treasure +
+

This is the caption of the figure.

@@ -34,3 +36,15 @@ into output like this:
+or this, if RESPONSIVE_IMAGES = True: + +
+ +

+ This is the caption of the figure. +

+
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod + tempor incididunt ut labore et dolore magna aliqua. +
+
\ No newline at end of file