From f3e3374103ee892540927b65acc2231a10e493b7 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Thu, 20 Jun 2013 13:37:37 +0200 Subject: [PATCH] Workaround was bad. --- librarian/pyhtml.py | 2 +- librarian/xmlutils.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/librarian/pyhtml.py b/librarian/pyhtml.py index 7047cc9..096e1f6 100644 --- a/librarian/pyhtml.py +++ b/librarian/pyhtml.py @@ -36,7 +36,7 @@ class EduModule(Xmill): txt = txt.replace("/\n", "
\n") return txt self.register_text_filter(functions.substitute_entities) - self.register_text_filter(swap_endlines) + self.register_escaped_text_filter(swap_endlines) @tagged('div', 'stanza') def handle_strofa(self, element): diff --git a/librarian/xmlutils.py b/librarian/xmlutils.py index 8890f4e..345e011 100644 --- a/librarian/xmlutils.py +++ b/librarian/xmlutils.py @@ -17,17 +17,23 @@ class Xmill(object): if options: self._options.append(options) self.text_filters = [] + self.escaped_text_filters = [] def register_text_filter(self, fun): self.text_filters.append(fun) def filter_text(self, text): + for flt in self.text_filters: + if text is None: + return None + else: + text = flt(text) # TODO: just work on the tree and let lxml handle escaping. e = etree.Element("x") e.text = text # This whole mixing text with ML is so wrong. output = etree.tostring(e, encoding=unicode)[3:-4] - for flt in self.text_filters: + for flt in self.escaped_text_filters: output = flt(output) return output -- 2.20.1