Overview
Introduction
Pasted code or quoted text often arrives with extra leading indentation that no longer matches its new context.
Manually deleting the same number of leading characters from every line in a text editor is slow and easy to get wrong.
What Is Text Dedenter?
A dedenter that removes up to a chosen number of leading copies of an indent unit from the start of every line in a block of text.
It runs entirely client-side as part of this site's String Tools collection, so nothing you paste is ever uploaded to a server.
How Text Dedenter Works
For each line, the tool repeatedly checks whether the line starts with the indent unit and strips it, up to the chosen number of levels, stopping early on a line as soon as the indent unit no longer matches.
The transformation happens synchronously in JavaScript the moment you type, with no network round trip involved.
When To Use Text Dedenter
Use it to un-nest a block of code that was pasted from one level deeper, strip '> ' quote markers from quoted text, or remove accidental leading whitespace.
It's a fast way to get the answer without opening a code editor, a REPL, or writing a one-off script just to check.
Often used alongside Text Indenter, String Left Aligner and Whitespace Remover.
Features
Advantages
- Stops safely on lines with less indentation than requested instead of deleting unrelated content.
- Works with any indent unit, not just spaces.
- Bounds the strip line by line, so a line with less indentation than requested loses only what it actually has rather than losing real content.
Limitations
- Requires the indent unit to match exactly at the start of each line; it won't detect and normalize mixed tab/space indentation automatically.
- Strips a fixed number of levels rather than detecting the block's common indentation, so a block whose minimum indent varies is not flattened evenly.
Examples
Best Practices & Notes
Best Practices
- Set the indent unit to '> ' to quickly strip email or chat quote markers from pasted text.
- Match the indent unit to the source exactly, including whether it is spaces or a tab, since a mismatch removes nothing at all.
- Dedent before pasting a code block into markdown, where unintended leading spaces turn ordinary text into a preformatted block.
Developer Notes
Each line runs its own bounded loop that strips one copy of `indentUnit` per iteration via `startsWith`/`slice`, breaking as soon as a line no longer starts with the unit, so partially indented lines are handled gracefully rather than throwing.
Text Dedenter Use Cases
- Un-nesting a code snippet pasted one level too deep
- Stripping '> ' quote markers from quoted email or chat text
- Removing accidental leading whitespace copied from a rendered web page
Common Mistakes
- Setting the indent unit to a single space when the original text was actually indented with tabs, which causes nothing to be removed.
- Dedenting a block whose first line is already unindented, which can disguise the fact that the rest of the block was over-stripped.
Tips
- If you're not sure how many levels to remove, start with a high number; lines that run out of matching indentation are simply left as-is.
- Setting a high level count is safe, because each line stops as soon as its own indentation runs out rather than eating into the content.