-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml-viewer-local.html
More file actions
74 lines (68 loc) · 1.89 KB
/
Copy pathhtml-viewer-local.html
File metadata and controls
74 lines (68 loc) · 1.89 KB
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
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Ace HTML Editor</title>
<!-- Ace core + HTML mode + Monokai theme -->
<script src="ace.js"></script>
<script src="mode-html.js"></script>
<script src="theme-monokai.js"></script>
<!-- js-beautify for HTML -->
<script src="beautify-html.min.js"></script>
<style>
html, body {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
background: #1e1e1e;
}
#editor {
position: absolute;
inset: 0;
font-size: 13px;
}
</style>
</head>
<body>
<div id="editor"></div>
<script>
// Global editor object that Swift talks to via evaluateJavaScript
window.editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/html");
editor.setOptions({
wrap: true,
useSoftTabs: true,
tabSize: 2,
showPrintMargin: false
});
window.showFind = function () {
ace.config.loadModule("ace/ext/searchbox", function () {
editor.execCommand("find");
});
};
// Notify Swift on each change
editor.session.on('change', function () {
if (window.webkit &&
window.webkit.messageHandlers &&
window.webkit.messageHandlers.htmlChanged) {
window.webkit.messageHandlers.htmlChanged.postMessage(editor.getValue());
}
});
</script>
// Optional: beautify the current buffer
function beautifyCurrentHTML() {
try {
var pretty = html_beautify(editor.getValue(), {
indent_size: 2,
wrap_line_length: 120
});
editor.setValue(pretty, -1);
} catch (e) {
// ignore beautify errors, keep raw content
}
}
</script>
</body>
</html>