-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
99 lines (86 loc) · 3.15 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Try tipograph</title>
<link rel="stylesheet" href="https://unpkg.com/hydrogen-css/dist/hydrogen.min.css"/>
<style media="screen">
body {
background-color: #dbcb90;
color: #3c3a36;
}
a {
color: #a03a38;
}
.page {
margin-top: 16px;
width: 1000px;
}
.center-block {
position: relative;
margin-left: auto;
margin-right: auto;
}
#input, #output {
font-family: serif;
font-size: 16px;
line-height: 1.5;
border: solid 1px #807659;
width: 95%;
height: 400px;
padding: 8px;
}
#input {
background-color: #ffffff;
resize: none;
}
#output {
background-color: #3c3a36;
color: #ffffff;
margin: 0;
white-space: pre-wrap;
}
</style>
</head>
<body>
<div class="page center-block">
<div class="center-block h-text-center">
<h1><a href="https://github.com/pnevyk/tipograph" target="_blank">tipograph</a> demo</h1>
<p>
<strong>Write something and see the result</strong>
</p>
</div>
<div class="h-g">
<div class="h-u h-u-6-12" class="center-block">
<textarea id="input">"When you ignore typography, you're ignoring an opportunity to improve the effectiveness of your writing." - Matthew Butterick</textarea>
</div>
<div class="h-u h-u-6-12" class="center-block">
<div id="output"></div>
</div>
</div>
</div>
<script src="https://unpkg.com/tipograph" charset="utf-8"></script>
<script type="text/javascript">
var typo = tipograph();
var input = document.getElementById('input');
var output = document.getElementById('output');
function highlight(converted, changes) {
var highlighted = '';
var last = 0;
for (var i = 0; i < changes.length; i++) {
highlighted += converted.slice(last, changes[i][1][0]);
highlighted += '<span style="background-color: #a03a38;">';
highlighted += converted.slice(changes[i][1][0], changes[i][1][1]);
highlighted += '</span>';
last = changes[i][1][1];
}
highlighted += converted.slice(last);
return highlighted;
}
output.innerHTML = typo(input.value, highlight);
input.addEventListener('input', function (e) {
output.innerHTML = typo(e.target.value, highlight);
});
</script>
</body>
</html>