def set_text(element, content):
content = escape(content, entities={'\r\n': '<br />'}) # retain html tags in text
content = content.replace("\n", "<br />") # replace new line for *nix system
content = content.replace("<br />", "<br />\n") # add the line break in source to make it readable
# trick to add CDATA for element tree lib
element.append(Comment(' --><![CDATA[' + content.replace(']]>', ']]]]><![CDATA[>') + ']]><!-- '))
评论列表
文章目录