From 7b575e3fddec3f442189d3667ad838c004b8855c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Mart=C3=AD?=
Date: Thu, 3 Dec 2015 16:19:33 +0100
Subject: [PATCH] Remove need for rstrip() of txt description
---
fdroidserver/metadata.py | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/fdroidserver/metadata.py b/fdroidserver/metadata.py
index f66ebc1a..48611510 100644
--- a/fdroidserver/metadata.py
+++ b/fdroidserver/metadata.py
@@ -506,6 +506,7 @@ class DescriptionFormatter:
self.bold = False
self.ital = False
self.state = self.stNONE
+ self.laststate = self.stNONE
self.text_html = ''
self.text_txt = ''
self.html = StringIO()
@@ -525,24 +526,24 @@ class DescriptionFormatter:
self.endol()
def endpara(self):
+ self.laststate = self.state
self.state = self.stNONE
whole_para = ' '.join(self.para_lines)
self.addtext(whole_para)
self.text.write(textwrap.fill(whole_para, 80,
break_long_words=False,
break_on_hyphens=False))
- self.text.write('\n\n')
self.html.write('
')
del self.para_lines[:]
def endul(self):
self.html.write('')
- self.text.write('\n')
+ self.laststate = self.state
self.state = self.stNONE
def endol(self):
self.html.write('')
- self.text.write('\n')
+ self.laststate = self.state
self.state = self.stNONE
def formatted(self, txt, html):
@@ -622,21 +623,27 @@ class DescriptionFormatter:
self.endcur()
elif line.startswith('* '):
self.endcur([self.stUL])
- self.text.write(line)
- self.text.write('\n')
if self.state != self.stUL:
self.html.write('')
self.state = self.stUL
+ if self.laststate != self.stNONE:
+ self.text.write('\n\n')
+ else:
+ self.text.write('\n')
+ self.text.write(line)
self.html.write('- ')
self.addtext(line[1:])
self.html.write('
')
elif line.startswith('# '):
self.endcur([self.stOL])
- self.text.write(line)
- self.text.write('\n')
if self.state != self.stOL:
self.html.write('')
self.state = self.stOL
+ if self.laststate != self.stNONE:
+ self.text.write('\n\n')
+ else:
+ self.text.write('\n')
+ self.text.write(line)
self.html.write('- ')
self.addtext(line[1:])
self.html.write('
')
@@ -644,12 +651,14 @@ class DescriptionFormatter:
self.para_lines.append(line)
self.endcur([self.stPARA])
if self.state == self.stNONE:
- self.html.write('')
self.state = self.stPARA
+ if self.laststate != self.stNONE:
+ self.text.write('\n\n')
+ self.html.write('
')
def end(self):
self.endcur()
- self.text_txt = self.text.getvalue().rstrip()
+ self.text_txt = self.text.getvalue()
self.text_html = self.html.getvalue()
self.text.close()
self.html.close()