File size: 667 Bytes
08994de |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import webbrowser
import tempfile
import os
from ..base_code_interpreter import BaseCodeInterpreter
class HTML(BaseCodeInterpreter):
file_extension = "html"
proper_name = "HTML"
def __init__(self):
super().__init__()
def run(self, code):
# Create a temporary HTML file with the content
with tempfile.NamedTemporaryFile(delete=False, suffix=".html") as f:
f.write(code.encode())
# Open the HTML file with the default web browser
webbrowser.open('file://' + os.path.realpath(f.name))
yield {"output": f"Saved to {os.path.realpath(f.name)} and opened with the user's default web browser."} |