Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from markdown import markdown
|
3 |
+
from bs4 import BeautifulSoup
|
4 |
+
import streamlit.components.v1 as components
|
5 |
+
|
6 |
+
def md_to_text(md_text):
|
7 |
+
html = markdown(md_text)
|
8 |
+
soup = BeautifulSoup(html, features='html.parser')
|
9 |
+
return soup.get_text()
|
10 |
+
|
11 |
+
def copy_button(text_to_copy):
|
12 |
+
components.html(
|
13 |
+
f"""
|
14 |
+
<textarea id="copyText" style="opacity:0;">{text_to_copy}</textarea>
|
15 |
+
<button onclick="navigator.clipboard.writeText(document.getElementById('copyText').value)">
|
16 |
+
Copy
|
17 |
+
</button>
|
18 |
+
""",
|
19 |
+
height=30,
|
20 |
+
)
|
21 |
+
|
22 |
+
st.title("Markdown to Plain Text Converter")
|
23 |
+
st.write("Paste your Markdown content below and convert it to plain text!")
|
24 |
+
|
25 |
+
# Using columns for better layout
|
26 |
+
col1, col2 = st.columns(2)
|
27 |
+
|
28 |
+
with col1:
|
29 |
+
md_input = st.text_area("Markdown Input", height=300,
|
30 |
+
placeholder="Paste your Markdown here...")
|
31 |
+
|
32 |
+
# Convert button
|
33 |
+
if st.button("Convert"):
|
34 |
+
converted_text = md_to_text(md_input)
|
35 |
+
st.session_state.converted_text = converted_text
|
36 |
+
|
37 |
+
# Display results
|
38 |
+
with col2:
|
39 |
+
if 'converted_text' in st.session_state:
|
40 |
+
st.text_area("Plain Text Output",
|
41 |
+
value=st.session_state.converted_text,
|
42 |
+
height=300,
|
43 |
+
key="output_area")
|
44 |
+
|
45 |
+
# Add copy button
|
46 |
+
if st.session_state.converted_text:
|
47 |
+
copy_button(st.session_state.converted_text)
|
48 |
+
|
49 |
+
# Optional: Add preview toggle
|
50 |
+
with st.expander("Preview Original Markdown"):
|
51 |
+
if md_input:
|
52 |
+
st.markdown(md_input, unsafe_allow_html=True)
|
53 |
+
else:
|
54 |
+
st.write("No Markdown to preview")
|
55 |
+
|
56 |
+
# How to run instructions
|
57 |
+
st.sidebar.markdown("""
|
58 |
+
**How to use:**
|
59 |
+
1. Paste your Markdown in the left panel
|
60 |
+
2. Click 'Convert'
|
61 |
+
3. Use the 'Copy' button in the right panel
|
62 |
+
4. Toggle the preview to see original formatting
|
63 |
+
""")
|