From ab515644e49161ed3345be280843d596e2435860 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Fri, 11 Dec 2015 23:04:56 -0600 Subject: [PATCH] Fix for replace_br_with_p with BS4. --- fanficfare/htmlheuristics.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fanficfare/htmlheuristics.py b/fanficfare/htmlheuristics.py index 1f1173a..6545eae 100644 --- a/fanficfare/htmlheuristics.py +++ b/fanficfare/htmlheuristics.py @@ -27,7 +27,7 @@ from . import exceptions as exceptions def replace_br_with_p(body): # Ascii character (and Unicode as well) xA0 is a non-breaking space, ascii code 160. - # However, Python Regex does not recognize it as a whitespace, so we'll be changing it to a reagular space. + # However, Python Regex does not recognize it as a whitespace, so we'll be changing it to a regular space. body = body.replace(u'\xa0', u' ') if body.find('>') == -1 or body.rfind('<') == -1: @@ -258,7 +258,9 @@ def soup_up_div(body): body = body.replace(u'
', u'[br /]') - soup = bs.BeautifulSoup(body,'html5lib') + # bs4 insists on wrapping *all* new soups in if they + # don't already have them. This way we have just the div. + soup = bs.BeautifulSoup('
'+body+'
','html5lib').find('div',id="soup_up_div") body = u'' lastElement = 1 # 1 = block, 2 = nested, 3 = invalid