Initial commit: ComfyUI-PromptComment

Add custom nodes for commenting out portions of prompts:
- PromptComment: Single marker comment stripping
- PromptCommentMultiMarker: Multi-marker support (#, //, --)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
YULE-WINDOWS\zlcbl
2026-01-21 00:47:33 +09:00
co-authored by Claude Opus 4.5
commit d8f2fa75a1
6 changed files with 447 additions and 0 deletions
+74
View File
@@ -0,0 +1,74 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# IDE
.idea/
.vscode/
*.swp
*.swo
*~
# OS
.DS_Store
Thumbs.db
# Claude temp files
tmpclaude-*
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+85
View File
@@ -0,0 +1,85 @@
# ComfyUI-PromptComment
ComfyUI のプロンプトでコメントアウト機能を提供するカスタムノードです。
[English](README_EN.md)
## 機能
プロンプト内で `#` や `//` などの記号を使ってコメントを記述できます。
コメント部分は自動的に除去され、クリーンなプロンプトが出力されます。
## インストール
### 手動インストール
```bash
cd ComfyUI/custom_nodes
git clone https://github.com/YOUR_USERNAME/ComfyUI-PromptComment.git
```
### ComfyUI Manager
ComfyUI Manager から "PromptComment" で検索してインストールできます。
## ノード
### Prompt Comment (Strip)
シンプルなコメント除去ノード。1種類のコメントマーカーを指定できます。
**入力:**
| パラメータ | 説明 |
|-----------|------|
| text | 入力プロンプト(複数行対応) |
| comment_style | コメント記法: `#`, `//`, `--`, `Custom` |
| custom_marker | comment_style が Custom の時に使用する文字列 |
| remove_empty_lines | 空行を削除するか |
| trim_whitespace | 各行の前後の空白を削除するか |
**出力:**
- `text`: コメントが除去されたプロンプト
### Prompt Comment (Multi-Marker)
複数のコメントマーカーを同時に認識するノード。
**入力:**
| パラメータ | 説明 |
|-----------|------|
| text | 入力プロンプト(複数行対応) |
| use_hash | `#` をコメントとして認識 |
| use_double_slash | `//` をコメントとして認識 |
| use_double_dash | `--` をコメントとして認識 |
| remove_empty_lines | 空行を削除するか |
| trim_whitespace | 各行の前後の空白を削除するか |
## 使用例
### 入力プロンプト:
```
masterpiece, best quality, # 品質タグ
1girl, solo, # キャラクター
blue hair, red eyes, # 外見
# sitting, standing, # ← この行は全体がコメント
smile
```
### 出力 (remove_empty_lines=True):
```
masterpiece, best quality,
1girl, solo,
blue hair, red eyes,
smile
```
## ワークフロー例
```
[String Literal] → [Prompt Comment] → [CLIP Text Encode]
(プロンプト) (コメント除去) (エンコード)
```
## ライセンス
MIT License
+85
View File
@@ -0,0 +1,85 @@
# ComfyUI-PromptComment
Custom nodes that provide comment functionality for ComfyUI prompts.
[日本語](README.md)
## Features
Write comments in your prompts using markers like `#` or `//`.
Comments are automatically removed, outputting a clean prompt.
## Installation
### Manual Installation
```bash
cd ComfyUI/custom_nodes
git clone https://github.com/YOUR_USERNAME/ComfyUI-PromptComment.git
```
### ComfyUI Manager
Search for "PromptComment" in ComfyUI Manager to install.
## Nodes
### Prompt Comment (Strip)
Simple comment removal node. Specify one type of comment marker.
**Inputs:**
| Parameter | Description |
|-----------|-------------|
| text | Input prompt (multiline supported) |
| comment_style | Comment syntax: `#`, `//`, `--`, `Custom` |
| custom_marker | String to use when comment_style is Custom |
| remove_empty_lines | Remove empty lines |
| trim_whitespace | Trim whitespace from each line |
**Output:**
- `text`: Prompt with comments removed
### Prompt Comment (Multi-Marker)
Node that recognizes multiple comment markers simultaneously.
**Inputs:**
| Parameter | Description |
|-----------|-------------|
| text | Input prompt (multiline supported) |
| use_hash | Recognize `#` as comment |
| use_double_slash | Recognize `//` as comment |
| use_double_dash | Recognize `--` as comment |
| remove_empty_lines | Remove empty lines |
| trim_whitespace | Trim whitespace from each line |
## Usage Example
### Input Prompt:
```
masterpiece, best quality, # quality tags
1girl, solo, # character
blue hair, red eyes, # appearance
# sitting, standing, # ← entire line is a comment
smile
```
### Output (remove_empty_lines=True):
```
masterpiece, best quality,
1girl, solo,
blue hair, red eyes,
smile
```
## Workflow Example
```
[String Literal] → [Prompt Comment] → [CLIP Text Encode]
(prompt) (strip comments) (encode)
```
## License
MIT License
+3
View File
@@ -0,0 +1,3 @@
from .prompt_comment import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]
+179
View File
@@ -0,0 +1,179 @@
# prompt_comment.py
#
# ComfyUI のプロンプトでコメントアウト機能を提供するノード
# 指定した記号以降のテキストを削除し、クリーンなプロンプトを出力します
#
# 対応コメント記法:
# - # (Python/Shell style)
# - // (C/JavaScript style)
# - -- (SQL style)
# - Custom (任意の文字列)
import re
class PromptComment:
"""
プロンプト内のコメントを除去するノード。
各行で指定したコメント記号以降のテキストを削除します。
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"text": ("STRING", {"multiline": True, "default": ""}),
"comment_style": (["#", "//", "--", "Custom"],),
"custom_marker": ("STRING", {"default": "#"}),
"remove_empty_lines": ("BOOLEAN", {"default": True}),
"trim_whitespace": ("BOOLEAN", {"default": True}),
}
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("text",)
FUNCTION = "strip_comments"
CATEGORY = "text/utils"
def strip_comments(
self,
text,
comment_style,
custom_marker,
remove_empty_lines,
trim_whitespace,
):
# コメントマーカーを決定
if comment_style == "Custom":
marker = custom_marker
else:
marker = comment_style
if not marker:
# マーカーが空の場合は何もしない
return (text,)
# 各行を処理
lines = text.split("\n")
processed_lines = []
for line in lines:
# コメントマーカーの位置を検索
# 文字列リテラル内のマーカーは無視しない(シンプルな実装)
marker_pos = line.find(marker)
if marker_pos != -1:
# コメントマーカー以前のテキストのみ保持
line = line[:marker_pos]
if trim_whitespace:
line = line.strip()
# 空行の処理
if remove_empty_lines:
if line: # 空でない行のみ追加
processed_lines.append(line)
else:
processed_lines.append(line)
# 行を結合
result = "\n".join(processed_lines)
# 最終的なトリム
if trim_whitespace:
result = result.strip()
return (result,)
class PromptCommentMultiMarker:
"""
複数のコメントマーカーに対応したプロンプトコメント除去ノード。
#, //, -- を同時に認識します。
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"text": ("STRING", {"multiline": True, "default": ""}),
"use_hash": ("BOOLEAN", {"default": True}), # #
"use_double_slash": ("BOOLEAN", {"default": False}), # //
"use_double_dash": ("BOOLEAN", {"default": False}), # --
"remove_empty_lines": ("BOOLEAN", {"default": True}),
"trim_whitespace": ("BOOLEAN", {"default": True}),
}
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("text",)
FUNCTION = "strip_comments"
CATEGORY = "text/utils"
def strip_comments(
self,
text,
use_hash,
use_double_slash,
use_double_dash,
remove_empty_lines,
trim_whitespace,
):
# 有効なマーカーのリストを構築
markers = []
if use_hash:
markers.append("#")
if use_double_slash:
markers.append("//")
if use_double_dash:
markers.append("--")
if not markers:
# マーカーが指定されていない場合は何もしない
return (text,)
# 各行を処理
lines = text.split("\n")
processed_lines = []
for line in lines:
# 最も早い位置にあるコメントマーカーを検索
earliest_pos = len(line)
for marker in markers:
pos = line.find(marker)
if pos != -1 and pos < earliest_pos:
earliest_pos = pos
if earliest_pos < len(line):
# コメントマーカー以前のテキストのみ保持
line = line[:earliest_pos]
if trim_whitespace:
line = line.strip()
# 空行の処理
if remove_empty_lines:
if line: # 空でない行のみ追加
processed_lines.append(line)
else:
processed_lines.append(line)
# 行を結合
result = "\n".join(processed_lines)
# 最終的なトリム
if trim_whitespace:
result = result.strip()
return (result,)
NODE_CLASS_MAPPINGS = {
"PromptComment": PromptComment,
"PromptCommentMultiMarker": PromptCommentMultiMarker,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"PromptComment": "Prompt Comment (Strip)",
"PromptCommentMultiMarker": "Prompt Comment (Multi-Marker)",
}