Introduce Line Batch Chunk and Remove Empty Lines utilities, and update the README to document their inputs, outputs, and behavior. This improves multiline text preprocessing in ComfyUI workflows by making chunk extraction and blank-line removal easier and more predictable.feat: add line batching and empty-line cleanup nodes Introduce Line Batch Chunk and Remove Empty Lines utilities, and update the README to document their inputs, outputs, and behavior. This improves multiline text preprocessing in ComfyUI workflows by making chunk extraction and blank-line removal easier and more predictable.
36 lines
919 B
Python
36 lines
919 B
Python
from typing import Tuple
|
|
|
|
|
|
def _remove_empty_lines(text: str) -> str:
|
|
return "\n".join(line for line in text.splitlines() if line.strip())
|
|
|
|
|
|
class RemoveEmptyLines:
|
|
"""Removes empty or whitespace-only lines from a multiline string."""
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"text": ("STRING", {"multiline": True, "default": ""}),
|
|
}
|
|
}
|
|
|
|
RETURN_TYPES = ("STRING",)
|
|
RETURN_NAMES = ("processed_text",)
|
|
FUNCTION = "process"
|
|
CATEGORY = "Text/Utils"
|
|
OUTPUT_NODE = False
|
|
|
|
def process(self, text: str) -> Tuple[str]:
|
|
if text is None:
|
|
text = ""
|
|
if not isinstance(text, str):
|
|
text = str(text)
|
|
|
|
return (_remove_empty_lines(text),)
|
|
|
|
@classmethod
|
|
def IS_CHANGED(cls, **kwargs) -> float:
|
|
text = kwargs.get("text", "") or ""
|
|
return float(len(text)) |