Skip to content

Commit

Permalink
More refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
flywire committed Jul 16, 2020
1 parent 465f811 commit a08563b
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions caption/caption.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a08563b

Please sign in to comment.