File size: 2,794 Bytes
1d1015f
77e4580
 
1d1015f
77e4580
 
 
 
 
 
1d1015f
77e4580
 
 
 
1d1015f
77e4580
 
 
 
 
 
1d1015f
77e4580
 
1d1015f
77e4580
 
 
 
 
 
 
 
 
1d1015f
77e4580
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d1015f
77e4580
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import streamlit as st
from markdown_it import MarkdownIt
from mdit_plain.renderer import RendererPlain

# Configure the page
st.set_page_config(
    page_title="Markdown to Plain Text Converter",
    page_icon="πŸ“",
    layout="wide"
)

# Initialize the markdown parser
@st.cache_resource
def get_parser():
    return MarkdownIt(renderer_cls=RendererPlain)

# App title and description
st.title("πŸ“ Markdown to Plain Text Converter")
st.markdown("""
Convert your markdown text to plain text. Paste your markdown in the left box, 
click convert, and copy the plain text from the right box.
""")

# Create two columns
col1, col2 = st.columns(2)

# Left column - Markdown input
with col1:
    st.subheader("Markdown Input")
    markdown_input = st.text_area(
        "Paste your markdown here:",
        height=400,
        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)",
        label_visibility="collapsed"
    )

# Right column - Plain text output
with col2:
    st.subheader("Plain Text Output")
    
    if st.button("Convert", type="primary", use_container_width=True):
        if markdown_input.strip():
            try:
                parser = get_parser()
                plain_text = parser.render(markdown_input)
                
                # Display the converted text in a text area
                plain_text_output = st.text_area(
                    "Converted plain text:",
                    value=plain_text,
                    height=400,
                    label_visibility="collapsed"
                )
                
                # Add copy button
                if plain_text_output:
                    st.button(
                        "Copy to Clipboard",
                        key="copy_button",
                        use_container_width=True,
                        on_click=lambda: st.write("πŸ“‹ Text copied to clipboard! Select and copy the text above.")
                    )
                
            except Exception as e:
                st.error(f"Error converting markdown: {str(e)}")
        else:
            st.warning("Please enter some markdown text to convert.")

# Add some examples
with st.expander("πŸ’‘ Examples"):
    st.markdown("""
    **Markdown Input:**
    ```
    # Main Heading
    
    This is a paragraph with **bold** and *italic* text.
    
    ## Subheading
    
    - List item 1
    - List item 2
    - List item 3
    
    [Visit Google](https://google.com)
    ```
    
    **Plain Text Output:**
    ```
    Main Heading
    
    This is a paragraph with bold and italic text.
    
    Subheading
    
    List item 1
    List item 2
    List item 3
    
    Visit Google (https://google.com)
    ```
    """)