HTML, CSS, JavaScript Playground

I created this page because I was tired of going to different websites to test out small snippets of code and because I want to test out the functionality of the code editors. I probably need to find a way to disable some JavaScript functionality later maybe using Webpack on the server.
Reference this Figma blog post to see how they handled the challenge of building a plugin system (allowing users to execute code in the browser).
Take a look at QuickJS emscripten library for executing user JavaScript on the client using QuickJS.

Why Create HTML, CSS, JavaScript Playground

Allow users to be more creative in what they add to the application rather than just constrain them with what is available in the Rich Text Editor.
Maybe allow users to insert custom HTML, CSS, and maybe JS into code editors in the future.

How To Implement CodeMirror Code Editors

The basic structure for implementing the code editor should look like this:

<div data-editor-wrapper id="ENTER_ID" >
          <div data-theme="vscode" data-codemirror="css" data-type="mid" data-placeholder="Hello World"></div>
    </div>
    <details>
      <summary></summary>
      <div class="accordion-content">
          <form>
            // select for code language
            // select for editor theme
            // Checkbox if lang is js or ts
          </form>
      </div>
    </details>

You can customize the theme, coding language, height, and initial code of the code editor by customizing the data-theme, data-codemirror, data-type, data-placeholder and attributes, respectively.
The coding language and editor theme should be one of the values seen in the sets below:

Allowed Languages and Themes

The height of the code editors is controlled by the data-type attribute, which can be set to tiny, min, mid, or full depending on if you want a code editor with a height of 150px, 200px, 250px or an editor with a min height of basically the entire page that expands downward when the user enters in more code. I included the tiny, min, and mid sizes because I might want to allow the users to insert custom html and css into lexical code editors as a decorator block. All editors are held in a code mirror object:

const CODE_MIRROR_EDITORS: {[index: string]: {editor: EditorView, language: Compartment, theme: Compartment}} = {};

Which can be used to change the theme, language, and typescript functionality of the code editors. To be able to edit the theme, language and typescript functionality of the editors, you must include a <form> inside the <div data-editor-wrapper> . The form must have an <input type="text" data-language-select /> and a <input type="text" data-theme /> to edit the coding language and theme, respectively, and a <input type="checkbox" data-typescript /> to edit the typescript functionality of the editor. These are not required, however.

How To Use HTML, CSS, JavaScript Playground

The HTML, CSS, JavaScript code below will be inserted inside the <main> tag of the page. Enter HTML, CSS, and JavaScript into the code editors below and click the Output tab to see the result. I have included code language customization just to show myself how it works.