def tidy_and_premail(content): # HTML Tidy strTidiedHtml, strErrors = tidy_document( content, options={ 'output-xhtml': 1, # XHTML instead of HTML4 'indent': 0, # Don't use indent, add's extra linespace or linefeeds which are big problems 'tidy-mark': 0, # No tidy meta tag in output 'wrap': 0, # No wrapping 'alt-text': '', # Help ensure validation 'doctype': 'strict', # Little sense in transitional for tool-generated markup... 'force-output': 1, # May not get what you expect but you will get something 'numeric-entities': 1, # remove HTML entities like e.g. nbsp 'clean': 1, # remove 'bare': 1, 'word-2000': 1, 'drop-proprietary-attributes': 1, 'enclose-text': 1, # enclose text in body always with <p>...</p> 'logical-emphasis': 1 # transforms <i> and <b> text to <em> and <strong> text }) # Move CSS from stylesheet inside the tags with. BTW: Premailer do this usually for old email clients. # Use a special XHTML Premailer which does not destroy the XML structure. premailer = xhtmlPremailer(strTidiedHtml) strTidiedPremailedHtml = premailer.transform() return strTidiedPremailedHtml
def tidy_and_premail(content): # HTML Tidy # Tidy up HTML and convert it to XHTML strTidiedXhtml, strErrors = tidy_document( content, options={ 'output-xhtml': 1, # XHTML instead of HTML4 'indent': 0, # Don't use indent which adds extra linespace or linefeeds which are big problems 'tidy-mark': 0, # No tidy meta tag in output 'wrap': 0, # No wrapping 'alt-text': '', # Help ensure validation 'doctype': 'strict', # Little sense in transitional for tool-generated markup... 'force-output': 1, # May not get what you expect but you will get something 'numeric-entities': 1, # Remove HTML entities like e.g. nbsp 'clean': 1, # Cleaning 'bare': 1, 'word-2000': 1, # Cleans Word HTML 'drop-proprietary-attributes': 1, 'enclose-text': 1, # enclose text in body always with <p>...</p> 'logical-emphasis': 1 # transforms <i> and <b> text to <em> and <strong> text }) # DEBUG #f=open('xhtml.xml', 'w') #f.write(strTidiedXhtml) #f.close # XHTML Premailer # Remove CSS references and place the whole CSS inside tags. # BTW: Premailer does this usually for old email clients. # Use a special XHTML Premailer which does not destroy the XML structure. # If Premailer fails (on complicated CSS) then return the unpremailed tidied HTML try: premailer = xhtmlPremailer(strTidiedXhtml) strTidiedPremailedHtml = premailer.transform() return strTidiedPremailedHtml except: return strTidiedXhtml
def tidy_and_premail(content): # HTML Tidy # Tidy up HTML and convert it to XHTML strTidiedXhtml, strErrors = tidy_document(content, options={ 'output-xhtml': 1, # XHTML instead of HTML4 'indent': 0, # Don't use indent which adds extra linespace or linefeeds which are big problems 'tidy-mark': 0, # No tidy meta tag in output 'wrap': 0, # No wrapping 'alt-text': '', # Help ensure validation 'doctype': 'strict', # Little sense in transitional for tool-generated markup... 'force-output': 1, # May not get what you expect but you will get something 'numeric-entities': 1, # Remove HTML entities like e.g. nbsp 'clean': 1, # Cleaning 'bare': 1, 'word-2000': 1, # Cleans Word HTML 'drop-proprietary-attributes': 1, 'enclose-text': 1, # enclose text in body always with <p>...</p> 'logical-emphasis': 1 # transforms <i> and <b> text to <em> and <strong> text }) # DEBUG #f=open('xhtml.xml', 'w') #f.write(strTidiedXhtml) #f.close # XHTML Premailer # Remove CSS references and place the whole CSS inside tags. # BTW: Premailer does this usually for old email clients. # Use a special XHTML Premailer which does not destroy the XML structure. # If Premailer fails (on complicated CSS) then return the unpremailed tidied HTML try: premailer = xhtmlPremailer(strTidiedXhtml) strTidiedPremailedHtml = premailer.transform() return strTidiedPremailedHtml except: return strTidiedXhtml
def tidy_and_premail(content): # HTML Tidy strTidiedHtml, strErrors = tidy_document(content, options={ 'output-xhtml': 1, # XHTML instead of HTML4 'indent': 0, # Don't use indent, add's extra linespace or linefeeds which are big problems 'tidy-mark': 0, # No tidy meta tag in output 'wrap': 0, # No wrapping 'alt-text': '', # Help ensure validation 'doctype': 'strict', # Little sense in transitional for tool-generated markup... 'force-output': 1, # May not get what you expect but you will get something 'numeric-entities': 1, # remove HTML entities like e.g. nbsp 'clean': 1, # remove 'bare': 1, 'word-2000': 1, 'drop-proprietary-attributes': 1, 'enclose-text': 1, # enclose text in body always with <p>...</p> 'logical-emphasis': 1 # transforms <i> and <b> text to <em> and <strong> text }) # Move CSS from stylesheet inside the tags with. BTW: Premailer do this usually for old email clients. # Use a special XHTML Premailer which does not destroy the XML structure. premailer = xhtmlPremailer(strTidiedHtml) strTidiedPremailedHtml = premailer.transform() return strTidiedPremailedHtml
def premail(xhtml): premailer = xhtmlPremailer(xhtml) premailed_xhtml = premailer.transform() return premailed_xhtml, {}