-
Notifications
You must be signed in to change notification settings - Fork 1
/
prefill-from-code-blocks.html
145 lines (142 loc) · 3.45 KB
/
prefill-from-code-blocks.html
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Sample Code</title>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
margin: 30px;
}
#container {
text-align: center;
}
h1 {
font-size: 1.5em;
}
h3 {
font-size: 1em;
margin: 0.5em;
}
a {
color: steelblue;
}
a.external::after {
content: " ↗";
}
code,
iframe.embed {
display: inline-block;
width: 60%;
}
pre {
text-align: left;
background: #f4f4f4;
border: 1px solid #ddd;
border-left: 3px solid #f36d33;
border-radius: 5px;
color: #666;
page-break-inside: avoid;
font-family: monospace;
font-size: 15px;
line-height: 1.6;
margin-bottom: 1em;
overflow: auto;
padding: 1em 1.5em;
display: block;
word-wrap: break-word;
}
iframe.embed {
display: inline-block;
border: 1px solid black;
border-radius: 5px;
resize: both;
overflow: hidden;
max-width: 90vw;
max-height: 90vh;
min-width: 60vw;
min-height: 60vh;
margin: 1em;
}
</style>
<script>
var livecodesUrl = "https://livecodes.io/";
var getCode = () =>
Array.from(document.querySelectorAll(".livecodes pre")).reduce(
(url, el) =>
el.dataset.lang
? url +
el.dataset.lang +
"=" +
encodeURIComponent(el.innerHTML) +
"&"
: url,
livecodesUrl + "?"
);
window.addEventListener("load", () => {
document.querySelector("iframe.embed.by-params").src = getCode();
document.querySelector(
"iframe.embed.by-url"
).src = `${livecodesUrl}?mode=embed&url#${location.href}`;
});
</script>
</head>
<body>
<div id="container">
<h1>
<a href="https://github.com/live-codes/livecodes">LiveCodes</a> Editors:
Auto-Prefill from Code Blocks
</h1>
<a
href="#"
target="_blank"
class="external"
onclick="this.href=`${livecodesUrl}?url#${location.href}`"
>Edit in LiveCodes (url)</a
>
-
<a
href="#"
target="_blank"
class="external"
onclick="this.href=`${getCode()}`"
>Edit in LiveCodes (query params)</a
>
<h3>HTML</h3>
<code class="livecodes">
<pre data-lang="html">
This code is in HTML code blocks
<div>With <strong>HTML</strong> <i>tags</i></div>
</pre
>
</code>
<h3>CSS</h3>
<code class="livecodes">
<pre data-lang="css">
body {
text-align: center;
}
.blue {
color: blue;
}
</pre
>
</code>
<h3>Typescript</h3>
<code class="livecodes">
<pre data-lang="typescript">
const p = document.createElement('p');
p.classList.add('blue');
p.innerHTML = 'hello from Typescript!';
document.body.appendChild(p);
</pre
>
</code>
<h3>Embedded Editor (url)</h3>
<iframe class="embed by-url"></iframe>
<h3>Embedded Editor (query params)</h3>
<iframe class="embed by-params"></iframe>
</div>
</body>
</html>