Spaces:
Sleeping
Sleeping
Update app_logic.py
Browse files- app_logic.py +6 -37
app_logic.py
CHANGED
@@ -63,44 +63,13 @@ def load_token_from_image_and_set_env(image_pil_object: Image.Image, password: s
|
|
63 |
|
64 |
|
65 |
def process_commented_markdown(commented_input):
|
66 |
-
"""Process a commented markdown string by stripping '# ' from
|
67 |
-
# Strip leading/trailing whitespace and split lines
|
68 |
lines = commented_input.strip().split("\n")
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
break
|
75 |
-
else:
|
76 |
-
return commented_input # No non-empty lines, return unchanged
|
77 |
-
|
78 |
-
# Only process if the first non-empty line is exactly '# # Space: ...'
|
79 |
-
if not first_non_empty_line.startswith("# # Space:"):
|
80 |
-
return commented_input # Not a commented space definition, return unchanged
|
81 |
-
|
82 |
-
cleaned_lines = []
|
83 |
-
in_code_block = False
|
84 |
-
|
85 |
-
for line in lines:
|
86 |
-
# Detect code block boundaries (handle '# ```' or '```')
|
87 |
-
if line.strip() in ("# ```", "```"):
|
88 |
-
in_code_block = not in_code_block
|
89 |
-
# Preserve backticks, strip '# ' if present
|
90 |
-
cleaned_line = line.lstrip("# ").rstrip()
|
91 |
-
cleaned_lines.append(cleaned_line)
|
92 |
-
continue
|
93 |
-
|
94 |
-
# Strip '# ' from lines that have it
|
95 |
-
cleaned_line = line.lstrip("# ")
|
96 |
-
|
97 |
-
# In code blocks, remove additional '# ' if present (handles over-commenting, e.g., Gemini)
|
98 |
-
if in_code_block and cleaned_line.startswith("# "):
|
99 |
-
cleaned_line = cleaned_line[2:]
|
100 |
-
|
101 |
-
cleaned_lines.append(cleaned_line)
|
102 |
-
|
103 |
-
return "\n".join(cleaned_lines)
|
104 |
|
105 |
|
106 |
|
|
|
63 |
|
64 |
|
65 |
def process_commented_markdown(commented_input):
|
66 |
+
"""Process a commented markdown string by stripping '# ' from each line if '# # Space:' is present."""
|
|
|
67 |
lines = commented_input.strip().split("\n")
|
68 |
+
# Check for '# # Space:' or variations (e.g., '# Space:') in any line
|
69 |
+
if any(line.strip().startswith("# # Space:") for line in lines):
|
70 |
+
cleaned_lines = [line.lstrip("# ") for line in lines]
|
71 |
+
return "\n".join(cleaned_lines)
|
72 |
+
return commented_input
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
|
75 |
|