Skip to content

Commit cf2b830

Browse files
committed
fix: Text starting with ** (bold) breaks new_list method
Closes #116 Refs #116
1 parent 2a3c2fb commit cf2b830

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

mdutils/tools/MDList.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def _add_new_item(self, item: str, marker: str):
4949
def _is_there_marker_in_item(cls, item: str) -> bool:
5050
if (
5151
item.startswith("-")
52-
or item.startswith("*")
52+
or item.startswith("*") and not item.startswith("**")
5353
or item.startswith("+")
5454
or re.search(r"^(\d\.)", item)
5555
):

tests/test_mdutils.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,34 @@ def setUp(self) -> None:
4545
],
4646
"Item 5",
4747
]
48+
self.expected_bold_list = (
49+
"\n\n\n"
50+
"\n- **Item 1**\n"
51+
"- **Item 2**\n"
52+
"- **Item 3**\n"
53+
"- **Item 4**\n"
54+
" - **Item 4.1**\n"
55+
" - **Item 4.2**\n"
56+
" - **Item 4.2.1**\n"
57+
" - **Item 4.2.2**\n"
58+
" - **Item 4.3**\n"
59+
" - **Item 4.3.1**\n"
60+
"- **Item 5**\n"
61+
)
62+
self.complex_bold_items = [
63+
"**Item 1**",
64+
"**Item 2**",
65+
"**Item 3**",
66+
"**Item 4**",
67+
[
68+
"**Item 4.1**",
69+
"**Item 4.2**",
70+
["**Item 4.2.1**", "**Item 4.2.2**"],
71+
"**Item 4.3**",
72+
["**Item 4.3.1**"],
73+
],
74+
"**Item 5**",
75+
]
4876

4977
def tearDown(self):
5078
md_file = Path("Test_file.md")
@@ -486,6 +514,13 @@ def test_new_list(self):
486514
md_file.create_md_file()
487515

488516
self.assertEqual(self.expected_list, MarkDownFile.read_file("Test_file.md"))
517+
518+
def test_new_list_bold_items(self):
519+
md_file = MdUtils(file_name="Test_file", title="")
520+
md_file.new_list(self.complex_bold_items)
521+
md_file.create_md_file()
522+
523+
self.assertEqual(self.expected_bold_list, MarkDownFile.read_file("Test_file.md"))
489524

490525
def test_new_checkbox_list(self):
491526
md_file = MdUtils(file_name="Test_file", title="")

0 commit comments

Comments
 (0)