> ## Documentation Index
> Fetch the complete documentation index at: https://learn.workflow.dog/llms.txt
> Use this file to discover all available pages before exploring further.

# Collapse Whitespace

> Limit consecutive spaces and line breaks while preserving the text.

The **Collapse Whitespace** action shortens runs of spaces and line breaks to
configurable maximums. Use it to clean copied text without removing all
paragraph structure.

<Note>
  The source filename intentionally uses `collpase-whitespace`. The action shown
  in the workflow builder is named **Collapse Whitespace**.
</Note>

## Inputs

| Input                 | Type    | Required | Description                                                               |
| --------------------- | ------- | -------- | ------------------------------------------------------------------------- |
| **Text**              | String  | Yes      | The text to clean.                                                        |
| **Collapse Spaces**   | Boolean | No       | Limits runs of literal space characters. Defaults to `true`.              |
| **Max Spaces**        | Number  | No       | Maximum spaces left in a run. Must be non-negative; defaults to `1`.      |
| **Collapse Newlines** | Boolean | No       | Limits consecutive line breaks. Defaults to `true`.                       |
| **Max Newlines**      | Number  | No       | Maximum line breaks left in a run. Must be non-negative; defaults to `2`. |

## Outputs

| Output        | Type   | Description                                     |
| ------------- | ------ | ----------------------------------------------- |
| **Collapsed** | String | The text after the selected limits are applied. |

## How the limits work

Only runs longer than the configured maximum are changed. With the defaults:

* Two or more consecutive spaces become one space.
* Three or more consecutive line breaks become two line breaks.
* Tabs and other whitespace are left unchanged.
* Windows-style `\r\n` line breaks are normalized to `\n` only when a run is
  collapsed.

Set a maximum to `0` to remove matching runs entirely. Turn either collapse
toggle off to preserve that kind of whitespace regardless of its maximum.

<Tip>
  Use **Trim Whitespace** after this action if leading or trailing whitespace
  should also be removed.
</Tip>
