Spaces:
Sleeping
Sleeping
Update app_logic.py
Browse files- app_logic.py +25 -74
app_logic.py
CHANGED
@@ -94,86 +94,37 @@ def process_commented_markdown(commented_input):
|
|
94 |
|
95 |
|
96 |
def parse_markdown(markdown_input):
|
97 |
-
"""
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
if line.startswith("# Space:"):
|
112 |
-
space_info["repo_name"] = line.replace("# Space:", "").strip()
|
113 |
-
if "/" in space_info["repo_name"]:
|
114 |
-
space_info["owner"], space_info["repo_name"] = space_info["repo_name"].split("/", 1)
|
115 |
continue
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
# Detect file in structure
|
122 |
-
if line.startswith("📄") or line.startswith("📁"):
|
123 |
-
if current_file and file_content and in_file_content:
|
124 |
-
space_info["files"].append({"path": current_file, "content": "\n".join(file_content)})
|
125 |
-
file_content = []
|
126 |
-
current_file = line[2:].strip()
|
127 |
-
in_file_content = False
|
128 |
-
in_code_block = False
|
129 |
continue
|
130 |
-
|
131 |
-
# Detect file content section
|
132 |
-
if line.startswith("### File:"):
|
133 |
-
if current_file and file_content and in_file_content:
|
134 |
-
space_info["files"].append({"path": current_file, "content": "\n".join(file_content)})
|
135 |
-
file_content = []
|
136 |
-
current_file = line.replace("### File:", "").strip()
|
137 |
-
in_file_content = True
|
138 |
-
in_code_block = False
|
139 |
-
continue
|
140 |
-
|
141 |
-
# Handle code block boundaries
|
142 |
-
if in_file_content and line == "```":
|
143 |
in_code_block = not in_code_block
|
144 |
-
if in_code_block:
|
145 |
-
file_content = [] # Start fresh for code block content
|
146 |
-
else:
|
147 |
-
# End of code block, save content if any
|
148 |
-
if current_file and file_content:
|
149 |
-
space_info["files"].append({"path": current_file, "content": "\n".join(file_content)})
|
150 |
-
file_content = []
|
151 |
-
in_file_content = False
|
152 |
continue
|
|
|
|
|
|
|
|
|
|
|
153 |
|
154 |
-
# Collect content
|
155 |
-
if in_file_content:
|
156 |
-
if in_code_block:
|
157 |
-
# Skip language identifier (first non-empty line after opening backtick)
|
158 |
-
if not file_content and line and not line.startswith("```"):
|
159 |
-
continue # Skip language line (e.g., `md`, `py`)
|
160 |
-
file_content.append(line)
|
161 |
-
else:
|
162 |
-
# Handle non-code-block content (e.g., binary file)
|
163 |
-
if line:
|
164 |
-
file_content.append(line)
|
165 |
-
else:
|
166 |
-
# End non-code-block content at empty line or next section
|
167 |
-
if current_file and file_content:
|
168 |
-
space_info["files"].append({"path": current_file, "content": "\n".join(file_content)})
|
169 |
-
file_content = []
|
170 |
-
in_file_content = False
|
171 |
-
|
172 |
-
# Append the last file
|
173 |
-
if current_file and file_content and in_file_content:
|
174 |
-
space_info["files"].append({"path": current_file, "content": "\n".join(file_content)})
|
175 |
|
176 |
-
return space_info
|
177 |
|
178 |
# --- `_determine_repo_id` (Unchanged) ---
|
179 |
def _determine_repo_id(ui_api_token_from_textbox, space_name_ui, owner_ui):
|
|
|
94 |
|
95 |
|
96 |
def parse_markdown(markdown_input):
|
97 |
+
space_info = {"repo_name_md": "", "owner_md": "", "files": []}
|
98 |
+
current_file_path = None; current_file_content_lines = []
|
99 |
+
in_file_definition = False; in_code_block = False
|
100 |
+
#markdown_clean = process_commented_markdown(markdown_input)
|
101 |
+
lines = markdown_input.strip().split("\n")
|
102 |
+
|
103 |
+
for line_content_orig in lines:
|
104 |
+
line_content_stripped = line_content_orig.strip()
|
105 |
+
if line_content_stripped.startswith("### File:"):
|
106 |
+
if current_file_path and in_file_definition:
|
107 |
+
space_info["files"].append({"path": current_file_path, "content": "\n".join(current_file_content_lines)})
|
108 |
+
current_file_path = line_content_stripped.replace("### File:", "").strip()
|
109 |
+
current_file_content_lines = []
|
110 |
+
in_file_definition = True; in_code_block = False
|
|
|
|
|
|
|
|
|
111 |
continue
|
112 |
+
if not in_file_definition:
|
113 |
+
if line_content_stripped.startswith("# Space:"):
|
114 |
+
full_space_name_md = line_content_stripped.replace("# Space:", "").strip()
|
115 |
+
if "/" in full_space_name_md: space_info["owner_md"], space_info["repo_name_md"] = full_space_name_md.split("/", 1)
|
116 |
+
else: space_info["repo_name_md"] = full_space_name_md
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
continue
|
118 |
+
if line_content_stripped.startswith("```"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
in_code_block = not in_code_block
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
continue
|
121 |
+
current_file_content_lines.append(line_content_orig)
|
122 |
+
if current_file_path and in_file_definition:
|
123 |
+
space_info["files"].append({"path": current_file_path, "content": "\n".join(current_file_content_lines)})
|
124 |
+
space_info["files"] = [f for f in space_info["files"] if f.get("path")]
|
125 |
+
return space_info
|
126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
|
|
|
128 |
|
129 |
# --- `_determine_repo_id` (Unchanged) ---
|
130 |
def _determine_repo_id(ui_api_token_from_textbox, space_name_ui, owner_ui):
|