-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
263 lines (236 loc) · 7.95 KB
/
index.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Text to HTML</title>
<!-- Include stylesheet -->
<link
href="https://cdn.quilljs.com/1.3.6/quill.snow.css"
rel="stylesheet"
/>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div id="main_content">
<!-- Left Content -->
<div id="left_content">
<div class="Top_Content">
<h1>Visual Editor to HTML</h1>
<div class="text_left">
<p>Press <strong> Ctrl + C </strong> to copy minified HTML.</p>
</div>
</div>
<div id="visual-editor">
<div id="editor">
<h1>Quill to HTML</h1>
Add content here.
</div>
</div>
<div id="code_output"><code id="output_html"></code></div>
<div id="code_formatted_output">
<code id="output_formatted_html"></code>
</div>
</div>
<!-- Right Content -->
<div id="right_content">
<div id="right_inner_content">
<h2>Configuration</h2>
<div id="optins">
<h3>Options</h3>
<div>
<label id="minified_html_checkbox">
<p>
<input name="formation_checkbox" type="radio" /> Minified HTML
</p>
</label>
<label id="formatted_html_checkbox">
<p>
<input name="formation_checkbox" type="radio" /> Formatted
HTML
</p>
</label>
<label id="both_html_checkbox">
<p><input name="formation_checkbox" type="radio" /> Both</p>
</label>
</div>
</div>
<div id="themes">
<h3>Themes</h3>
<input
type="radio"
class="radio_animation radio_navy_blue a06c"
name="radio_colors"
/>
<input
type="radio"
class="radio_animation radio_green a1cd05b"
name="radio_colors"
/>
<input
type="radio"
class="radio_animation radio_orange af69130"
name="radio_colors"
/>
<input
type="radio"
class="radio_animation radio_purple a754aff"
name="radio_colors"
/>
<input
type="radio"
class="radio_animation radio_black a000"
name="radio_colors"
/>
</div>
<div id="request-feature">
<!-- <a href="https://am-designers.pw/request-a-feature" target="_blank"> -->
<a href="mailto:acmegamer97@hotmail.com" target="_blank">
<button id="request_feature_button">Request a Feature</button>
</a>
</div>
</div>
</div>
</div>
</body>
<!-- Include the Quill library -->
<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<script>
// Initialize QUill editor
var toolbarOptions = [
// Headers and Font
[{ header: [1, 2, 3, 4, 5, 6, false] }],
[{ font: [] }],
// [{ size: ["small", false, "large", "huge"] }],
// Togglable buttons
[{ align: [] }],
["bold", "italic", "underline", "strike"],
["blockquote", "code-block"],
// [{ header: 1 }, { header: 2 }], // custom button values
[{ list: "ordered" }, { list: "bullet" }],
[{ script: "sub" }, { script: "super" }], // superscript/subscript
[{ indent: "-1" }, { indent: "+1" }], // outdent/indent
[{ direction: "rtl" }], // text direction
[{ color: [] }, { background: [] }], // dropdown with defaults from theme
["clean"], // remove formatting button
];
var quill = new Quill("#editor", {
modules: {
toolbar: toolbarOptions,
},
theme: "snow",
});
function updateHTML() {
document.getElementById("output_html").innerText = quill.root.innerHTML;
document.getElementById("output_formatted_html").innerText = format(
quill.root.innerHTML
);
}
quill.on("text-change", () => {
updateHTML();
});
// HTML Formatter
function format(html) {
var tab = "\t";
var result = "";
var indent = "";
html.split(/>\s*</).forEach(function (element) {
if (element.match(/^\/\w/)) {
indent = indent.substring(tab.length);
}
result += indent + "<" + element + ">\r\n";
if (element.match(/^<?\w[^>]*[^\/]$/) && !element.startsWith("input")) {
indent += tab;
}
});
return result.substring(1, result.length - 3);
}
function selectText(node) {
node = document.getElementById(node);
// Seclting Data
if (document.body.createTextRange) {
const range = document.body.createTextRange();
range.moveToElementText(node);
range.select();
} else if (window.getSelection) {
const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(node);
selection.removeAllRanges();
selection.addRange(range);
} else {
alert("Could not select text in node: Unsupported browser.");
}
}
// Performing Copy Action
document.addEventListener("copy", (event) => {
console.log("copy action initiated");
selectText("output_html");
event.clipboardData.setData("text/plain");
});
// Adding Input Check Support
document.addEventListener("keydown", function (event) {
var minified_html_checkbox = document.querySelector(
"#minified_html_checkbox > p > input"
);
var formatted_html_checkbox = document.querySelector(
"#formatted_html_checkbox > p > input"
);
var both_html_checkbox = document.querySelector(
"#both_html_checkbox > p > input"
);
// Event for Shift + f1
if (event.shiftKey && event.which == 112) {
console.log("Shift + f1, was pressed");
minified_html_checkbox.checked == false
? (minified_html_checkbox.checked = true)
: (minified_html_checkbox.checked = false);
}
// Event for Shift + f2
else if (event.shiftKey && event.which == 113) {
console.log("Shift + f2, was pressed");
formatted_html_checkbox.checked == false
? (formatted_html_checkbox.checked = true)
: (formatted_html_checkbox.checked = false);
}
// Event for Shift + f4
else if (event.shiftKey && event.which == 115) {
console.log("Shift + f4, was pressed");
both_html_checkbox.checked == false
? (both_html_checkbox.checked = true)
: (both_html_checkbox.checked = false);
}
});
// Adding Theme Change Option
var themes = document.querySelectorAll("#themes > input");
document
.getElementById("themes")
.addEventListener("change", function (event) {
for (const theme of themes) {
theme.checked == true
? (document.querySelector(
"body"
).style.background = `#${theme.classList[2].substring(1)}`)
: "";
}
});
// Minify
function minify(data) {
var minified_html = data.replace(/\s+/g, " ");
console.log(minified_html);
return minified_html;
}
// Ctrl + V directly pastes the answer
document.addEventListener("keydown", async function (event) {
if (event.ctrlKey && event.which == 86) {
console.log("Ctrl + V, was pressed");
// get data from clipboard
var data = await navigator.clipboard.readText(),
// paste minify html
minifiedHTML = await minify(data);
document.querySelector("#editor > .ql-editor").innerHTML = minifiedHTML;
}
});
</script>
</html>