From a21bc61feb6da339f3d65a3a00cffb37502f6f12 Mon Sep 17 00:00:00 2001 From: Miloslav Pojman Date: Sat, 28 Jul 2018 14:33:48 +0100 Subject: [PATCH 1/2] Allow class attribute for images, so they can be aligned. RST renders images with class="align-..." attributes. With this commit, the aligment won't stripped during bleach cleanup. Because class is already allowed on other elements (span, code, hr), this should not introduce any new possibilities for bad guys. --- readme_renderer/clean.py | 2 +- tests/fixtures/test_rst_png_attrs.html | 2 +- tests/fixtures/test_rst_svg_attrs.html | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/readme_renderer/clean.py b/readme_renderer/clean.py index d1ccb11..47f950e 100644 --- a/readme_renderer/clean.py +++ b/readme_renderer/clean.py @@ -42,7 +42,7 @@ # Custom Additions "*": ["id"], "hr": ["class"], - "img": ["src", "width", "height", "alt", "align"], + "img": ["src", "width", "height", "alt", "align", "class"], "span": ["class"], "th": ["align"], "td": ["align"], diff --git a/tests/fixtures/test_rst_png_attrs.html b/tests/fixtures/test_rst_png_attrs.html index dfe7b76..71e85ed 100644 --- a/tests/fixtures/test_rst_png_attrs.html +++ b/tests/fixtures/test_rst_png_attrs.html @@ -1 +1 @@ -alternate text +alternate text diff --git a/tests/fixtures/test_rst_svg_attrs.html b/tests/fixtures/test_rst_svg_attrs.html index 9340d36..2ff8ba9 100644 --- a/tests/fixtures/test_rst_svg_attrs.html +++ b/tests/fixtures/test_rst_svg_attrs.html @@ -1 +1 @@ -alternate text +alternate text From 7a9f78c6113c1f1fdd7889e95aa2e116cde59885 Mon Sep 17 00:00:00 2001 From: Miloslav Pojman Date: Sat, 28 Jul 2018 15:20:52 +0100 Subject: [PATCH 2/2] Allow to set width and height of images. RST creates image tags with style="width: ...; height=...;" attributes. This commit stops bleach from stripping it. Width and height attributes are already whitelisted, so this should not allow anything new. --- readme_renderer/clean.py | 6 ++++-- tests/fixtures/test_CommonMark_style.html | 1 + tests/fixtures/test_CommonMark_style.md | 1 + tests/fixtures/test_GFM_style.html | 1 + tests/fixtures/test_GFM_style.md | 1 + tests/fixtures/test_rst_png_attrs.html | 2 +- tests/fixtures/test_rst_svg_attrs.html | 2 +- 7 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 tests/fixtures/test_CommonMark_style.html create mode 100644 tests/fixtures/test_CommonMark_style.md create mode 100644 tests/fixtures/test_GFM_style.html create mode 100644 tests/fixtures/test_GFM_style.md diff --git a/readme_renderer/clean.py b/readme_renderer/clean.py index 47f950e..42aed79 100644 --- a/readme_renderer/clean.py +++ b/readme_renderer/clean.py @@ -42,7 +42,7 @@ # Custom Additions "*": ["id"], "hr": ["class"], - "img": ["src", "width", "height", "alt", "align", "class"], + "img": ["src", "width", "height", "alt", "align", "class", "style"], "span": ["class"], "th": ["align"], "td": ["align"], @@ -50,7 +50,9 @@ "p": ["align"], } -ALLOWED_STYLES = [] +ALLOWED_STYLES = [ + "width", "height", +] def clean(html, tags=None, attributes=None, styles=None): diff --git a/tests/fixtures/test_CommonMark_style.html b/tests/fixtures/test_CommonMark_style.html new file mode 100644 index 0000000..3468fc5 --- /dev/null +++ b/tests/fixtures/test_CommonMark_style.html @@ -0,0 +1 @@ + diff --git a/tests/fixtures/test_CommonMark_style.md b/tests/fixtures/test_CommonMark_style.md new file mode 100644 index 0000000..49bcc89 --- /dev/null +++ b/tests/fixtures/test_CommonMark_style.md @@ -0,0 +1 @@ + diff --git a/tests/fixtures/test_GFM_style.html b/tests/fixtures/test_GFM_style.html new file mode 100644 index 0000000..3468fc5 --- /dev/null +++ b/tests/fixtures/test_GFM_style.html @@ -0,0 +1 @@ + diff --git a/tests/fixtures/test_GFM_style.md b/tests/fixtures/test_GFM_style.md new file mode 100644 index 0000000..49bcc89 --- /dev/null +++ b/tests/fixtures/test_GFM_style.md @@ -0,0 +1 @@ + diff --git a/tests/fixtures/test_rst_png_attrs.html b/tests/fixtures/test_rst_png_attrs.html index 71e85ed..892688d 100644 --- a/tests/fixtures/test_rst_png_attrs.html +++ b/tests/fixtures/test_rst_png_attrs.html @@ -1 +1 @@ -alternate text +alternate text diff --git a/tests/fixtures/test_rst_svg_attrs.html b/tests/fixtures/test_rst_svg_attrs.html index 2ff8ba9..3797e28 100644 --- a/tests/fixtures/test_rst_svg_attrs.html +++ b/tests/fixtures/test_rst_svg_attrs.html @@ -1 +1 @@ -alternate text +alternate text