X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/fcaf06749607b02e11e4edc3b8ae8313e1a1ef91..bfdf1fb55d9a5ee7be5a16ef73e6237ad949ddcb:/librarian/pypdf.py diff --git a/librarian/pypdf.py b/librarian/pypdf.py index 387f647..adc414c 100644 --- a/librarian/pypdf.py +++ b/librarian/pypdf.py @@ -20,6 +20,7 @@ import re import random from copy import deepcopy from subprocess import call, PIPE +from urllib2 import urlopen from Texml.processor import process from lxml import etree @@ -52,7 +53,7 @@ def escape(really): def cmd(name, parms=None): - def wrap(self, element): + def wrap(self, element=None): pre, post = tag_open_close('cmd', name=name) if parms: @@ -60,9 +61,12 @@ def cmd(name, parms=None): e = etree.Element("parm") e.text = parm pre += etree.tostring(e) - pre += "" - post = "" + post - return pre, post + if element is not None: + pre += "" + post = "" + post + return pre, post + else: + return pre + post return wrap @@ -348,10 +352,39 @@ class EduModule(Xmill): def handle_link(self, element): if element.attrib.get('url'): - return cmd('href', parms=[element.attrib['url']])(self, element) + url = element.attrib.get('url') + if url == element.text: + return cmd('url')(self, element) + else: + return cmd('href', parms=[element.attrib['url']])(self, element) else: return cmd('em')(self, element) + def handle_obraz(self, element): + frmt = self.options['format'] + name = element.attrib['nazwa'].strip() + image = frmt.get_image(name.strip()) + img_path = "obraz/%s" % name.replace("_", "") + frmt.attachments[img_path] = image + return cmd("obraz", parms=[img_path])(self) + + def handle_video(self, element): + url = element.attrib.get('url') + if not url: + print '!!