mdreader / app.py
RP-Azul's picture
Update app.py
0c7bb1d verified
raw
history blame
1.29 kB
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"])