Skip to content

Instantly share code, notes, and snippets.

@skorotkiewicz
Created May 18, 2026 05:47
Show Gist options
  • Select an option

  • Save skorotkiewicz/3fb4884e38358c8b30c69e51a51c8549 to your computer and use it in GitHub Desktop.

Select an option

Save skorotkiewicz/3fb4884e38358c8b30c69e51a51c8549 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Simple Editor</title>
<style>
body { font-family: sans-serif; max-width: 600px; margin: 20px auto; }
#input { width: 100%; height: 200px; }
#output { border: 1px solid #ccc; padding: 10px; min-height: 100px; }
code { background: #f4f4f4; padding: 2px 4px; }
pre { background: #f4f4f4; padding: 10px; overflow-x: auto; }
italic { font-style: italic; }
</style>
</head>
<body>
<h1>Simple Editor</h1>
<textarea id="input" placeholder="Type here..."></textarea>
<div id="output"></div>
<script>
function parse(text) {
let html = '';
const blocks = text.split(/\n\s*\n/);
for (const block of blocks) {
if (block.match(/^ /m)) {
html += '<pre>' + escapeHtml(block.replace(/^ /gm, '')) + '</pre>';
} else {
let processed = block;
processed = processed.replace(/<(\S+)>/g, '<a href="$1">$1</a>');
processed = processed.replace(/\bhttps?:\/\/[^\s<]+/g, '<a href="$&">$&</a>');
processed = processed.replace(/\\\*/g, '\x00AST\x00');
processed = processed.replace(/\*\*/g, '\x00AST\x00');
processed = processed.replace(/\*([^*]+)\*/g, '<em>$1</em>');
processed = processed.replace(/\x00AST\x00/g, '*');
const lines = processed.split('\n').map(l => l ? '<p>' + l + '</p>' : '');
html += lines.join('');
}
}
return html;
}
function escapeHtml(s) { return s.replace(/[&<>"']/g, c => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c])); }
document.getElementById('output').innerHTML = parse(document.getElementById('input').value);
document.getElementById('input').addEventListener('input', e => {
document.getElementById('output').innerHTML = parse(e.target.value);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment