metadata: fix text wrapping on unicode characters

We were passing the utf-8 encoded string to textwrap, which took the
bytes as characters. Hence multi-byte unicode characters (in utf-8)
would count as multiple columns, which is clearly wrong.
This commit is contained in:
Daniel Martí 2016-01-10 17:54:38 +01:00
parent 309660423c
commit 0cf2539c89

View file

@ -525,9 +525,10 @@ class DescriptionFormatter:
self.state = self.stNONE
whole_para = ' '.join(self.para_lines)
self.addtext(whole_para)
self.text.write(textwrap.fill(whole_para, 80,
wrapped = textwrap.fill(whole_para.decode('utf-8'), 80,
break_long_words=False,
break_on_hyphens=False))
break_on_hyphens=False)
self.text.write(wrapped.encode('utf-8'))
self.html.write('</p>')
del self.para_lines[:]