From f12cda8f013eee7c2ca71fb7b14c803f787592c2 Mon Sep 17 00:00:00 2001 From: Slava Cherkasov Date: Wed, 12 Feb 2025 16:51:49 +0100 Subject: [PATCH] added the node for removing // comments from a text line --- nodes.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/nodes.py b/nodes.py index 0ce0250..0101092 100644 --- a/nodes.py +++ b/nodes.py @@ -237,6 +237,28 @@ class SmartSaveText: return (text,) +class SmartRemoveComments: + """ + A node that removes all lines that start with // (with optional leading whitespace) + """ + + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "text": ("STRING", {"multiline": True}), + }, + } + + RETURN_TYPES = ("STRING",) + FUNCTION = "remove_comments" + CATEGORY = "SmartHelperNodes" + + def remove_comments(self, text): + # Split text into lines, filter out comment lines, and rejoin + lines = text.splitlines() + filtered_lines = [line for line in lines if not line.strip().startswith("//")] + return ("\n".join(filtered_lines),) NODE_CLASS_MAPPINGS = { "SmartHVLoraSelect": SmartHVLoraSelect, @@ -244,6 +266,7 @@ NODE_CLASS_MAPPINGS = { "SmartFormatString": SmartFormatString, "SmartFormatString10": SmartFormatString10, "SmartSaveText": SmartSaveText, + "SmartRemoveComments": SmartRemoveComments, } NODE_DISPLAY_NAME_MAPPINGS = { @@ -252,4 +275,5 @@ NODE_DISPLAY_NAME_MAPPINGS = { "SmartFormatString": "Smart Format String", "SmartFormatString10": "Smart Format String (10 params)", "SmartSaveText": "Smart Save Text File", + "SmartRemoveComments": "Smart Remove Comments", }