Reformat: squash newlines
1 files changed, 24 insertions(+), 12 deletions(-)

M plwiki/chemia/comp.py
M plwiki/chemia/comp.py +24 -12
@@ 121,32 121,44 @@ def extractwiki(site, reallybadfile, com
 				print >>reallybadfile, repr(comp.title)
 	return (compounds, badlist)
 
+def formatgroup(group, ch, elementopen, cntcur, cntcursiz):
+	if group:
+		if cntcursiz > 5:
+			group.insert(0, u"===%s<sub>%d</sub>===" % (ch.symbol, cntcur))
+		else:
+			if elementopen:
+				group.insert(0, "") # Additional newline
+		return "\n".join(group)
+	else:
+		return None
+
+
 def formatter(elements):
 	out = ["__NOEDITSECTION__", u"{{Spis treści}}"]
+	group = []
 	for (ch, ac) in elements.allarticles():
 		out.append(u"==%s==" % unicode(ch.wikilink))
 		ac.sort()
 		group = []
-		cntcur = 0
+		cntcur = 1
 		cntcursiz = 0
-		groupopen = False
+		elementopen = False
 		for (cnt, a) in ac:
 			if cnt > cntcur:
-				out.append("\n".join(group))
-				group = []
+				got = formatgroup(group, ch, elementopen, cntcur, cntcursiz)
+				if got:
+					out.append(got)
+					group = []
+					elementopen = True
 				cntcursiz = 0
 				cntcur = cnt
-				if groupopen:
-					groupopen = False
-
-			if cntcursiz > 5 and not groupopen:
-				out.append(u"===%s<sub>%d</sub>===" % (ch.symbol, cnt))
-				groupopen = True
 
 			group.append(u"%s" % a.wikilink())
 			cntcursiz += 1
-		out.append("\n".join(group))
-
+         
+		got = formatgroup(group, ch, elementopen, cntcur, cntcursiz)
+		if got:
+			out.append(got)
 	return out