Skip to content

Commit 4ac8c4f

Browse files
authored
1 parent 3920209 commit 4ac8c4f

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

escape-entities.html

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>HTML Entity Escaper</title>
7+
<style>
8+
body {
9+
font-family: Arial, sans-serif;
10+
max-width: 600px;
11+
margin: 0 auto;
12+
padding: 20px;
13+
box-sizing: border-box;
14+
}
15+
textarea {
16+
width: 100%;
17+
height: 150px;
18+
margin-bottom: 10px;
19+
padding: 5px;
20+
box-sizing: border-box;
21+
}
22+
button {
23+
background-color: #4CAF50;
24+
border: none;
25+
color: white;
26+
padding: 10px 20px;
27+
text-align: center;
28+
text-decoration: none;
29+
display: inline-block;
30+
font-size: 16px;
31+
margin: 4px 2px;
32+
cursor: pointer;
33+
border-radius: 4px;
34+
}
35+
label {
36+
font-weight: bold;
37+
display: block;
38+
margin-top: 15px;
39+
margin-bottom: 5px;
40+
}
41+
.documentation {
42+
background-color: #f0f0f0;
43+
padding: 15px;
44+
border-radius: 4px;
45+
margin-top: 30px;
46+
}
47+
</style>
48+
</head>
49+
<body>
50+
<h1>HTML Entity Escaper</h1>
51+
<label for="input">Input:</label>
52+
<textarea id="input" placeholder="Paste your text here"></textarea>
53+
<label for="output">Output (with escaped entities):</label>
54+
<textarea id="output" readonly></textarea>
55+
<button id="copyButton">Copy to clipboard</button>
56+
57+
<div class="documentation">
58+
<h2>What this tool does:</h2>
59+
<p>This HTML Entity Escaper is a simple tool that helps you convert special characters in your text to their corresponding HTML entities. It's particularly useful when you need to display code or text containing HTML syntax on a web page without it being interpreted as actual HTML.</p>
60+
<p>The tool escapes the following characters:</p>
61+
<ul>
62+
<li><code>&</code> becomes <code>&amp;amp;</code></li>
63+
<li><code><</code> becomes <code>&amp;lt;</code></li>
64+
<li><code>></code> becomes <code>&amp;gt;</code></li>
65+
<li><code>"</code> becomes <code>&amp;quot;</code></li>
66+
<li><code>'</code> becomes <code>&amp;#39;</code></li>
67+
</ul>
68+
<p>To use the tool, simply paste your text into the input box. The escaped version will automatically appear in the output box. You can then copy the escaped text to your clipboard using the "Copy to clipboard" button.</p>
69+
</div>
70+
71+
<script>
72+
const input = document.getElementById('input');
73+
const output = document.getElementById('output');
74+
const copyButton = document.getElementById('copyButton');
75+
76+
function escapeHTML(text) {
77+
const entities = {
78+
'&': '&amp;',
79+
'<': '&lt;',
80+
'>': '&gt;',
81+
'"': '&quot;',
82+
"'": '&#39;'
83+
};
84+
return text.replace(/[&<>"']/g, char => entities[char]);
85+
}
86+
87+
input.addEventListener('input', () => {
88+
output.value = escapeHTML(input.value);
89+
});
90+
91+
copyButton.addEventListener('click', () => {
92+
output.select();
93+
document.execCommand('copy');
94+
copyButton.textContent = 'Copied!';
95+
setTimeout(() => {
96+
copyButton.textContent = 'Copy to clipboard';
97+
}, 1500);
98+
});
99+
</script>
100+
</body>
101+
</html>

0 commit comments

Comments
 (0)