From 0e79b86f8ae3172bf1afbed114371af82d0c1aab Mon Sep 17 00:00:00 2001 From: GRiker Date: Wed, 15 Jun 2011 07:23:21 -0600 Subject: [PATCH] For CSV_XML output, convert fields of type unicode from HTML to markup text. --- src/calibre/library/catalog.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/calibre/library/catalog.py b/src/calibre/library/catalog.py index a19534191b..97454c90e2 100644 --- a/src/calibre/library/catalog.py +++ b/src/calibre/library/catalog.py @@ -149,6 +149,15 @@ class CSV_XML(CatalogPlugin): # {{{ elif field == 'comments': item = item.replace(u'\r\n',u' ') item = item.replace(u'\n',u' ') + + # Convert HTML to markdown text + if type(item) is unicode: + opening_tag = re.search('<(\w+)(\x20|>)',item) + if opening_tag: + closing_tag = re.search('<\/%s>$' % opening_tag.group(1), item) + if closing_tag: + item = html2text(item) + outstr.append(u'"%s"' % unicode(item).replace('"','""')) outfile.write(u','.join(outstr) + u'\n')