File size: 1,290 Bytes
77c8775
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24a0b74
 
 
b28532b
0c7bb1d
 
 
 
b28532b
24a0b74
b28532b
0c7bb1d
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import streamlit as st
import re

st.set_page_config(page_title="📦 Markdown Formatter", layout="centered")
st.title("📄 Markdown Formatter App")

method = st.selectbox("Choose a formatting method:", ["Select a method", "Boxing Method", "Raw Markdown"])
uploaded_file = st.file_uploader("Upload a Markdown (.md) file", type=["md"])

if uploaded_file and method != "Select a method":
    markdown_text = uploaded_file.read().decode("utf-8")

    if method == "Raw Markdown":
        st.markdown(markdown_text)

    elif method == "Boxing Method":
        def parse_markdown_into_boxes(text):
            pattern = r'(^#+ .*$)'
            parts = re.split(pattern, text, flags=re.MULTILINE)
            sections = []

            for i in range(1, len(parts), 2):
                header = parts[i].strip()
                content = parts[i + 1].strip() if i + 1 < len(parts) else ""
                sections.append({"header": header, "content": content})

            return sections

        st.subheader("📦 Formatted Output")
        for section in parse_markdown_into_boxes(markdown_text):
            with st.container(border=True):
                if section["header"]:
                    st.markdown(f"#### {section['header']}")
                st.markdown(section["content"])