-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunhtml.py
More file actions
38 lines (31 loc) · 1.08 KB
/
Runhtml.py
File metadata and controls
38 lines (31 loc) · 1.08 KB
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
import streamlit as st
from bs4 import BeautifulSoup
def sanitize_html(html):
soup = BeautifulSoup(html, 'html.parser')
for script in soup(["script", "style"]):
script.decompose()
return str(soup)
st.set_page_config(page_title="HTML Code Executor", layout="wide")
st.title("HTML Code Executor")
# Default HTML code
default_html = """
<!-- Enter your HTML code here -->
<h1>Hello, World!</h1>
<p>This is a sample HTML code.</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
"""
# Create a text area for HTML input
html_code = st.text_area("Enter HTML Code", value=default_html, height=300)
# Create a button to run the HTML code
if st.button("Run HTML"):
# Sanitize the HTML to remove potentially harmful elements
sanitized_html = sanitize_html(html_code)
# Display the sanitized HTML
st.subheader("Output:")
st.components.v1.html(sanitized_html, height=400)
st.markdown("---")
st.write("Note: This app executes HTML code in a restricted environment. Some operations may be limited for security reasons.")