Spaces:
Sleeping
Sleeping
File size: 704 Bytes
09321b6 |
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 |
import os
import tempfile
import webbrowser
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."
}
|