X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/8550d172b829f29b2fcd4723789fb2a5d9fff6eb..175c5cf4f727162fa5bddd2460d37595251bbe8e:/src/librarian/parser.py diff --git a/src/librarian/parser.py b/src/librarian/parser.py index 2bb9509..6e21d4d 100644 --- a/src/librarian/parser.py +++ b/src/librarian/parser.py @@ -19,7 +19,27 @@ import re import six +from .elements import WL_ELEMENTS + + +class WLElementLookup(etree.CustomElementClassLookup): + def lookup(self, node_type, document, namespace, name): + if node_type != 'element': + return + if namespace: + return + return WL_ELEMENTS[name] + + +parser = etree.XMLParser() +parser.set_element_class_lookup( + WLElementLookup() +) + + + class WLDocument(object): + """Legacy class, to be replaced with documents.WLDocument.""" LINE_SWAP_EXPR = re.compile(r'/\s', re.MULTILINE | re.UNICODE) provider = None @@ -177,6 +197,13 @@ class WLDocument(object): node.tag = 'span' node.tail = tail + def fix_pa_akap(self): + for pa in ('pa','pe','pr','pt'): + for akap in self.edoc.findall(f'//{pa}/akap'): + akap.getparent().set('blocks', 'true') + if not akap.getparent().index(akap): + akap.set('inline', 'true') + def editors(self): """Returns a set of all editors for book and its children.