Spaces:
Sleeping
Sleeping
Update app_logic.py
Browse files- app_logic.py +47 -26
app_logic.py
CHANGED
@@ -71,34 +71,55 @@ def process_commented_markdown(lines):
|
|
71 |
|
72 |
# --- `parse_markdown` (Unchanged from previous corrected version) ---
|
73 |
def parse_markdown(markdown_input):
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
full_space_name_md = line_content_stripped.replace("# Space:", "").strip()
|
92 |
-
if "/" in full_space_name_md: space_info["owner_md"], space_info["repo_name_md"] = full_space_name_md.split("/", 1)
|
93 |
-
else: space_info["repo_name_md"] = full_space_name_md
|
94 |
continue
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
in_code_block = not in_code_block
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
return space_info
|
103 |
|
104 |
# --- `_determine_repo_id` (Unchanged) ---
|
|
|
71 |
|
72 |
# --- `parse_markdown` (Unchanged from previous corrected version) ---
|
73 |
def parse_markdown(markdown_input):
|
74 |
+
"""Parse markdown input to extract space details and file structure."""
|
75 |
+
# Preprocess to remove comments
|
76 |
+
cleaned_markdown = process_commented_markdown(markdown_input)
|
77 |
+
space_info = {"repo_name": "", "owner": "", "files": []}
|
78 |
+
current_file = None
|
79 |
+
file_content = []
|
80 |
+
in_file_content = False
|
81 |
+
in_code_block = False
|
82 |
+
|
83 |
+
lines = cleaned_markdown.strip().split("\n")
|
84 |
+
for line in lines:
|
85 |
+
line = line.strip()
|
86 |
+
if line.startswith("# Space:"):
|
87 |
+
space_info["repo_name"] = line.replace("# Space:", "").strip()
|
88 |
+
if "/" in space_info["repo_name"]:
|
89 |
+
space_info["owner"], space_info["repo_name"] = space_info["repo_name"].split("/", 1)
|
90 |
+
elif line.startswith("## File Structure"):
|
|
|
|
|
|
|
91 |
continue
|
92 |
+
elif line.startswith("📄") or line.startswith("📁"):
|
93 |
+
if current_file and file_content and in_file_content:
|
94 |
+
space_info["files"].append({"path": current_file, "content": "\n".join(file_content)})
|
95 |
+
file_content = []
|
96 |
+
current_file = line[2:].strip()
|
97 |
+
in_file_content = False
|
98 |
+
in_code_block = False
|
99 |
+
elif line.startswith("### File:"):
|
100 |
+
if current_file and file_content and in_file_content:
|
101 |
+
space_info["files"].append({"path": current_file, "content": "\n".join(file_content)})
|
102 |
+
file_content = []
|
103 |
+
current_file = line.replace("### File:", "").strip()
|
104 |
+
in_file_content = True
|
105 |
+
in_code_block = False
|
106 |
+
elif in_file_content and line.startswith("```"):
|
107 |
in_code_block = not in_code_block
|
108 |
+
if in_code_block:
|
109 |
+
# First line after ``` is the language
|
110 |
+
file_content = []
|
111 |
+
else:
|
112 |
+
# End of code block, store file content
|
113 |
+
if current_file and file_content:
|
114 |
+
space_info["files"].append({"path": current_file, "content": "\n".join(file_content)})
|
115 |
+
file_content = []
|
116 |
+
in_file_content = False
|
117 |
+
elif in_file_content and in_code_block:
|
118 |
+
file_content.append(line)
|
119 |
+
|
120 |
+
if current_file and file_content and in_file_content:
|
121 |
+
space_info["files"].append({"path": current_file, "content": "\n".join(file_content)})
|
122 |
+
|
123 |
return space_info
|
124 |
|
125 |
# --- `_determine_repo_id` (Unchanged) ---
|