| 2334 | } | 2334 | } |
| 2335 | | 2335 | |
| 2336 | str = str.replaceAll('"', ''); | 2336 | str = str.replaceAll('"', ''); |
| 2337 | str = str.replaceAll('"', ''); | 2337 | str = str.replaceAll('“', ''); |
| 2338 | str = str.replaceAll('\n', ', '); | 2338 | str = str.replaceAll('\n', ', '); |
| 2339 | str = str.normalize('NFD'); | 2339 | str = str.normalize('NFD'); |
| 2340 | | 2340 | |
| 2341 | // Check if using NAI Diffusion V4 models and preserve pipe (|) and hash (#) characters | 2341 | // Strip out non-alphanumeric characters barring model syntax exceptions |
| 2342 | if (extension_settings.sd.model === 'nai-diffusion-4-full' || | 2342 | str = str.replace(/[^a-zA-Z0-9.,:_(){}<>[\]\-'|#]+/g, ' '); |
| 2343 | extension_settings.sd.model === 'nai-diffusion-4-curated-preview') { | | |
| 2344 | // Keep pipe and hash characters for NAI Diffusion V4 models | | |
| 2345 | str = str.replace(/[^a-zA-Z0-9.,:_(){}<>[\]\-'|#]+/g, ' '); | | |
| 2346 | } else { | | |
| 2347 | // Original behavior for other models | | |
| 2348 | str = str.replace(/[^a-zA-Z0-9.,:_(){}<>[\]\-']+/g, ' '); | | |
| 2349 | } | | |
| 2350 | | 2343 | |
| 2351 | str = str.replace(/\s+/g, ' '); // Collapse multiple whitespaces into one | 2344 | str = str.replace(/\s+/g, ' '); // Collapse multiple whitespaces into one |
| 2352 | str = str.trim(); | 2345 | str = str.trim(); |