remove .prettify() @ pre_with_pr (bs4);

fix spaces in tables too
This commit is contained in:
Mathieu PATUREL
2017-01-26 10:43:04 +11:00
parent 48c1800065
commit 6f18e8e4a2
4 changed files with 5 additions and 14 deletions

View File

@ -96,15 +96,4 @@ def pre_with_br(html):
code = pre.find('code')
code.replaceWith(BeautifulSoup(''.join(str(node) for node in pre.contents) \
.replace('\n', '<br/>').replace(' ', '<i class="space">.</i>'), 'html.parser'))
return soup.prettify().replace('<br/>', '<br />')
while True:
obj = re.search(r'<pre (?:class="table")?>(.*?)</pre>', html, re.DOTALL)
if not obj:
break
html = list(html)
html[obj.start(0):obj.end(0)] = '<pre >' + ''.join(html[obj.start(1):obj.end(1)]) \
.replace('\n', '<br>') \
.replace(' ', '&nbsp;') + '</pre>'
html = ''.join(html)
return html
return str(soup).replace('<br/>', '<br />')