Commit c0b25722 authored by Romain Courteaud's avatar Romain Courteaud

erp5_corporate_identity: downgrade heading with an attribute

Example: <h2 class="foo">bar</h2> => <h3 class="foo">bar</h3>
parent 3feeda15
...@@ -5,17 +5,15 @@ Downgrade headers in passed content by 1 or number of levels specified ...@@ -5,17 +5,15 @@ Downgrade headers in passed content by 1 or number of levels specified
""" """
import re import re
def pushDown(level): REGEXP = re.compile('<h([1-6]).*>.*</h([1-6])>')
return ''.join(["h", str(level), ">"])
for header in re.findall("<h[1-6].*</h[1-6]>", content or ""): def pushDown(regexp_match):
header_list = re.findall("<(h[1-6]>)", header) text = '%r' % regexp_match.group()
if len(header_list): start_level = regexp_match.group(1)
tag = header_list[0] #h2> stop_level = regexp_match.group(2)
key = tag[1] if (start_level == stop_level):
content = content.replace( next_level = "%i" % (int(start_level) + downgrade)
header, text = '<h' + next_level + text[4:-3] + next_level + '>'
header.replace(tag, pushDown(int(key) + (downgrade or 1))) return text
)
return content return REGEXP.sub(pushDown, content)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment