Update formatInfo.ts (#569)

pull/568/merge
bluelovers 2024-05-17 10:38:43 +08:00 committed by GitHub
parent 9862d69557
commit aa1504b129
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 19 additions and 3 deletions

View File

@ -1,10 +1,26 @@
import { parseFromRawInfo } from '@bluelovers/auto1111-pnginfo';
import { Converter } from '@/scripts/formatPrompt';
import { splitSmartly } from 'split-smartly2';
const formatPrompt = (prompt: string) => {
let newPrompt = prompt.replaceAll('&lt;', '<').replaceAll('&gt;', '>');
return Converter.convert(newPrompt);
let newPrompt = prompt
.replaceAll('&lt;', '<')
.replaceAll('&gt;', '>')
.replace(/^[\x00\s,,。]+$/gm, '')
.replace(/\n{2,}/g, '\n')
;
const entries = splitSmartly(newPrompt.replace(/\n/g, '<br>'), [',','','。'], {
brackets: true,
trimSeparators: true,
}) as string[];
return entries
.filter(line => line.length)
.join(', ')
.replace(/<br>/g, '\n')
.replace(/^\s+|\s+$/gm, '')
;
};
export const formatInfo = (info: string) => {