diff -r 1d314f629611 -r b7a092a52eae src/cm/converters/abi_converters.py --- a/src/cm/converters/abi_converters.py Tue Jul 31 16:37:23 2012 +0200 +++ b/src/cm/converters/abi_converters.py Mon Aug 06 13:42:15 2012 +0200 @@ -270,7 +270,10 @@ Add an HTML header to an HTML body """ - return """ + if '
@@ -281,3 +284,24 @@ """ %body + # Adds some style to fix Abiword default margins for paragraphs. + from BeautifulSoup import BeautifulSoup + import cssutils + soup = BeautifulSoup(full_html) + for p in soup.findAll(['p', 'div', 'ul', 'ol', 'dl']): + try: + css = p['style'] + s = cssutils.parseStyle(css) + if s.getProperty('margin') == None: + if s.getProperty('margin-top') == None: + s.setProperty('margin-top', '10pt') + if s.getProperty('margin-bottom') == None: + s.setProperty('margin-bottom', '10pt') + p['style'] = s.cssText + + except KeyError: + p['style'] = 'margin-top: 10pt; margin-bottom: 10pt;'; + + # for some reason having DOCTYPE declaration makes soup unhappy + output = re.sub(r']*>)>', r'\1', unicode(soup)) + return output