RP-Azul commited on
Commit
0c7bb1d
Β·
verified Β·
1 Parent(s): 24a0b74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -29
app.py CHANGED
@@ -5,7 +5,6 @@ st.set_page_config(page_title="πŸ“¦ Markdown Formatter", layout="centered")
5
  st.title("πŸ“„ Markdown Formatter App")
6
 
7
  method = st.selectbox("Choose a formatting method:", ["Select a method", "Boxing Method", "Raw Markdown"])
8
-
9
  uploaded_file = st.file_uploader("Upload a Markdown (.md) file", type=["md"])
10
 
11
  if uploaded_file and method != "Select a method":
@@ -15,39 +14,21 @@ 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
  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):
50
- with st.container(border=True):
51
- if section["header"]:
52
- st.markdown(f"#### {section['header']}")
53
- st.markdown(section["content"])
 
5
  st.title("πŸ“„ Markdown Formatter App")
6
 
7
  method = st.selectbox("Choose a formatting method:", ["Select a method", "Boxing Method", "Raw Markdown"])
 
8
  uploaded_file = st.file_uploader("Upload a Markdown (.md) file", type=["md"])
9
 
10
  if uploaded_file and method != "Select a method":
 
14
  st.markdown(markdown_text)
15
 
16
  elif method == "Boxing Method":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  def parse_markdown_into_boxes(text):
18
  pattern = r'(^#+ .*$)'
19
  parts = re.split(pattern, text, flags=re.MULTILINE)
20
  sections = []
21
 
22
+ for i in range(1, len(parts), 2):
23
+ header = parts[i].strip()
24
+ content = parts[i + 1].strip() if i + 1 < len(parts) else ""
25
+ sections.append({"header": header, "content": content})
26
 
27
  return sections
28
 
29
+ st.subheader("πŸ“¦ Formatted Output")
30
+ for section in parse_markdown_into_boxes(markdown_text):
31
+ with st.container(border=True):
32
+ if section["header"]:
33
+ st.markdown(f"#### {section['header']}")
34
+ st.markdown(section["content"])