ComfyUI Node

Text Wrap

Break a long wall of text into fixed-width lines

By wwsmiao·Created 4 months ago·Updated 4 months ago· 0
Text Wrap
    • lines
    text
    width80
    break_long_wordstrue

    TextWrap is the formatting node: it takes a long string and breaks it into lines of roughly width characters, returning a list of wrapped lines. In the wwdm-aicd pack it's the quiet one - but if you're feeding text to a display node, a console-style output, or anything where line length matters, it's the difference between readable output and a scroll.

    The inputs are text, width (default 80, minimum 4), and break_long_words (default on). The mechanism is word-based wrapping: it splits each paragraph into words and packs as many as fit on a line, like a text editor. break_long_words is the interesting toggle - when on, a single word longer than width gets chopped into width-sized chunks so no line ever exceeds the limit; when off, the word stays intact even if it blows past the width. For normal English text, on is what you want.

    Here's the detail that makes or breaks this node for the CJK crowd, and it's worth reading even if you write English: word-based wrapping only works when there are spaces to split on. Chinese and Japanese text doesn't use spaces, so split() on a Chinese sentence produces one giant "word," and the entire wrap depends on break_long_words being on - the long "word" then gets chunked character-by-character into width-sized lines. The README's own Chinese example works, but only because the default break_long_words: true is doing the heavy lifting. Turn it off on a spaceless script and you get one unwrapped blob per paragraph. So: keep it on, always, unless you have a specific reason not to.

    The output is a STRING list - one element per wrapped line. That list drops into ListOps join to re-flatten, or into TextFilterLines for a pass, or straight into a display/save node. One small behavior: blank lines in the input are preserved as empty list elements rather than dropped, which is polite for keeping paragraph structure.

    Install is the pack standard:

    cd ComfyUI/custom_nodes
    git clone https://github.com/wwsmiao/comfyui-wwdm-aicd.git
    

    Restart ComfyUI, find it under wwdm-aicd. Stdlib only, no requirements.txt in the repo despite what the README's install block implies. The author's README and source comments are in Chinese; widget labels are English.

    Honest take: this is the most niche node in the pack, and you can go a long time without touching it. It's for when output is going somewhere that cares about width - building a fixed-width text block, formatting an LLM's long answer for a preview node, or preparing text for a file that a line-based parser will read. When that day comes, it's a one-node fix. Otherwise, file it under "nice to have, costs nothing to keep installed."

    Categorywwdm-aicd

    Inputs (3)

    NameTypeDefaultDescription
    textSTRING
    widthINT804–9999
    break_long_wordsBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    linesSTRING