From: Marcin Koziej Date: Wed, 13 Feb 2013 15:00:04 +0000 (+0100) Subject: strip spaces in title anchors X-Git-Url: https://git.mdrn.pl/librarian.git/commitdiff_plain/31a937f6e9a6f521181637c84a196788696eefee strip spaces in title anchors --- diff --git a/librarian/pyhtml.py b/librarian/pyhtml.py index 9fd0d97..1762c01 100644 --- a/librarian/pyhtml.py +++ b/librarian/pyhtml.py @@ -52,11 +52,14 @@ class EduModule(Xmill): handle_tytul_dziela = tag('em', 'title') handle_slowo_obce = tag('em', 'foreign') + def naglowek_to_anchor(self, naglowek): + return re.sub(r" +", " ", naglowek.text.strip()) + def handle_nazwa_utworu(self, element): toc = [] for naglowek in element.getparent().findall('.//naglowek_rozdzial'): a = etree.Element("a") - a.attrib["href"] = "#" + naglowek.text + a.attrib["href"] = "#" + self.naglowek_to_anchor(naglowek) a.text = naglowek.text atxt = etree.tostring(a, encoding=unicode) toc.append("
  • %s
  • " % atxt) @@ -66,7 +69,7 @@ class EduModule(Xmill): @tagged("h2") def handle_naglowek_rozdzial(self, element): - return "", "".join(tag_open_close("a", name=element.text)) + return "", "".join(tag_open_close("a", name=self.naglowek_to_anchor(element))) def handle_uwaga(self, _e): return None