From a08563b44bce734bec68de11fa950747a75cd554 Mon Sep 17 00:00:00 2001 From: flywire Date: Thu, 16 Jul 2020 14:38:31 +1000 Subject: [PATCH] More refactoring --- caption/caption.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/caption/caption.py b/caption/caption.py index 5231931..b76702e 100644 --- a/caption/caption.py +++ b/caption/caption.py @@ -40,31 +40,30 @@ def buildContentElement(self, par): par.text = "\n" par.tail = "\n" - def buildCaptionElement(self, par, title): - capcaption = ElementTree.SubElement(par, "figcaption") + caption = ElementTree.SubElement(par, "figcaption") if self.captionClass is not "": - capcaption.set("class", self.captionClass) + caption.set("class", self.captionClass) if self.captionNumbering: - captionPrefixSpan = ElementTree.SubElement(capcaption, "span") + captionPrefixSpan = ElementTree.SubElement(caption, "span") captionPrefixSpan.text = "{} {}:".format(self.captionPrefix, self.captionNumber) captionPrefixSpan.tail = " {}".format(title) if self.captionPrefixClass is not "": captionPrefix.set("class", self.captionPrefixClass) else: - capcaption.text = title - capcaption.tail = "\n" + caption.text = title + caption.tail = "\n" def run(self, root): for par in root.findall("./p[img]"): - self.captionNumber += 1 img = par.find("img") + self.captionNumber += 1 self.buildContentElement(par) img.tail = "\n" - if self.stripTitle: - del img.attrib["title"] par.append(img) self.buildCaptionElement(par, img.get("title")) + if self.stripTitle: + del img.attrib["title"] class captionExtension(Extension): def __init__(self, **kwargs):