Nodes/Painting Coder Utils/Remove Empty Lines And Leading Spaces 📝
ComfyUI Node

Remove Empty Lines And Leading Spaces 📝

Stop fighting your own pasted prompts — clean them in one node

By jammyfu·Created 2 years ago·Updated 2 years ago· 16
Remove Empty Lines And Leading Spaces 📝
    • output
    text
    output_typeString
    remove_empty_lines_optiontrue
    remove_leading_spaces_optiontrue

    Every prompt you copy out of a shared workflow or a website comes with baggage: blank lines, stray indentation, a leading space that quietly changes how the CLIP text encoder tokenizes the first word. This node is the lint pass. It takes a block of text, strips the cruft, and hands back something clean enough to paste straight into a prompt or a LoRA training caption file.

    It's part of the Painting Coder Utils pack from jammyfu, a small collection of image-and-text helpers that all share the PaintingCoder:: namespace and the same no-frills install. Nothing here calls an API, downloads a model, or needs a key - it's regex and string work end to end.

    How it works

    The node takes your text and runs two independent cleanup passes, each controlled by its own toggle:

    • remove_empty_lines_option (on by default) drops blank lines, collapses runs of empty lines down to one, and trims leading/trailing newlines.
    • remove_leading_spaces_option (on by default) strips leading spaces on every line and then trims each line's leading/trailing whitespace.

    So this mess:

        Hello World
        
         This is a test
        
        
        Multiple empty lines above
    

    becomes, with defaults:

    Hello World
    This is a test
    Multiple empty lines above
    

    Both toggles default to on, so out of the box it does the full cleanup. Turn one off if you care about that specific thing - say you're feeding a markdown-ish block where indentation means something.

    The inputs and output that matter

    • text - the multiline string you're cleaning. This is the only required input.
    • output_type - String or List. String joins the cleaned lines back together with newlines; List hands you an actual list you can feed to nodes that expect a list of strings (like a batch text processor).
    • Output: output - the cleaned text (or list).

    One thing to know: this node doesn't display anything. If you want to see what it produced, run the output into a Show Text Plus or any display node. That trips people up more than you'd expect - you wire it in, queue the graph, and "nothing happens," because the cleaned text is just silently waiting on the output port.

    Install

    Use ComfyUI Manager and search for Painting Coder Utils, or clone it manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/jammyfu/ComfyUI_PaintingCoderUtils.git
    

    Then restart ComfyUI. The pack's requirements.txt lists numpy, Pillow, torch, and gradio - all things a working ComfyUI install already has, so there are no model downloads and no heavy surprises. If you're loading an old workflow that uses the pre-0.3.0 class names, jammyfu ships a workflow fixer tool in docs/fix/workflow_fixer.html to repair the JSON - worth knowing before you assume the node is broken.

    Where you'll actually use it

    • Cleaning pasted prompts before they hit a CLIP Text Encode, especially when the source was a multiline block with junk whitespace.
    • Formatting caption files for LoRA training, where a stray blank line or leading space can mess up the dataset parsing.
    • Normalizing text that came out of another node - several of this pack's own text nodes produce multi-line output you'll want tidied before reusing.

    It's a boring node, and that's the compliment. If you've ever stared at a workflow and wondered why "cat" with a leading space wasn't matching your tags, this is the fix.

    Category🎨Painting👓Coder/📝Text

    Inputs (4)

    NameTypeDefaultDescription
    textSTRING
    output_typeoptCOMBOString2 options: String, List
    remove_empty_lines_optionoptBOOLEANtrue
    remove_leading_spaces_optionoptBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    outputSTRING