fake slant
[librarian.git] / librarian / formats / epub / __init__.py
index 38443ee..36891be 100644 (file)
@@ -13,7 +13,7 @@ import zipfile
 from urllib2 import urlopen
 
 from lxml import etree
 from urllib2 import urlopen
 
 from lxml import etree
-from librarian import OPFNS, NCXNS, XHTMLNS, DCNS
+from librarian import OPFNS, NCXNS, XHTMLNS, DCNS, BuildError
 from librarian import core
 from librarian.formats import Format
 from librarian.formats.cover.evens import EvensCover
 from librarian import core
 from librarian.formats import Format
 from librarian.formats.cover.evens import EvensCover
@@ -35,8 +35,11 @@ class EpubFormat(Format):
         if cover is not None:
             self.cover = cover
 
         if cover is not None:
             self.cover = cover
 
-    def dc(self, tag):
-        return self.doc.meta.get_one(DCNS(tag))
+    def dc(self, tag, multiple=False):
+        if multiple:
+            return ', '.join(self.doc.meta.get(DCNS(tag)))
+        else:
+            return self.doc.meta.get_one(DCNS(tag))
 
     def build(self, ctx=None):
 
 
     def build(self, ctx=None):
 
@@ -158,7 +161,7 @@ class EpubFormat(Format):
             'Information about the resource',
             'Publisher: %s' % self.dc('publisher'),
             'Rights: %s' % self.dc('rights'),
             'Information about the resource',
             'Publisher: %s' % self.dc('publisher'),
             'Rights: %s' % self.dc('rights'),
-            'Intended audience: %s' % self.dc('audience'),
+            'Intended audience: %s' % self.dc('audience', multiple=True),
             self.dc('description'),
             'Resource prepared using MIL/PEER editing platform.',
             'Source available at %s' % ctx.source_url,
             self.dc('description'),
             'Resource prepared using MIL/PEER editing platform.',
             'Source available at %s' % ctx.source_url,
@@ -334,12 +337,15 @@ EpubFormat.renderers.register(core.Div, 'p', NaturalText('p'))
 EpubFormat.renderers.register(core.Div, 'list', NaturalText('ul'))
 EpubFormat.renderers.register(core.Div, 'list.enum', NaturalText('ol'))
 EpubFormat.renderers.register(core.Div, 'item', NaturalText('li'))
 EpubFormat.renderers.register(core.Div, 'list', NaturalText('ul'))
 EpubFormat.renderers.register(core.Div, 'list.enum', NaturalText('ol'))
 EpubFormat.renderers.register(core.Div, 'item', NaturalText('li'))
+EpubFormat.renderers.register(core.Span, 'item', NaturalText('li'))
 
 
 class DivImageR(EpubRenderer):
     def render(self, element, ctx):
         src = element.attrib.get('src', '')
         ctx.images.append(src)
 
 
 class DivImageR(EpubRenderer):
     def render(self, element, ctx):
         src = element.attrib.get('src', '')
         ctx.images.append(src)
+        if '/' not in src:
+            raise BuildError('Bad image URL')
         src = src.rsplit('/', 1)[1]
         return super(DivImageR, self).render(element, Context(ctx, src=src))
 
         src = src.rsplit('/', 1)[1]
         return super(DivImageR, self).render(element, Context(ctx, src=src))