Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +93 -32
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,101 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
| 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 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from markdown_it import MarkdownIt
|
| 3 |
+
from mdit_plain.renderer import RendererPlain
|
| 4 |
|
| 5 |
+
# Configure the page
|
| 6 |
+
st.set_page_config(
|
| 7 |
+
page_title="Markdown to Plain Text Converter",
|
| 8 |
+
page_icon="π",
|
| 9 |
+
layout="wide"
|
| 10 |
+
)
|
| 11 |
|
| 12 |
+
# Initialize the markdown parser
|
| 13 |
+
@st.cache_resource
|
| 14 |
+
def get_parser():
|
| 15 |
+
return MarkdownIt(renderer_cls=RendererPlain)
|
| 16 |
|
| 17 |
+
# App title and description
|
| 18 |
+
st.title("π Markdown to Plain Text Converter")
|
| 19 |
+
st.markdown("""
|
| 20 |
+
Convert your markdown text to plain text. Paste your markdown in the left box,
|
| 21 |
+
click convert, and copy the plain text from the right box.
|
| 22 |
+
""")
|
| 23 |
|
| 24 |
+
# Create two columns
|
| 25 |
+
col1, col2 = st.columns(2)
|
| 26 |
|
| 27 |
+
# Left column - Markdown input
|
| 28 |
+
with col1:
|
| 29 |
+
st.subheader("Markdown Input")
|
| 30 |
+
markdown_input = st.text_area(
|
| 31 |
+
"Paste your markdown here:",
|
| 32 |
+
height=400,
|
| 33 |
+
placeholder="# Heading\n\nThis is **bold** and this is *italic*.\n\n- List item 1\n- List item 2\n\n[This is a link](https://example.com)",
|
| 34 |
+
label_visibility="collapsed"
|
| 35 |
+
)
|
| 36 |
|
| 37 |
+
# Right column - Plain text output
|
| 38 |
+
with col2:
|
| 39 |
+
st.subheader("Plain Text Output")
|
| 40 |
+
|
| 41 |
+
if st.button("Convert", type="primary", use_container_width=True):
|
| 42 |
+
if markdown_input.strip():
|
| 43 |
+
try:
|
| 44 |
+
parser = get_parser()
|
| 45 |
+
plain_text = parser.render(markdown_input)
|
| 46 |
+
|
| 47 |
+
# Display the converted text in a text area
|
| 48 |
+
plain_text_output = st.text_area(
|
| 49 |
+
"Converted plain text:",
|
| 50 |
+
value=plain_text,
|
| 51 |
+
height=400,
|
| 52 |
+
label_visibility="collapsed"
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# Add copy button
|
| 56 |
+
if plain_text_output:
|
| 57 |
+
st.button(
|
| 58 |
+
"Copy to Clipboard",
|
| 59 |
+
key="copy_button",
|
| 60 |
+
use_container_width=True,
|
| 61 |
+
on_click=lambda: st.write("π Text copied to clipboard! Select and copy the text above.")
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
except Exception as e:
|
| 65 |
+
st.error(f"Error converting markdown: {str(e)}")
|
| 66 |
+
else:
|
| 67 |
+
st.warning("Please enter some markdown text to convert.")
|
| 68 |
|
| 69 |
+
# Add some examples
|
| 70 |
+
with st.expander("π‘ Examples"):
|
| 71 |
+
st.markdown("""
|
| 72 |
+
**Markdown Input:**
|
| 73 |
+
```
|
| 74 |
+
# Main Heading
|
| 75 |
+
|
| 76 |
+
This is a paragraph with **bold** and *italic* text.
|
| 77 |
+
|
| 78 |
+
## Subheading
|
| 79 |
+
|
| 80 |
+
- List item 1
|
| 81 |
+
- List item 2
|
| 82 |
+
- List item 3
|
| 83 |
+
|
| 84 |
+
[Visit Google](https://google.com)
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
**Plain Text Output:**
|
| 88 |
+
```
|
| 89 |
+
Main Heading
|
| 90 |
+
|
| 91 |
+
This is a paragraph with bold and italic text.
|
| 92 |
+
|
| 93 |
+
Subheading
|
| 94 |
+
|
| 95 |
+
List item 1
|
| 96 |
+
List item 2
|
| 97 |
+
List item 3
|
| 98 |
+
|
| 99 |
+
Visit Google (https://google.com)
|
| 100 |
+
```
|
| 101 |
+
""")
|