ComfyUI Node

String Unescape

Get real newlines and tabs into a single-line string

By jamesWalker55·Created 3 years ago·Updated about a year ago· 215
String Unescape
    • STRING
    text

    Here's the tiny problem this solves. A single-line string field in ComfyUI can't hold an actual newline, you press Enter and nothing happens, or it submits. So if you need a line break inside that text, you're stuck typing the two literal characters \n and hoping something interprets them. JWStringUnescape is the something. Feed it text containing escape sequences like \n and \t, and it converts them into the real characters they represent: an actual newline, an actual tab.

    It's one of the string utilities in jamesWalker55's "Various ComfyUI Nodes by Type" pack, sitting in the primitive-ops file next to a pile of other little string and number helpers. Nothing glamorous. Occasionally exactly what you need.

    What "unescape" means

    When you type a backslash followed by n into a text field, you've typed two separate characters: a backslash and the letter n. That is not a newline; it just looks like the way a newline is written in code. "Unescaping" is the step that reads those escape sequences and swaps in the character they stand for. \n becomes a line break, \t becomes a tab, and so on. Programming languages do this for you automatically when they read a string literal. A ComfyUI text widget does not, which is why this node exists.

    When you'd want it

    The classic case is a prompt or a filename template where you want structure but you're stuck in a one-line field. You type your text with \n where the breaks should go, run it through JWStringUnescape, and the downstream node receives properly multi-line text. It's also handy any time you're assembling strings from pieces and want to inject a tab or newline without a dedicated multi-line widget getting in the way.

    If you already have a genuine multi-line string field to work in (this same pack ships one, and core ComfyUI has multiline text areas), you often don't need this at all, you can just press Enter. Unescape earns its keep specifically when the text is coming through a single-line path and you can't put a real line break there.

    Input and output

    • text: the string to process, escape sequences and all.

    The output is a single STRING with the escapes turned into real characters, ready to feed a prompt encoder, a filename/path builder, a save node, or another string operation.

    Installing it

    ComfyUI Manager: search "Various ComfyUI Nodes by Type" or jamesWalker55, install, restart. Manual install:

    cd ComfyUI/custom_nodes
    git clone https://github.com/jamesWalker55/comfyui-various
    

    then restart ComfyUI. No models, no dependencies.

    Small things to watch

    Don't expect it to change text that has no escape sequences in it, if there's no \n or \t in your input, the output is identical to the input. That's correct behavior, not a broken node.

    Also mind the backslashes if your text genuinely needs a literal backslash for some other reason (a Windows path, say). Unescaping treats backslash sequences as instructions, so \t in C:\temp could get read as a tab. If you're feeding it paths, be deliberate about what you actually want interpreted, or keep path-building out of this node entirely.

    CategoryjamesWalker55

    Inputs (1)

    NameTypeDefaultDescription
    textSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING