From: Radek Czajka Date: Mon, 18 Feb 2013 11:22:12 +0000 (+0100) Subject: obraz + video in pdf X-Git-Url: https://git.mdrn.pl/librarian.git/commitdiff_plain/bfdf1fb55d9a5ee7be5a16ef73e6237ad949ddcb obraz + video in pdf --- diff --git a/librarian/pdf/wl.cls b/librarian/pdf/wl.cls index 4023934..fa89dc3 100755 --- a/librarian/pdf/wl.cls +++ b/librarian/pdf/wl.cls @@ -75,6 +75,7 @@ \usepackage[overload]{textcase} \usepackage{scalefnt} % TODO: link color is a style thing +\usepackage[hyphens]{url} \usepackage[colorlinks=true,linkcolor=black,setpagesize=false,urlcolor=blue,xetex]{hyperref} \ifenablewlfont @@ -426,3 +427,12 @@ Letters={Uppercase} \renewcommand{\naglowekpodrozdzial}[1]{% \subsubsection*{\typosubsubsection{#1}}% } + +\newcommand{\obraz}[1]{ +\includegraphics[width=8cm]{#1} +} + +\newcommand{\video}[2]{ +\includegraphics[width=8cm]{#1}\\ +\href{#2}{(Otwórz wideo w serwisie YouTube)} +} 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 '!!