X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/935dcf2282ee3c08f776e221bc71f9a0744cb85e..e4ffa9f5172b88a5a49ed832634105dd65b9727f:/librarian/weasy.py
diff --git a/librarian/weasy.py b/librarian/weasy.py
new file mode 100644
index 0000000..d2cd7e4
--- /dev/null
+++ b/librarian/weasy.py
@@ -0,0 +1,729 @@
+# -*- coding: utf-8 -*-
+#
+# This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
+import os
+import shutil
+from tempfile import mkdtemp, NamedTemporaryFile
+
+from lxml import etree
+from subprocess import call
+
+from librarian import IOFile, Format, ParseError, get_resource
+from xmlutils import Xmill, tag, tagged, ifoption, tag_open_close
+from librarian import functions
+import re
+import random
+from copy import deepcopy
+
+IMAGE_THUMB_WIDTH = 300
+
+
+class EduModule(Xmill):
+ def __init__(self, options=None):
+ super(EduModule, self).__init__(options)
+ self.activity_counter = 0
+ self.activity_last = None
+ self.exercise_counter = 0
+
+ # text filters
+ def swap_endlines(txt):
+ if self.options['strofa']:
+ txt = txt.replace("/\n", "
\n")
+ return txt
+ self.register_text_filter(functions.substitute_entities)
+ self.register_escaped_text_filter(swap_endlines)
+
+ @tagged('div', 'stanza')
+ def handle_strofa(self, element):
+ self.options = {'strofa': True}
+ return "", ""
+
+ def handle_powiesc(self, element):
+ return u"""
+
+
%s
%s min
W przygotowaniu.
' + else: + return None + if ltype == 'slowniczek': + surl = element.attrib.get('src', None) + if surl is None: + # print '** missing src on