114 lines
3.6 KiB
Python
114 lines
3.6 KiB
Python
import re
|
|
|
|
|
|
class TextConcatenator4Node:
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"separator": ("STRING", {"default": "; "}),
|
|
},
|
|
"optional": {
|
|
"input_1": ("STRING", {"multiline": True, "default": ""}),
|
|
"input_2": ("STRING", {"multiline": True, "default": ""}),
|
|
"input_3": ("STRING", {"multiline": True, "default": ""}),
|
|
"input_4": ("STRING", {"multiline": True, "default": ""}),
|
|
},
|
|
}
|
|
|
|
RETURN_TYPES = ("STRING",)
|
|
RETURN_NAMES = ("merged_text",)
|
|
FUNCTION = "combine_strings"
|
|
CATEGORY = "TextRandomizer/Text"
|
|
|
|
def combine_strings(
|
|
self, separator, input_1="", input_2="", input_3="", input_4=""
|
|
):
|
|
raw_fragments = [input_1, input_2, input_3, input_4]
|
|
active_fragments = []
|
|
|
|
for frag in raw_fragments:
|
|
if frag is not None:
|
|
clean_frag = str(frag).strip()
|
|
if clean_frag:
|
|
active_fragments.append(clean_frag)
|
|
|
|
if not active_fragments:
|
|
return ("",)
|
|
|
|
combined_output = separator.join(active_fragments)
|
|
combined_output = re.sub(r"\s+", " ", combined_output)
|
|
combined_output = re.sub(r",\s*,", ", ", combined_output)
|
|
combined_output = combined_output.strip().rstrip(",")
|
|
|
|
return (combined_output.strip(),)
|
|
|
|
|
|
class TextConcatenator8Node:
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"separator": ("STRING", {"default": "; "}),
|
|
},
|
|
"optional": {
|
|
# 8 dedicated, predictable slots accepting typing OR wire inputs
|
|
"input_1": ("STRING", {"multiline": True, "default": ""}),
|
|
"input_2": ("STRING", {"multiline": True, "default": ""}),
|
|
"input_3": ("STRING", {"multiline": True, "default": ""}),
|
|
"input_4": ("STRING", {"multiline": True, "default": ""}),
|
|
"input_5": ("STRING", {"multiline": True, "default": ""}),
|
|
"input_6": ("STRING", {"multiline": True, "default": ""}),
|
|
"input_7": ("STRING", {"multiline": True, "default": ""}),
|
|
"input_8": ("STRING", {"multiline": True, "default": ""}),
|
|
},
|
|
}
|
|
|
|
RETURN_TYPES = ("STRING",)
|
|
RETURN_NAMES = ("merged_text",)
|
|
FUNCTION = "combine_strings"
|
|
CATEGORY = "TextRandomizer/Text"
|
|
|
|
def combine_strings(
|
|
self,
|
|
separator,
|
|
input_1="",
|
|
input_2="",
|
|
input_3="",
|
|
input_4="",
|
|
input_5="",
|
|
input_6="",
|
|
input_7="",
|
|
input_8="",
|
|
):
|
|
# 1. Gather all 8 potential input strings
|
|
raw_fragments = [
|
|
input_1,
|
|
input_2,
|
|
input_3,
|
|
input_4,
|
|
input_5,
|
|
input_6,
|
|
input_7,
|
|
input_8,
|
|
]
|
|
active_fragments = []
|
|
|
|
# 2. Iterate and drop empty text values or skipped wires safely
|
|
for frag in raw_fragments:
|
|
if frag is not None:
|
|
clean_frag = str(frag).strip()
|
|
if clean_frag:
|
|
active_fragments.append(clean_frag)
|
|
|
|
if not active_fragments:
|
|
return ("",)
|
|
|
|
# 3. Assemble and apply standard punctuation/spacing cleanup passes
|
|
combined_output = separator.join(active_fragments)
|
|
combined_output = re.sub(r"\s+", " ", combined_output)
|
|
combined_output = re.sub(r",\s*,", ", ", combined_output)
|
|
combined_output = combined_output.strip().rstrip(",")
|
|
|
|
return (combined_output.strip(),)
|