Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
eed4f62c
Commit
eed4f62c
authored
Jun 08, 2023
by
space-nuko
Browse files
Add comment support to dynamic prompts nodes
parent
29c50954
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
1 deletion
+8
-1
web/extensions/core/dynamicPrompts.js
web/extensions/core/dynamicPrompts.js
+8
-1
No files found.
web/extensions/core/dynamicPrompts.js
View file @
eed4f62c
...
...
@@ -3,6 +3,13 @@ import { app } from "../../scripts/app.js";
// Allows for simple dynamic prompt replacement
// Inputs in the format {a|b} will have a random value of a or b chosen when the prompt is queued.
/*
* Strips C-style line and block comments from a string
*/
function
stripComments
(
str
)
{
return
str
.
replace
(
/
\/\*[\s\S]
*
?\*\/
|
\/\/
.*/g
,
''
);
}
app
.
registerExtension
({
name
:
"
Comfy.DynamicPrompts
"
,
nodeCreated
(
node
)
{
...
...
@@ -15,7 +22,7 @@ app.registerExtension({
for
(
const
widget
of
widgets
)
{
// Override the serialization of the value to resolve dynamic prompts for all widgets supporting it in this node
widget
.
serializeValue
=
(
workflowNode
,
widgetIndex
)
=>
{
let
prompt
=
widget
.
value
;
let
prompt
=
stripComments
(
widget
.
value
)
;
while
(
prompt
.
replace
(
"
\\
{
"
,
""
).
includes
(
"
{
"
)
&&
prompt
.
replace
(
"
\\
}
"
,
""
).
includes
(
"
}
"
))
{
const
startIndex
=
prompt
.
replace
(
"
\\
{
"
,
"
00
"
).
indexOf
(
"
{
"
);
const
endIndex
=
prompt
.
replace
(
"
\\
}
"
,
"
00
"
).
indexOf
(
"
}
"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment