列表编号
Number a list of lines, then keep counting in the next node
- 输出
- 接续编号
Numbering lines sounds like a solved problem until you're in ComfyUI and realize there's no loop index to reach for. It comes up constantly: you have a block of prompts and want them labelled 1., 2., 3. so you can tell which output frame belongs to which line; or you're generating shot descriptions and need the sequence unmistakable in the final text. 列表编号 (YanhuoListNumber) is the tiny node that does it - and it has one trick that makes it more than a formatter.
How it works
Inputs are 文本 (multiline), 起始编号 (default 1), 编号前缀, 编号后缀, 输出模式 (列表 / 合并文本) and 合并间隔符 (default \n, used only in merge-text mode). It splits the text on newlines, drops blank lines, and produces 前缀 + number + 后缀 + line for each one, numbering up from your start value.
The gotcha hiding in that format string: there's no separator inserted between the number and the line. With both prefix and suffix empty and start at 1, apple becomes 1apple. So put the punctuation in the suffix - ". " gives you 1. apple, 编号前缀 of 第 with a suffix of 项 gives you 第1项 apple. Two string fields is not a lot of rope, but it's enough to hang yourself with the default.
Note also that 合并间隔符 accepts \n as two literal characters and converts it into a real newline. So merge-text mode with the default gives you a normal multi-line string, and setting it to something like | gives you a one-liner - handy when a prompt field eats newlines in ways you don't want.
Two outputs, and the second one is the reason to install this rather than use a text editor:
输出- the numbered lines, as a STRING list (or a single-element list when you're in merge-text mode).接续编号- an INT holding起始编号 + line count.
Wire 接续编号 into the next List Number's 起始编号 and numbering continues across nodes instead of restarting at 1. That's how you number a long script split across several text blocks without doing arithmetic by hand every time you edit the earlier one. It's a two-node pattern doing the job of a variable that ComfyUI doesn't really have.
The list output is worth a second look if you're new to how ComfyUI handles this: string lists are a real type, they get consumed per-item by some nodes and joined by others, and the author took care to return [""] rather than [] when the input is empty - because an empty list is what breaks downstream execution. That kind of defensive detail shows up all over this pack.
Where it's useful
Prompt libraries where each line is a variant and you need to know which is which in a grid of results. Shot lists and storyboards, where the numbering is part of the deliverable text. Feeding a numbered block into 文本处理 so that the 序号 segmentation mode can find those markers and split on them - numbering first and splitting second is a legitimate workflow, and it's the reason these two nodes share a pack.
Conversely: if what you want is a list of distinct prompts rather than numbered text, this node isn't doing the looping for you. ComfyUI doesn't have implicit iteration over a list in the core graph; nodes that accept a list consume it themselves.
Install
One of 16 nodes in yanhuo-easy-use - category yanhuo, Chinese node labels, MIT, v1.3.1. ComfyUI Manager → search the pack title. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/yanhuoxunxianren/yanhuo-easy-use
# restart ComfyUI
No pip install (the pack's pyproject.toml declares no dependencies) and nothing to download. Pure string work: no models, no GPU.
Common issues
"My numbers are glued to the words." Add a . to 编号后缀 or a space. The node inserts nothing between the counter and the line.
"Downstream broke on an empty input." It shouldn't - empty input returns a one-element list containing an empty string, specifically so the chain survives. If something else broke, the problem is further along.
"My numbering resets between nodes." You're feeding each node 起始编号 from a literal instead of from the previous node's 接续编号. Chain them.
"Blank lines shifted my count." They're dropped entirely, so they consume no numbers. That's usually what you want; just don't expect paragraph breaks to be preserved through this node.
"The lines merged into one line without separators." You're in 合并文本 mode with 合并间隔符 set to something that isn't a newline. Check the field - \n as two characters is the intended way to write a newline, and it's the default.
For why list-versus-string and the empty-list rule matter so much in ComfyUI's execution model, docs/knowledge/comfyui-node-plumbing.md is the explainer.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| 文本 | STRING | 输入待编号的文本列表。每行作为一组,从第一组到最后一组依次编号。 | |
| 起始编号 | INT | 1 | 编号起始值,从该数字开始递增编号。 |
| 编号前缀 | STRING | 每个编号前添加的自定义文本前缀。 | |
| 编号后缀 | STRING | 每个编号后添加的自定义文本后缀。 | |
| 输出模式 | COMBO | 列表 | ● 列表:输出为包含所有编号文本的字符串列表。 ● 合并文本:将所有带编号的文本合并成一个字符串。 |
| 合并间隔符 | STRING | \n | 仅在输出模式为"合并文本"时生效,用于分隔各条带编号的文本。 |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| 输出 | STRING | — |
| 接续编号 | INT | — |