Skip to content

Instantly share code, notes, and snippets.

@ohownew
Created September 22, 2024 15:46
Show Gist options
  • Save ohownew/19747f4d3a4592db36d895033080bdc7 to your computer and use it in GitHub Desktop.
Save ohownew/19747f4d3a4592db36d895033080bdc7 to your computer and use it in GitHub Desktop.
ProcessOn to markdown
import json
with open('./file.pos', encoding='utf-8') as f:
pos_json = f.read()
pos_dict = json.loads(pos_json)
def parse_element(element, level=0):
markdown = ""
indent = " " * level
title = element.get("title", "Untitled")
markdown += f"{indent}- {title}\n"
for child in element.get("children", []):
markdown += parse_element(child, level + 1)
return markdown
def pos_to_markdown(pos_data):
"""左右子树分别解析"""
left_elements = pos_data["diagram"]["elements"]["leftChildren"]
right_elements = pos_data["diagram"]["elements"]["children"]
markdown = ""
for element in left_elements:
markdown += parse_element(element)
for element in right_elements:
markdown += parse_element(element)
return markdown
with open("./output.md", mode='wt', encoding='utf-8') as new_file:
new_file.write(pos_to_markdown(pos_dict))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment