Spaces:
Sleeping
Sleeping
| 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 | |
| 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) | |
| ``` | |
| """) | |