diff --git a/src/calibre/ebooks/metadata/opf3.py b/src/calibre/ebooks/metadata/opf3.py
index 2e67f89f92..d3e54f156f 100644
--- a/src/calibre/ebooks/metadata/opf3.py
+++ b/src/calibre/ebooks/metadata/opf3.py
@@ -526,6 +526,27 @@ def read_last_modified(root, prefixes, refines):
continue
# }}}
+# Comments {{{
+
+def read_comments(root, prefixes, refines):
+ ans = ''
+ for dc in XPath('./opf:metadata/dc:description')(root):
+ if dc.text:
+ ans += '\n' + dc.text.strip()
+ return ans.strip()
+
+def set_comments(root, prefixes, refines, val):
+ for dc in XPath('./opf:metadata/dc:description')(root):
+ remove_element(dc, refines)
+ m = XPath('./opf:metadata')(root)[0]
+ if val:
+ val = val.strip()
+ if val:
+ c = m.makeelement(DC('description'))
+ c.text = val
+ m.append(c)
+# }}}
+
def read_metadata(root):
ans = Metadata(_('Unknown'), [_('Unknown')])
prefixes, refines = read_prefixes(root), read_refines(root)
@@ -557,6 +578,7 @@ def read_metadata(root):
lm = read_last_modified(root, prefixes, refines)
if not is_date_undefined(lm):
ans.last_modified = lm
+ ans.comments = read_comments(root, prefixes, refines) or ans.comments
return ans
def get_metadata(stream):
@@ -575,6 +597,7 @@ def apply_metadata(root, mi, cover_prefix='', cover_data=None, apply_null=False,
set_authors(root, prefixes, refines, authors)
set_pubdate(root, prefixes, refines, mi.pubdate)
set_timestamp(root, prefixes, refines, mi.timestamp)
+ set_comments(root, prefixes, refines, mi.comments)
pretty_print_opf(root)
diff --git a/src/calibre/ebooks/metadata/opf3_test.py b/src/calibre/ebooks/metadata/opf3_test.py
index d96ce73b03..4b985324d4 100644
--- a/src/calibre/ebooks/metadata/opf3_test.py
+++ b/src/calibre/ebooks/metadata/opf3_test.py
@@ -15,7 +15,8 @@ from calibre.ebooks.metadata.opf3 import (
read_refines, set_title, read_title_sort, read_languages, set_languages,
read_authors, Author, set_authors, ensure_prefix, read_prefixes,
read_book_producers, set_book_producers, read_timestamp, set_timestamp,
- read_pubdate, set_pubdate, CALIBRE_PREFIX, read_last_modified
+ read_pubdate, set_pubdate, CALIBRE_PREFIX, read_last_modified, read_comments,
+ set_comments
)
TEMPLATE = '''{metadata}''' % CALIBRE_PREFIX # noqa
@@ -172,6 +173,16 @@ class TestOPF3(unittest.TestCase):
self.ae(read_last_modified(root, read_prefixes(root), read_refines(root)).year, 2003)
# }}}
+ def test_comments(self): # {{{
+ def rt(root):
+ return read_comments(root, read_prefixes(root), read_refines(root))
+ def st(root, val):
+ set_comments(root, read_prefixes(root), read_refines(root), val)
+ return rt(root)
+ root = self.get_opf('''<span>one</span> xxx''')
+ self.ae('one\nxxx', rt(root))
+ # }}}
+
# Run tests {{{
def suite():