Separator:
Reuse
Designed to work fully offline. The source code for this tool is licensed under the MIT License
(View License)
rnd195
May 31, 2026
Last updated: 2026-06-05
---
title: "Line breaks"
author: "rnd195"
date: "2026-05-31"
categories: [text]
description: "Remove line breaks and extra spaces"
image: "linebreaks.assets/linebreaks.png"
last_updated: "2026-06-05"
---
<style>
div.linebreaks-container {
width: 100%;
}
textarea.linebreaks-common {
border: 1px solid #bebebe;
border-radius: 5px;
font-size: 11pt;
padding: 5px;
resize: vertical;
width: 100%;
margin-bottom: 1em;
}
#linebreaks-output {
background: #f7f7f7;
margin-top: 0em;
}
.separators-container {
padding-bottom: 10px;
}
.separator {
margin-left: 10px;
}
</style>
<div class="linebreaks-container">
<label for="linebreaks-input"><b>Text with line breaks</b></label>
<textarea id="linebreaks-input" class="linebreaks-common" placeholder="Paste your text here" rows=9></textarea>
<div class="separators-container">
<b>Separator:</b>
<input class="separator" type="radio" name="separator" value=" " id="sep-space" checked>
<label for="sep-space">Space</label>
<input class="separator" type="radio" name="separator" value=", " id="sep-comma">
<label for="sep-comma">Comma</label>
<input class="separator" type="radio" name="separator" value=" | " id="sep-beam">
<label for="sep-beam">Beam</label>
</div>
<label for="linebreaks-output"><b>Text without line breaks</b></label>
<textarea id="linebreaks-output" class="linebreaks-common" rows=9 readonly></textarea>
</div>
<script>
"use strict";
// Add some wait time to not trigger the linebreak removal on every keystroke
function debounce(func, wait = 100) {
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => {
func.apply(this, args);
}, wait);
};
}
function getSeparator() {
const selected = document.querySelector('input[name="separator"]:checked');
return selected.value;
}
document.addEventListener("DOMContentLoaded", () => {
var inputText = document.getElementById("linebreaks-input");
var outputText = document.getElementById("linebreaks-output");
// Replace newlines with spaces and too many spaces/tabs with single spaces
var removeLinebreaks = () => {
outputText.value = (inputText.value || "")
.split("\n")
.map((line) => line.trim().replace(/\s+/g, " "))
.filter((line) => line.length > 0)
.join(getSeparator())
.replace(/ +$/gm, "");
};
if (inputText)
inputText.addEventListener("input", debounce(removeLinebreaks));
// Select all text when clicking in the output field
if (outputText) {
outputText.addEventListener("click", () => {
outputText.select();
});
}
// Update when radio button changes
document.querySelectorAll('input[name="separator"]').forEach((radio) => {
radio.addEventListener("change", () => {
removeLinebreaks();
});
});
removeLinebreaks();
});
</script>
<p class="meta-last-updated">Last updated: {{< meta last_updated >}}</p>