EpubFormat.renderers.register(core.Div, 'img', DivImageR('img'))
+class DivVideoR(Silent):
+ def render(self, element, ctx):
+ src = 'https://www.youtube.com/watch?v=%s' % element.attrib.get('videoid', '')
+ return super(DivVideoR, self).render(element, Context(ctx, src=src))
+
+ def container(self, ctx):
+ root, inner = super(DivVideoR, self).container(ctx)
+ src = getattr(ctx, 'src', '')
+ link = etree.Element('a', {'href': src})
+ link.text = src
+ inner.append(link)
+ return root, inner
+EpubFormat.renderers.register(core.Div, 'video', DivVideoR('p'))
+
+
class HeaderR(NaturalText):
def subcontext(self, element, ctx):
return Context(ctx, inline=True)
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.Div, 'list', NaturalText('ul'))
HtmlFormat.renderers.register(core.Div, 'list.enum', NaturalText('ol'))
PdfFormat.renderers.register(core.Div, 'img', ImgRenderer('insertimage'))
+class VideoRenderer(CmdRenderer):
+ def render(self, element, ctx):
+ root = super(VideoRenderer, self).render(element, ctx)
+ url = 'https://www.youtube.com/watch?v=%s' % element.attrib.get('videoid')
+ link = texml_cmd('href', url, url)
+ root[0][0].text = None
+ root[0][0].append(link)
+ return root
+
+PdfFormat.renderers.register(core.Div, 'video', VideoRenderer('par'))
+
+
PdfFormat.renderers.register(core.Div, 'defined', CmdRenderer('textbf'))
PdfFormat.renderers.register(core.Div, 'item', CmdRenderer('item'))
PdfFormat.renderers.register(core.Div, 'list', EnvRenderer('itemize'))