Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit f584724

Browse files
committed
render.py: Add a little spacing after each algorithm.
1 parent b686a7e commit f584724

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

scripts/render.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ def w_element(name, content=(), **attrs):
6969
return e
7070

7171
class Paragraph(list):
72-
__slots__ = ["pStyle", "numId", "ilvl"]
73-
def __init__(self, runs=(), pStyle=None, numId=None, ilvl=None):
72+
__slots__ = ["pStyle", "numId", "ilvl", "spacingAfter"]
73+
def __init__(self, runs=(), pStyle=None, numId=None, ilvl=None, spacingAfter=None):
7474
list.__init__(self, runs)
7575
self.pStyle = pStyle
7676
self.numId = numId
7777
self.ilvl = ilvl
78+
self.spacingAfter = spacingAfter
7879

7980
def to_etree(self):
8081
content = []
@@ -87,6 +88,9 @@ def to_etree(self):
8788
w_element(u"numId", val=str(self.numId)),
8889
w_element(u"ilvl", val=str(self.ilvl))
8990
]))
91+
if self.spacingAfter is not None:
92+
pPr_content.append(w_element(u"spacing", after=str(self.spacingAfter)))
93+
pPr_content.append(w_element(u"contextualSpacing"))
9094
if pPr_content:
9195
pPr = w_element(u"pPr", pPr_content)
9296
content.append(pPr)
@@ -243,9 +247,14 @@ def convert_block(e, numId=None, list_level=0):
243247
else:
244248
pStyle = "Alg4"
245249

246-
for child in e:
247-
for p in convert_li(child, numId, pStyle, list_level=list_level + 1):
248-
yield p
250+
# Put extra spacing on the last list item.
251+
paras = [p for child in e
252+
for p in convert_li(child, numId, pStyle, list_level=list_level + 1)]
253+
if tag == 'ol' and list_level == 0 and paras:
254+
paras[-1].spacingAfter = 240
255+
for p in paras:
256+
yield p
257+
249258
elif tag == "blockquote":
250259
if list_level != 0:
251260
raise Exception("can't convert a blockquote inside a list")

0 commit comments

Comments
 (0)