diff --git a/bloom_nofos/nofos/nofo.py b/bloom_nofos/nofos/nofo.py
index cf5f6aa1..ed094d87 100644
--- a/bloom_nofos/nofos/nofo.py
+++ b/bloom_nofos/nofos/nofo.py
@@ -1265,7 +1265,7 @@ def _convert_single_item_lists_to_paragraphs(soup, cell):
This function checks if a given table cell (`
` or ` | `) contains exactly one child,
which must be a list (`` or ``) with only one list item (`- `). If such a list
- is found, it is replaced with a `
` tag containing the same text content as the list item.
+ is found, it is replaced with a ` ` tag containing the same HTML content as the list item.
Modifies:
The `cell` object is modified in place. If a matching single-item list is found,
@@ -1273,10 +1273,10 @@ def _convert_single_item_lists_to_paragraphs(soup, cell):
Example:
Input:
- |
+ |
Output:
- List item |
+ Bold list item |
"""
cell_children = list(cell.children)
if (
@@ -1285,12 +1285,13 @@ def _convert_single_item_lists_to_paragraphs(soup, cell):
and len(cell_children[0].find_all("li")) == 1
):
# Extract the text content of the single list item
- text = cell_children[0].get_text(strip=True)
- # Remove the list and replace with a paragraph
- cell_children[0].decompose()
+ li = cell_children[0].find("li", recursive=False)
+
+ # Replace with a paragraph, then remove the list
new_paragraph = soup.new_tag("p")
- new_paragraph.string = text
+ new_paragraph.extend(li.contents)
cell.append(new_paragraph)
+ cell_children[0].decompose()
def clean_table_cells(soup):
diff --git a/bloom_nofos/nofos/test_nofo.py b/bloom_nofos/nofos/test_nofo.py
index a88cecf2..d7c0bd22 100644
--- a/bloom_nofos/nofos/test_nofo.py
+++ b/bloom_nofos/nofos/test_nofo.py
@@ -164,6 +164,15 @@ def test_replace_single_item_ul_in_table_cell(self):
str(soup), ""
)
+ def test_replace_single_item_ul_in_table_cell_with_other_tags(self):
+ html = '- UL list item 1 with a link and bold formatting
| '
+ soup = BeautifulSoup(html, "html.parser")
+ clean_table_cells(soup)
+ self.assertEqual(
+ str(soup),
+ 'UL list item 1 with a link and bold formatting | ',
+ )
+
def test_replace_single_item_ol_in_table_cell(self):
html = ""
soup = BeautifulSoup(html, "html.parser")
|