diff --git a/jrnl/Entry.py b/jrnl/Entry.py index 4504982b..b773e747 100755 --- a/jrnl/Entry.py +++ b/jrnl/Entry.py @@ -17,6 +17,10 @@ class Entry: self.starred = starred self.modified = False + @property + def fulltext(self): + return self.title + " " + self.body + @staticmethod def tag_regex(tagsymbols): pattern = r'(?u)\s([{tags}][-+*#/\w]+)'.format(tags=tagsymbols) diff --git a/jrnl/plugins/xml_exporter.py b/jrnl/plugins/xml_exporter.py index 3a031769..0af2ed47 100644 --- a/jrnl/plugins/xml_exporter.py +++ b/jrnl/plugins/xml_exporter.py @@ -28,6 +28,16 @@ class XMLExporter(JSONExporter): else: return entry_el + @classmethod + def entry_to_xml(cls, entry, doc): + entry_el = doc.createElement('entry') + entry_el.setAttribute('date', entry.date.isoformat()) + if hasattr(entry, "uuid"): + entry_el.setAttribute('uuid', u(entry.uuid)) + entry_el.setAttribute('starred', u(entry.starred)) + entry_el.appendChild(doc.createTextNode(entry.fulltext)) + return entry_el + @classmethod def export_journal(cls, journal): """Returns an XML representation of an entire journal.""" @@ -36,12 +46,12 @@ class XMLExporter(JSONExporter): xml = doc.createElement('journal') tags_el = doc.createElement('tags') entries_el = doc.createElement('entries') - for tag in tags: + for count, tag in tags: tag_el = doc.createElement('tag') - tag_el.setAttribute('name', tag[1]) - count_node = doc.createTextNode(u(tag[0])) - tag.appendChild(count_node) - tags_el.appendChild(tag) + tag_el.setAttribute('name', tag) + count_node = doc.createTextNode(u(count)) + tag_el.appendChild(count_node) + tags_el.appendChild(tag_el) for entry in journal.entries: entries_el.appendChild(cls.entry_to_xml(entry, doc)) xml.appendChild(entries_el) diff --git a/jrnl/util.py b/jrnl/util.py index f93d8fd8..e7cedae7 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -76,10 +76,13 @@ def set_keychain(journal_name, password): def u(s): """Mock unicode function for python 2 and 3 compatibility.""" + if not isinstance(s, str): + s = str(s) return s if PY3 or type(s) is unicode else s.decode("utf-8") + def py2encode(s): - """Encodes to UTF-8 in Python 2 but not r.""" + """Encodes to UTF-8 in Python 2 but not in Python 3.""" return s.encode("utf-8") if PY2 and type(s) is unicode else s