X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/3f24ff6b4246a5206555952f6e6c53f6ed5231d8..ea9a4eea8ee61954c9ae52e8662139c8933ea95d:/librarian/formats/html/__init__.py diff --git a/librarian/formats/html/__init__.py b/librarian/formats/html/__init__.py index ae6470a..064eba7 100644 --- a/librarian/formats/html/__init__.py +++ b/librarian/formats/html/__init__.py @@ -9,7 +9,7 @@ from librarian.formats import Format from librarian.output import OutputFile from librarian.renderers import Register, TreeRenderer from librarian.utils import Context, get_resource -from librarian import core +from librarian import core, VIDEO_PROVIDERS class HtmlFormat(Format): @@ -187,7 +187,27 @@ 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) + provider = element.attrib.get('provider', '') + video_id = element.attrib.get('videoid', '') + attribs = { + 'width': '854', + 'height': '480', + 'src': VIDEO_PROVIDERS[provider]['embed'] % 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'))