Skip to content

Commit

Permalink
Update formatInfo.ts (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluelovers committed May 17, 2024
1 parent 9862d69 commit aa1504b
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/modules/ImageInfo/features/formatInfo.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down

0 comments on commit aa1504b

Please sign in to comment.