if element.parent.name == "ul":
if element.ul:
# for nested ul lists use simple spaces (pragmatic solution)
element.li.insert(0, ' ')
element.insert_before(element.find_all('li'))
element.clear()
else:
element.name = "para"
bullet_tag = soup.new_tag("bullet")
bullet_tag.string = "•"
element.insert(0, bullet_tag)
# ... and replace ol list elements with ....
if element.parent.name == "ol":
# set list id if element is the first of numbered list
if not element.find_previous_sibling():
id = random.randrange(0, 101)
if element.ol:
# nested ol list
element.li.insert(0, ' ')
element.insert_before(element.find_all('li'))
element.clear()
else:
element.name = "para"
element.insert(0, soup.new_tag("bullet"))
element.bullet.insert(0, soup.new_tag("seq"))
element.bullet.seq['id'] = id
element.bullet.insert(1, ".")
# remove tags which are not supported by reportlab (replace tags with their children tags)
for tag in soup.find_all('ul'):
tag.unwrap()
for tag in soup.find_all('ol'):
tag.unwrap()
for tag in soup.find_all('li'):
tag.unwrap()
# print paragraphs with numbers
text = soup.body.contents
paragraph_number = 1
for paragraph in text:
paragraph = str(paragraph)
# ignore empty paragraphs (created by newlines/tabs of ckeditor)
if paragraph == '\n' or paragraph == '\n\n' or paragraph == '\n\t':
continue
if "" in paragraph:
pdf.append(Paragraph(paragraph.replace('\n', '
'), stylesheet['InnerMonotypeParagraph'], str(paragraph_number)))
paragraph_number += 1
elif "" in paragraph:
pdf.append(Paragraph(paragraph, stylesheet['InnerListParagraph']))
elif "" in paragraph:
pdf.append(Paragraph(paragraph, stylesheet['InnerH1Paragraph']))
elif "" in paragraph:
pdf.append(Paragraph(paragraph, stylesheet['InnerH2Paragraph']))
elif "" in paragraph:
pdf.append(Paragraph(paragraph, stylesheet['InnerH3Paragraph']))
else:
pdf.append(Paragraph(str(paragraph), stylesheet['InnerParagraph'], str(paragraph_number)))
paragraph_number += 1
def all_motion_cover(pdf, motions):
"""Create a coverpage for all motions."""
pdf.append(Paragraph(config["motion_pdf_title"], stylesheet['Heading1']))
preamble = config["motion_pdf_preamble"]
if preamble:
pdf.append(Paragraph("%s" % preamble.replace('\r\n', '
'), stylesheet['Paragraph']))
pdf.append(Spacer(0, 0.75 * cm))
if not motions:
pdf.append(Paragraph(_("No motions available."), stylesheet['Heading3']))
else:
for motion in motions:
pdf.append(Paragraph(motion.title, stylesheet['Heading3']))