stupid bug in epub
[librarian.git] / librarian / formats / html / __init__.py
index 2cf2601..e1825a5 100644 (file)
@@ -40,7 +40,7 @@ class HtmlFormat(Format):
 
         t.find('.//div[@id="content"]').extend(
             self.render(self.doc.edoc.getroot(), ctx))
-        #t.find('.//div[@id="toc"]').append(ctx.toc.render())
+        # t.find('.//div[@id="toc"]').append(ctx.toc.render())
         t.find('.//div[@id="footnotes"]').extend(ctx.footnotes.output)
 
         return OutputFile.from_string(etree.tostring(
@@ -81,7 +81,8 @@ class Footnotes(object):
 
     def append(self, item):
         self.counter += 1
-        e = etree.Element("a",
+        e = etree.Element(
+            "a",
             href="#footnote-anchor-%d" % self.counter,
             id="footnote-%d" % self.counter,
             style="float:left;margin-right:1em")
@@ -89,7 +90,8 @@ class Footnotes(object):
         e.tail = " "
         self.output.append(e)
         self.output.extend(item)
-        anchor = etree.Element("a",
+        anchor = etree.Element(
+            "a",
             id="footnote-anchor-%d" % self.counter,
             href="#footnote-%d" % self.counter)
         anchor.text = "[%d]" % self.counter
@@ -131,6 +133,7 @@ class TOC(object):
 HtmlFormat.renderers.register(core.Aside, None, NaturalText('aside'))
 HtmlFormat.renderers.register(core.Aside, 'comment', Silent())
 
+
 class AsideFootnote(NaturalText):
     def render(self, element, ctx):
         output = super(AsideFootnote, self).render(element, ctx)
@@ -150,21 +153,23 @@ class Header(NaturalText):
         else:
             root[0].tag = 'h2'
             if root[0].text:
-                d = etree.SubElement(root[0], 'a', {'id': root[0].text, 'style': 'pointer: hand; color:#ddd; font-size:.8em'})
-                #d.text = "per"
+                d = etree.SubElement(
+                    root[0], 'a', {'id': root[0].text, 'style': 'pointer: hand; color:#ddd; font-size:.8em'})
+                # d.text = "per"
         return root
 
-       
+
 HtmlFormat.renderers.register(core.Header, None, Header('h1'))
 
 
 HtmlFormat.renderers.register(core.Div, None, NaturalText('div'))
 
+
 class DivDefined(NaturalText):
     def render(self, element, ctx):
         output = super(DivDefined, self).render(element, ctx)
         output[0].text = (output[0].text or '') + ':'
-        output[0].attrib['id'] = output[0].text # not so cool?
+        output[0].attrib['id'] = output[0].text  # not so cool?
         return output
 
 HtmlFormat.renderers.register(core.Div, 'defined', DivDefined('dt', {'style': 'display: inline-block'}))
@@ -182,15 +187,35 @@ class DivImage(NaturalText):
 
 HtmlFormat.renderers.register(core.Div, 'img', DivImage('img'))
 
+
+class DivVideo(NaturalText):
+    def render(self, element, ctx):
+        output = super(DivVideo, self).render(element, ctx)
+        video_id = element.attrib.get('videoid', '')
+        attribs = {
+            'width': '854',
+            'height': '480',
+            'src': '//www.youtube.com/embed/%s?controls=2&rel=0&showinfo=0&theme=light' % video_id,
+            'frameborder': '0',
+            'allowfullscreen': '',
+        }
+        for attrib, value in attribs.iteritems():
+            output[0].attrib[attrib] = value
+        return output
+
+HtmlFormat.renderers.register(core.Div, 'video', DivVideo('iframe'))
+
 HtmlFormat.renderers.register(core.Div, 'item', NaturalText('li'))
+HtmlFormat.renderers.register(core.Span, 'item', NaturalText('li'))
 HtmlFormat.renderers.register(core.Div, 'list', NaturalText('ul'))
 HtmlFormat.renderers.register(core.Div, 'list.enum', NaturalText('ol'))
 
+
 class DivListDefinitions(NaturalText):
     def render(self, element, ctx):
         output = super(DivListDefinitions, self).render(element, ctx)
-        #if ctx.toc_level > 2:
-        #    output[0].attrib['style'] = 'float: right'
+        # if ctx.toc_level > 2:
+        #     output[0].attrib['style'] = 'float: right'
         return output
 
 HtmlFormat.renderers.register(core.Div, 'list.definitions', DivListDefinitions('ul'))
@@ -215,6 +240,7 @@ HtmlFormat.renderers.register(core.Span, 'cite.code', LiteralText('code'))
 HtmlFormat.renderers.register(core.Span, 'emph', NaturalText('em'))
 HtmlFormat.renderers.register(core.Span, 'emp', NaturalText('strong'))
 
+
 class SpanUri(LiteralText):
     def render(self, element, ctx):
         root = super(SpanUri, self).render(element, ctx)
@@ -222,6 +248,7 @@ class SpanUri(LiteralText):
         return root
 HtmlFormat.renderers.register(core.Span, 'uri', SpanUri('a'))
 
+
 class SpanLink(LiteralText):
     def render(self, element, ctx):
         root = super(SpanLink, self).render(element, ctx)
@@ -231,4 +258,3 @@ class SpanLink(LiteralText):
         root[0].attrib['href'] = src
         return root
 HtmlFormat.renderers.register(core.Span, 'link', SpanLink('a'))
-