File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <style >
2+ .page {
3+ display : flex ;
4+ flex-flow : column ;
5+ width : var (--max-page-width );
6+ }
7+ main {
8+ display : flex ;
9+ flex-flow : column ;
10+ width : var (--max-page-width );
11+ flex : 1 ;
12+ }
13+ #form {
14+ display : flex ;
15+ flex-flow : column ;
16+ gap : .3rem ;
17+ flex : 1 ;
18+ align-items : end ;
19+ width : 100% ;
20+ flex : 1 ;
21+ }
22+ #editor {
23+ flex : 1 ;
24+ width : 100% ;
25+ width : var (--max-page-width );
26+ height : 100% ;
27+ }
28+ </style >
29+
30+ <form id =" form" >
31+ <button >Run</button >
32+ <textarea id =" editor" class =" language-javascript prism-live" >export default {
33+ name: "Addition",
34+ run: (a, b) => a + b,
35+ tests: [
36+ {
37+ arg: 1,
38+ expect: 1
39+ },
40+ {
41+ args: [1, 2, 3],
42+ expect: 6
43+ },
44+ {
45+ args: [],
46+ expect: undefined
47+ },
48+ ]
49+ };
50+ </textarea >
51+
52+
53+ </form >
54+ <script type =" module" src =" https://prismjs.com/prism.js" ></script >
55+ <script type =" module" src =" https://live.prismjs.com/src/prism-live.mjs?load=javascript" ></script >
56+ <link rel =" stylesheet" href =" https://live.prismjs.com/prism-live.css" >
57+ <script type =" module" >
58+ import run from " ../src/run.js" ;
59+ const editor = document .getElementById (' editor' );
60+
61+ function runTests () {
62+ let code = editor .value ;
63+ code = code .replace (" \u200B " , " " ); // Remove zero-width space added by Prism Live
64+ import (` data:text/javascript,${ encodeURIComponent (code)} ` ).then (m => {
65+ run (m .default );
66+ });
67+ };
68+
69+ form .onsubmit = e => {
70+ e? .preventDefault ();
71+ runTests ();
72+ };
73+
74+ runTests ();
75+ < / script>
You can’t perform that action at this time.
0 commit comments