Nodes/ComfyUI-lhyNodes/CodeableString
ComfyUI Node

CodeableString

Prompts with comments, the way code should have them

By lihaoyun6·Created 12 months ago·Updated 13 days ago· 20
CodeableString
    • STRING
    value
    trim_empty_linestrue
    prev

    Every serious ComfyUI user eventually hits the wall where a prompt box is the worst documentation format ever invented. You've got a good prompt, but you've also got the three variants you tried, the notes about what each weight does, and the reminder to yourself that this one needs the negative prompt tightened. CodeableString lets you keep all of that in the box - because it understands comments.

    It's a string node that strips Python-style comments before passing the text along. # starts a comment to end of line, and '''...''' blocks are removed wholesale. The output is clean prompt text; the box you're editing can be an annotated mess. The author's own framing: "Advanced string node that support comments."

    How it works

    The mechanism is regex, done carefully. It strips triple-quoted blocks first, then whole-line # comments, then trailing #... on any line, then trailing whitespace. With trim_empty_lines on (the default) blank lines vanish too, so your comment scaffolding doesn't leave gaps in the middle of the prompt. There's one more trick: if you connect the optional prev input, the result is passed through Python's .format(), so any {} placeholder in your text gets filled by the previous node's output. That turns it into a two-stage prompt builder - build a fragment upstream, slot it into a template here.

    Inputs and outputs

    • value (STRING, multiline) - your text, comments included.
    • trim_empty_lines (BOOLEAN, default true) - drop blank lines left by stripped comments. The tooltip says it all: "Remove all blank lines."
    • prev (STRING, optional) - if connected, feeds a value into {} placeholders.

    One output: STRING, the cleaned text, ready for a CLIP Text Encode or wherever.

    Installing it

    Part of ComfyUI-lhyNodes:

    • ComfyUI Manager → search lhyNodes → Install, restart.
    • Or manually:
    cd ComfyUI/custom_nodes
    git clone https://github.com/lihaoyun6/ComfyUI-lhyNodes.git
    python -m pip install -r ComfyUI-lhyNodes/requirements.txt
    

    Restart ComfyUI.

    Where people get burned

    Two genuine traps. First, the comment stripping is greedy: a literal # inside your prompt - "hashtag #viral," a # in a character name, whatever - gets eaten along with everything after it on that line. If you ever prompt for a hashtag or a C#-style token, this node will silently delete it. Second, the .format() pass, when prev is connected, will throw if your text contains literal { or } that aren't paired placeholders - most people discover this when they format a prompt containing JSON or curly-brace weights. The fix is to only use prev when your template is actually a template. Both quirks are visible in the source, and both are worth knowing before they cost you a confusing silent-prompt-change session.

    CategorylhyNodes/Utils

    Inputs (3)

    NameTypeDefaultDescription
    valueSTRING
    trim_empty_linesBOOLEANtrueRemove all blank lines.
    prevoptSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING