Skip to content

Commit f7b908d

Browse files
Chris1221claude
andcommitted
fix: render ListElement in mixed lists with empty key column
Previously ListElement had no to_markdown() method, crashing when a list mixed dict items (- x: 123) and plain strings (- y). Now plain string items render as a table row with an empty key and the value shown. Closes #27. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 01f4ec9 commit f7b908d

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

test/test_examples.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ def test_mixed_list_does_not_crash(self):
248248
# Regression test for issue #27
249249
output = get_output("test/yaml/mixed_list.yaml")
250250
self.assertIn("a_list_of_mixed_dict_and_str", output)
251+
self.assertIn("123", output)
252+
self.assertIn("`y`", output)
251253

252254

253255
class TestPackage(unittest.TestCase):

yamldoc/entries.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __repr__(self):
8282

8383
def non_excluded_entries(self):
8484
"""Returns a list of entries that are not excluded."""
85-
return [entry for entry in self.entries if not entry.exclude and not isinstance(entry, ListElement)]
85+
return [entry for entry in self.entries if not entry.exclude]
8686

8787
def table_header(self, schema=False):
8888
if schema:
@@ -149,7 +149,13 @@ def to_markdown(self, schema=False):
149149
@dataclass
150150
class ListElement:
151151
entry: str
152-
exclude: bool = False
152+
exclude: bool = False
153+
154+
def to_markdown(self, schema=False):
155+
if schema:
156+
return f"| | `{self.entry}` | Unknown | |"
157+
else:
158+
return f"| | `{self.entry}` | |"
153159

154160

155161
class Entry:

0 commit comments

Comments
 (0)