RP-Azul commited on
Commit
b28532b
·
verified ·
1 Parent(s): 6cb2ab4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -16
app.py CHANGED
@@ -15,23 +15,35 @@ if uploaded_file and method != "Select a method":
15
  st.markdown(markdown_text)
16
 
17
  elif method == "Boxing Method":
18
- # Parse markdown into boxes based on headers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  def parse_markdown_into_boxes(text):
20
- pattern = r'(^#+ .*$)'
21
- parts = re.split(pattern, text, flags=re.MULTILINE)
22
- sections = []
23
- current_section = {"header": None, "content": ""}
24
- for part in parts:
25
- if re.match(r'^#+ ', part):
26
- if current_section["header"] or current_section["content"]:
27
- sections.append(current_section)
28
- current_section = {"header": None, "content": ""}
29
- current_section["header"] = part.strip()
30
- else:
31
- current_section["content"] += part.strip() + "\n"
32
- if current_section["header"] or current_section["content"]:
33
- sections.append(current_section)
34
- return sections
35
 
36
  st.subheader("📦 Formatted Output")
37
  for section in parse_markdown_into_boxes(markdown_text):
 
15
  st.markdown(markdown_text)
16
 
17
  elif method == "Boxing Method":
18
+ # # Parse markdown into boxes based on headers
19
+ # def parse_markdown_into_boxes(text):
20
+ # pattern = r'(^#+ .*$)'
21
+ # parts = re.split(pattern, text, flags=re.MULTILINE)
22
+ # sections = []
23
+ # current_section = {"header": None, "content": ""}
24
+ # for part in parts:
25
+ # if re.match(r'^#+ ', part):
26
+ # if current_section["header"] or current_section["content"]:
27
+ # sections.append(current_section)
28
+ # current_section = {"header": None, "content": ""}
29
+ # current_section["header"] = part.strip()
30
+ # else:
31
+ # current_section["content"] += part.strip() + "\n"
32
+ # if current_section["header"] or current_section["content"]:
33
+ # sections.append(current_section)
34
+ # return sections
35
  def parse_markdown_into_boxes(text):
36
+ pattern = r'(^#+ .*$)'
37
+ parts = re.split(pattern, text, flags=re.MULTILINE)
38
+ sections = []
39
+
40
+ for i in range(1, len(parts), 2):
41
+ header = parts[i].strip()
42
+ content = parts[i+1].strip() if i+1 < len(parts) else ""
43
+ sections.append({"header": header, "content": content})
44
+
45
+ return sections
46
+
 
 
 
 
47
 
48
  st.subheader("📦 Formatted Output")
49
  for section in parse_markdown_into_boxes(markdown_text):