From d187d47296c30c915930ee5762c143cb431ab170 Mon Sep 17 00:00:00 2001
From: Loic Dachary <loic@dachary.org>
Date: Tue, 12 Jan 2016 19:29:46 +0100
Subject: [PATCH] Fix #1085 - allow h1/h2 in html cleanup

The markdown conversion of

    bin/python -m markdown <<EOF
    AAAAAAA
    =======

    BBBBBBB
    -------

    CCCCCCC
    EOF

    <h1>AAAAAAA</h1>
    <h2>BBBBBBB</h2>
    <p>CCCCCCC</p>

Must not be stripped of the h1/h2 elements.

Signed-off-by: Loic Dachary <loic@dachary.org>
---
 mediagoblin/tests/test_util.py | 6 +++++-
 mediagoblin/tools/text.py      | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/mediagoblin/tests/test_util.py b/mediagoblin/tests/test_util.py
index 8193233..970ea1f 100644
--- a/mediagoblin/tests/test_util.py
+++ b/mediagoblin/tests/test_util.py
@@ -169,11 +169,15 @@ def test_html_cleaner():
     result = text.clean_html(
         '<p>Hi everybody! '
         '<img src="http://example.org/huge-purple-barney.png" /></p>\n'
-        '<p>:)</p>')
+        '<p>:)</p>'
+        '<h1>H1</h1>'
+        '<h2>H2</h2>')
     assert result == (
         '<div>'
         '<p>Hi everybody! </p>\n'
         '<p>:)</p>'
+        '<h1>H1</h1>'
+        '<h2>H2</h2>'
         '</div>')
 
     # Remove evil javascript
diff --git a/mediagoblin/tools/text.py b/mediagoblin/tools/text.py
index 96df49d..b253696 100644
--- a/mediagoblin/tools/text.py
+++ b/mediagoblin/tools/text.py
@@ -37,7 +37,7 @@ HTML_CLEANER = Cleaner(
     annoying_tags=True,
     allow_tags=[
         'div', 'b', 'i', 'em', 'strong', 'p', 'ul', 'ol', 'li', 'a', 'br',
-        'pre', 'code'],
+        'pre', 'code', 'h1', 'h2'],
     remove_unknown_tags=False,  # can't be used with allow_tags
     safe_attrs_only=True,
     add_nofollow=True,  # for now
-- 
2.6.4

