X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/3f24ff6b4246a5206555952f6e6c53f6ed5231d8..1428a9d8f91b754fe7f9fb96cbdd0d6a2536ffc1:/librarian/formats/pdf/__init__.py diff --git a/librarian/formats/pdf/__init__.py b/librarian/formats/pdf/__init__.py index e8e936b..fd1fd5e 100644 --- a/librarian/formats/pdf/__init__.py +++ b/librarian/formats/pdf/__init__.py @@ -11,7 +11,7 @@ from lxml import etree from urllib import urlretrieve from StringIO import StringIO from Texml.processor import process -from librarian import DCNS, XMLNamespace +from librarian import DCNS, XMLNamespace, BuildError from librarian.formats import Format from librarian.output import OutputFile from librarian.renderers import Register, TreeRenderer @@ -52,7 +52,8 @@ class PdfFormat(Format): def add_file(self, ctx, filename, url=None, path=None, image=False): from subprocess import call - assert url or path + if not url or path: + raise BuildError('No URL or path for image') save_as = os.path.join(ctx.workdir, filename) if path is not None: ext = path.rsplit('.', 1)[-1] @@ -332,6 +333,18 @@ class ImgRenderer(CmdRenderer): 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'))