Nodes/EBU Workflow/EBU Encode New Lines
ComfyUI Node

EBU Encode New Lines

Squash multiline text into a single line

By burnsbert·Created about a year ago·Updated 12 months ago· 0
EBU Encode New Lines
    • encoded_text
    text
    new_line_encoding|||

    EBU Encode New Lines does one trivial thing: it replaces every literal newline in a string with a token you choose - by default ||| - producing a single-line string. Its counterpart EBU Decode New Lines reverses it. Individually they're the kind of node you'd never search for; together they solve a real annoyance.

    That annoyance: a surprising number of ComfyUI nodes - and string-handling utilities especially - behave badly with embedded newlines. Some text widgets mangle multiline values, some string nodes treat a newline as a separator, and a lot of "show this text" flows collapse or choke on multi-line input. Encoding to a single line is the classic transport trick: move the text through whatever string machinery you have, then decode it back into proper newlines at the destination.

    How it works

    It's a pure string replace: text.replace("\n", new_line_encoding). Nothing else. The input text is a multiline STRING; the new_line_encoding input (default |||) is your token. The single output encoded_text is the flattened version.

    Pick a token that can't appear naturally in your content. ||| is a reasonable default because it's rare in prose and prompts. If your text might legitimately contain |||, change the token to something else - otherwise decoding later will split mid-thought.

    The pair in practice

    The usual shape is encode → pass through string plumbing → decode. Realistic uses:

    • Feeding a multiline prompt through a node that treats newlines as list separators - encode first, decode after.
    • Storing multiline text in a single-line widget or a config file without the newline breaking the format.
    • Keeping a long prompt intact through a text switch or a string operation that strips or rewrites newlines.
    • Round-tripping through EbuAppendToFile / EbuReadFromFile where you want one logical line per file entry but the content itself is multi-line.

    It's marked as an output node, so you can also use it as a simple way to see the flattened result in the UI without wiring anything onward.

    Installing

    Part of the EBU Workflow pack - no dependencies beyond Python's standard library, no models. ComfyUI Manager (search "EBU Workflow"), or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/burnsbert/ComfyUI-EBU-Workflow
    

    then restart ComfyUI.

    Gotchas

    • The replacement is literal and global - every newline, including blank lines, becomes the token. Multi-blank-line text collapses into a run of tokens, which usually still round-trips fine, but be aware the "shape" is preserved as token runs, not blank lines.
    • If your content already contains the token, encode/decode is lossy. Choose the token to avoid collision.
    • These two nodes are mirrors of each other but nothing checks that you use matching tokens. If you encode with ||| and decode with ---, you'll get a literal mess. Keep them in the same workflow and the same token.
    CategoryUtility

    Inputs (2)

    NameTypeDefaultDescription
    textSTRING
    new_line_encodingSTRING|||

    Outputs (1)

    NameTypeDescription
    encoded_textSTRING