From caf6a130466defff5e8de54dc1e40479fe0f9f73 Mon Sep 17 00:00:00 2001 From: "Hasko, Vladimir" Date: Wed, 19 Apr 2023 10:28:18 +0000 Subject: [PATCH] adding th fix for matches without strong element Reviewed-by: gtema Co-authored-by: Hasko, Vladimir Co-committed-by: Hasko, Vladimir --- otc_doc_convertor/convertor.py | 2 +- .../tests/unit/test_convertor.py | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/otc_doc_convertor/convertor.py b/otc_doc_convertor/convertor.py index fdfa1520..305c0c41 100644 --- a/otc_doc_convertor/convertor.py +++ b/otc_doc_convertor/convertor.py @@ -224,7 +224,7 @@ class OTCDocConvertor: # Drop strong in table headers "/" for th in soup.body.find_all("th"): - if th.p.strong: + if th.p and th.p.strong: th.p.strong.unwrap() if args and args.improve_table_headers: diff --git a/otc_doc_convertor/tests/unit/test_convertor.py b/otc_doc_convertor/tests/unit/test_convertor.py index 094b6847..82b40287 100644 --- a/otc_doc_convertor/tests/unit/test_convertor.py +++ b/otc_doc_convertor/tests/unit/test_convertor.py @@ -219,3 +219,31 @@ class TestConvertor(TestCase): str(res.find('p')), expected.strip(), ) + + def test_streamline_html_escape_16(self): + test_data= """ +

Mandatory

+ """ # noqa + expected = """ +

Mandatory

+ """ # noqa + soup = bs4.BeautifulSoup(test_data, 'lxml') + res = self.convertor.streamline_html(soup, "dummy") + self.assertEqual( + str(res.find('th')), + expected.strip(), + ) + + def test_streamline_html_escape_17(self): + test_data= """ + Mandatory + """ # noqa + expected = """ + Mandatory + """ # noqa + soup = bs4.BeautifulSoup(test_data, 'lxml') + res = self.convertor.streamline_html(soup, "dummy") + self.assertEqual( + str(res.find('th')), + expected.strip(), + )