-
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathtext-indentation.html
More file actions
251 lines (220 loc) · 5.84 KB
/
text-indentation.html
File metadata and controls
251 lines (220 loc) · 5.84 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
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
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Indentation Tool</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: Helvetica, Arial, sans-serif;
padding: 20px;
max-width: 800px;
margin: 0 auto;
background: #f5f5f5;
}
h1 {
margin-top: 0;
color: #333;
}
.container {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
textarea {
width: 100%;
min-height: 300px;
padding: 12px;
font-size: 16px;
font-family: 'Courier New', monospace;
border: 1px solid #ddd;
border-radius: 4px;
resize: vertical;
margin-bottom: 15px;
}
.buttons {
display: flex;
gap: 10px;
flex-wrap: wrap;
}
button {
padding: 10px 20px;
font-size: 16px;
font-family: Helvetica, Arial, sans-serif;
background: #007aff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background 0.2s;
}
button:hover {
background: #0051d5;
}
button:active {
transform: translateY(1px);
}
button.remove {
background: #ff3b30;
}
button.remove:hover {
background: #d62d20;
}
button.quote {
background: #34c759;
}
button.quote:hover {
background: #28a745;
}
button.hidden {
display: none;
}
button.copy {
background: #5856d6;
}
button.copy:hover {
background: #4240a8;
}
button.copy.success {
background: #34c759;
}
</style>
</head>
<body>
<div class="container">
<h1>Text indentation tool</h1>
<textarea id="textInput" placeholder="Paste your text here..."></textarea>
<div class="buttons">
<button id="indent2">Indent 2</button>
<button id="indent4">Indent 4</button>
<button id="remove2" class="remove">Remove 2 spaces</button>
<button id="remove4" class="remove">Remove 4 spaces</button>
<button id="removeIndent" class="remove">Remove all indentation</button>
<button id="removeTrailing" class="remove">Remove trailing whitespace</button>
<button id="quote" class="quote">Quote</button>
<button id="unquote" class="remove hidden">Unquote</button>
<button id="copy" class="copy">Copy to clipboard</button>
</div>
</div>
<script type="module">
const textInput = document.getElementById('textInput');
const removeIndentBtn = document.getElementById('removeIndent');
const indent2Btn = document.getElementById('indent2');
const indent4Btn = document.getElementById('indent4');
const remove2Btn = document.getElementById('remove2');
const remove4Btn = document.getElementById('remove4');
const quoteBtn = document.getElementById('quote');
const unquoteBtn = document.getElementById('unquote');
const removeTrailingBtn = document.getElementById('removeTrailing');
const copyBtn = document.getElementById('copy');
function updateQuoteButtons() {
const text = textInput.value;
if (!text.trim()) {
unquoteBtn.classList.add('hidden');
return;
}
const lines = text.split('\n');
const nonEmptyLines = lines.filter(line => line.trim().length > 0);
const allQuoted = nonEmptyLines.length > 0 && nonEmptyLines.every(line => line.startsWith('> '));
if (allQuoted) {
unquoteBtn.classList.remove('hidden');
} else {
unquoteBtn.classList.add('hidden');
}
}
textInput.addEventListener('input', updateQuoteButtons);
removeIndentBtn.addEventListener('click', () => {
const text = textInput.value;
const lines = text.split('\n');
const processed = lines.map(line => line.replace(/^\s+/, '')).join('\n');
textInput.value = processed;
updateQuoteButtons();
});
indent2Btn.addEventListener('click', () => {
const text = textInput.value;
const lines = text.split('\n');
const processed = lines.map(line => ' ' + line).join('\n');
textInput.value = processed;
updateQuoteButtons();
});
indent4Btn.addEventListener('click', () => {
const text = textInput.value;
const lines = text.split('\n');
const processed = lines.map(line => ' ' + line).join('\n');
textInput.value = processed;
updateQuoteButtons();
});
remove2Btn.addEventListener('click', () => {
const text = textInput.value;
const lines = text.split('\n');
const processed = lines.map(line => {
if (line.startsWith(' ')) {
return line.slice(2);
}
return line;
}).join('\n');
textInput.value = processed;
updateQuoteButtons();
});
remove4Btn.addEventListener('click', () => {
const text = textInput.value;
const lines = text.split('\n');
const processed = lines.map(line => {
if (line.startsWith(' ')) {
return line.slice(4);
}
return line;
}).join('\n');
textInput.value = processed;
updateQuoteButtons();
});
quoteBtn.addEventListener('click', () => {
const text = textInput.value;
const lines = text.split('\n');
const processed = lines.map(line => '> ' + line).join('\n');
textInput.value = processed;
updateQuoteButtons();
});
unquoteBtn.addEventListener('click', () => {
const text = textInput.value;
const lines = text.split('\n');
const processed = lines.map(line => {
if (line.startsWith('> ')) {
return line.slice(2);
}
return line;
}).join('\n');
textInput.value = processed;
updateQuoteButtons();
});
removeTrailingBtn.addEventListener('click', () => {
const text = textInput.value;
const lines = text.split('\n');
const processed = lines.map(line => line.replace(/\s+$/, '')).join('\n');
textInput.value = processed;
updateQuoteButtons();
});
copyBtn.addEventListener('click', async () => {
try {
await navigator.clipboard.writeText(textInput.value);
copyBtn.textContent = 'Copied!';
copyBtn.classList.add('success');
setTimeout(() => {
copyBtn.textContent = 'Copy to clipboard';
copyBtn.classList.remove('success');
}, 2000);
} catch (err) {
copyBtn.textContent = 'Failed to copy';
setTimeout(() => {
copyBtn.textContent = 'Copy to clipboard';
}, 2000);
}
});
// Initial check
updateQuoteButtons();
</script>
</body>
</html>