Skip to content

Commit

Permalink
adding a dict to markdown method
Browse files Browse the repository at this point in the history
  • Loading branch information
brifordwylie committed Dec 16, 2024
1 parent 150aebd commit 4d64817
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions src/sageworks/web_interface/components/plugins/pipeline_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,37 @@ def pipeline_details(self):
str: A markdown string
"""

# Construct the markdown string
# Grab the pipeline details and construct the markdown string
details = self.current_pipeline.details()
markdown = ""
for key, value in details.items():
markdown = self.dict_to_markdown(details)
return markdown

# If the value is a list, convert it to a comma-separated string
if isinstance(value, list):
value = ", ".join(value)
def dict_to_markdown(self, dictionary: dict, indent: int = 0) -> str:
"""Convert a dictionary to a markdown string with nested list formatting.
# If the value is a dictionary, get the name
if isinstance(value, dict):
value = value.get("name", "Unknown")
Args:
dictionary (dict): A dictionary to convert to markdown.
indent (int): The current level of indentation (for nested lists).
# Add to markdown string
markdown += f"**{key}:** {value} \n"
Returns:
str: A markdown string.
"""
markdown = ""
prefix = " " * indent + "- " # Use "- " for Markdown nested list items

for key, value in dictionary.items():
if isinstance(value, dict):
# Add the key as a parent item and recurse for nested dictionary
markdown += f"{prefix}**{key}:**\n"
markdown += self.dict_to_markdown(value, indent + 1)
elif isinstance(value, list):
# Add the key as a parent item, then each list item
markdown += f"{prefix}**{key}:**\n"
for item in value:
markdown += f"{' ' * (indent + 1)}- {item}\n"
else:
# Add a plain key-value pair
markdown += f"{prefix}**{key}:** {value}\n"

return markdown

Expand Down

0 comments on commit 4d64817

Please sign in to comment.