broadfield-dev commited on
Commit
320726b
·
verified ·
1 Parent(s): 2618cb9

Update app_logic.py

Browse files
Files changed (1) hide show
  1. 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
- space_info = {"repo_name_md": "", "owner_md": "", "files": []}
75
- current_file_path = None; current_file_content_lines = []
76
- in_file_definition = False; in_code_block = False
77
- lines = markdown_input.strip().split("\n")
78
- lines = process_commented_markdown(lines)
79
- #print(lines)
80
- for line_content_orig in lines:
81
- line_content_stripped = line_content_orig.strip()
82
- if line_content_stripped.startswith("### File:"):
83
- if current_file_path and in_file_definition:
84
- space_info["files"].append({"path": current_file_path, "content": "\n".join(current_file_content_lines)})
85
- current_file_path = line_content_stripped.replace("### File:", "").strip()
86
- current_file_content_lines = []
87
- in_file_definition = True; in_code_block = False
88
- continue
89
- if not in_file_definition:
90
- if line_content_stripped.startswith("# Space:"):
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
- if line_content_stripped.startswith("```"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  in_code_block = not in_code_block
97
- continue
98
- current_file_content_lines.append(line_content_orig)
99
- if current_file_path and in_file_definition:
100
- space_info["files"].append({"path": current_file_path, "content": "\n".join(current_file_content_lines)})
101
- space_info["files"] = [f for f in space_info["files"] if f.get("path")]
 
 
 
 
 
 
 
 
 
 
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) ---