Nodes/ZMG PLUGIN/Remove Empty Lines 🗑️
ComfyUI Node

Remove Empty Lines 🗑️

Strip blank lines out of any text, with modes for every definition of 'empty'

By fq393·Created 2 years ago·Updated 8 months ago· 8
Remove Empty Lines 🗑️
    • processed_text
    • statistics
    • removed_lines_count
    text
    modestrict
    preserve_single_emptyfalse
    trim_linestrue

    Every so often you end up with text from a file, an API, or a paste that's full of blank lines and trailing whitespace - a prompt list, a batch of filenames, a caption dump - and you want it tidy before it goes downstream. That's this node. It's a focused text cleaner with a genuinely useful set of modes, and it tells you exactly what it removed.

    How it works

    It splits your text on newlines, processes each line, and reassembles. The three modes are the interesting part:

    • strict - removes only lines that are completely empty (zero characters). A line containing spaces survives.
    • loose - removes empty lines and lines that are only whitespace. This is the one you usually want for pasted text.
    • trim_only - removes nothing; just strips leading/trailing whitespace from every line. It's a trim tool in a node's clothing.

    Then there are two quality-of-life toggles. trim_lines (on by default) strips each line's edges. preserve_single_empty keeps a single blank line where multiple empties collapsed - which is how you keep paragraph breaks in prose instead of smashing a whole document into one blob. It treats "groups" of blank lines, so a paragraph break survives as exactly one blank line.

    Inputs and outputs

    Inputs: text (multiline), mode (strict / loose / trim_only), preserve_single_empty, trim_lines. That's the whole surface - no optional extras to get lost in.

    Outputs: processed_text (the cleaned result), statistics (a summary - original line count, final count, removed count, empty-line groups, mode) and removed_lines_count (the number of lines dropped, as an INT). The stats string is plain and readable, and it's honestly the most useful output after the text itself: when you're debugging why a batch came out short, knowing how many lines got eaten is gold.

    Who it's for

    If your workflows hand-clean prompt text with a dozen text nodes, this collapses that into one node with a count output. If you never have this problem, you won't miss it - it's a niche utility, not a headline feature. The removed_lines_count output does give you a cheap way to detect "the input was empty of real content," which is sneakily handy for routing.

    Installing

    Part of the ZMG pack. ComfyUI Manager → search "ZMG" / "ComfyUI-ZMG-Nodes", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/vanche1212/ComfyUI-ZMG-Nodes
    cd ComfyUI-ZMG-Nodes
    pip install -r requirements.txt
    

    Restart; it lives under ZMGNodes/data. Pure standard-library string handling, so no extra dependencies. Set it to loose for pasted text, keep preserve_single_empty on for prose, and it just works.

    CategoryZMGNodes/data

    Inputs (4)

    NameTypeDefaultDescription
    textSTRING
    modeCOMBOstrictstrict: 去除完全空行; loose: 去除空行和仅空白字符行; trim_only: 仅去除行首尾空白
    preserve_single_emptyBOOLEANfalse是否保留单个空行(用于段落分隔)
    trim_linesBOOLEANtrue是否去除每行的首尾空白字符

    Outputs (3)

    NameTypeDescription
    processed_textSTRING
    statisticsSTRING
    removed_lines_countINT