[feat] add automark

This commit is contained in:
kwaroran
2023-07-18 00:28:44 +09:00
parent 44c81e10f9
commit 1d84f0cae1
5 changed files with 69 additions and 85 deletions

View File

@@ -4,49 +4,22 @@ const reg:[RegExp,string][] = []
export function autoMarkPlugin(data:string){
if(reg.length === 0){
const pluginRegex = [
{
"in": "“|”",
"out": "\"",
"flag": "g"
},
{
"in": "|",
"out": "'",
"flag": "g"
},
{
"in": "^(?!\\d\\.)([\\wㄱ-ㅎ가-힣'])(?!.*[{<>}])|(?<=^\\[.*\\] *|^\\(.*\\) *)([\\wㄱ-ㅎ가-힣'])(?!.*[{<>}])",
"out": "<em>$1$2",
"flag": "gm"
},
{
"in": "(?<!^ +.*)(\".*|<em>.*)(?<!\")$",
"out": "$1</em>",
"flag": "gm"
},
{
"in": "(?<=<em>.*|^\".*)( +\"[\\S])|(?<=<em>.*|\" +.*)( *\\[)",
"out": "</em>$1$2",
"flag": "gm"
},
{
"in": "(?<=^\".*|<\\/em>.*)([\\S]\" +|[\\S]\"(?=[,.…ㄱ-ㅎ가-힣]))|(?<=<\\/em>.*)( *\\] *)",
"out": "$1$2<em>",
"flag": "gm"
},
{
"in": "(?<=<em>.*? +|\\[|\\[.* +|\\(|\\(.* +|\"|\".*? +)(?<!style=.*)(')|(?<=<em>)('[\\wㄱ-ㅎ가-힣])",
"out": "<strong><em>$1$2",
"flag": "gm"
},
{
"in": "(?<=<strong><em>')(.*?')(?= +.+?|[ㄱ-ㅎ가-힣?!:;,.…—-])|(?<=<strong><em>'.*)(')(?=<\\/em>|\")|(?<=\\(<strong><em>')(?=\\))",
"out": "$1$2</em></strong>",
"flag": "gm"
}
{"comment":"──── ▼ Head 스크립트 ▼ ───────────────────────────────────────────────","in":"","out":"","type":"editinput","ableFlag":false,"flag":"g"},
{"comment":"[ 💱 ]ㅤ구조변환 #1=ㅤ대사 부호 수정","in":"“|”","out":"\"","type":"editdisplay","ableFlag":false},
{"comment":"[ 💱 ]ㅤ구조변환 #2=ㅤ생각 부호 수정","in":"|","out":"'","type":"editdisplay","ableFlag":false},
{"comment":"──── ▼ Auto 스크립트 ▼ ───────────────────────────────────────────────","in":"","out":"","type":"editinput","ableFlag":false,"flag":"g"},
{"comment":"[ 🧷 ]ㅤ이탈릭체 #1=ㅤ문장 앞 묶음 추가","in":"^(?!\\d\\.)([\\wㄱ-ㅎ가-힣'])(?!.*[{<>}])|(?<=^\\[.*\\] *|^\\(.*\\) *)([\\wㄱ-ㅎ가-힣'])(?!.*[{<>}])","out":"<em>$1$2","type":"editdisplay","ableFlag":true,"flag":"gm"},
{"comment":"[ 🧷 ]ㅤ이탈릭체 #2=ㅤ문장 뒤 묶음 추가","in":"(?<!^ +.*)(\".*|<em>.*)(?<!\")$","out":"$1</em>","type":"editdisplay","ableFlag":true,"flag":"gm"},
{"comment":"[ 🧷 ]ㅤ대사묶음 #1=ㅤ대사 앞 묶음 추가","in":"(?<=<em>.*|^\".*)( +\"[\\S])|(?<=<em>.*|\" +.*)( *\\[)","out":"</em>$1$2","type":"editdisplay","ableFlag":true,"flag":"gm"},
{"comment":"[ 🧷 ]ㅤ대사묶음 #2=ㅤ대사 뒤 묶음 추가","in":"(?<=^\".*|<\\/em>.*)([\\S]\" +|[\\S]\"(?=[,.…ㄱ-ㅎ가-힣]))|(?<=<\\/em>.*)( *\\] *)","out":"$1$2<em>","type":"editdisplay","ableFlag":true,"flag":"gm"},
{"comment":"[ 🧷 ]ㅤ생각묶음 #1=ㅤ생각 앞 묶음 추가","in":"(?<=<em>.*? +|\\[|\\[.* +|\\(|\\(.* +|\"|\".*? +)(?<!style=.*)(')|(?<=<em>)('[\\wㄱ-ㅎ가-힣])","out":"<strong><em>$1$2","type":"editdisplay","ableFlag":true,"flag":"gm"},
{"comment":"[ 🧷 ]ㅤ생각묶음 #2=ㅤ생각 뒤 묶음 추가","in":"(?<=<strong><em>')(.*?')(?= +.+?|[ㄱ-ㅎ가-힣?!:;,.…—-])|(?<=<strong><em>'.*)(')(?=<\\/em>|\")|(?<=\\(<strong><em>')(?=\\))","out":"$1$2</em></strong>","type":"editdisplay","ableFlag":true,"flag":"gm"},
{"comment":"──── ▼ Key 스크립트 ▼ ────────────────────────────────────────────────","in":"","out":"","type":"editinput","ableFlag":false},
{"comment":"[ 📝 ]ㅤ추가핫키 #1=ㅤ따옴표 추가 : (`)","in":"(?<!`)`(?!`)","out":"\"","type":"editinput","ableFlag":false},
{"comment":"[ 📝 ]ㅤ추가핫키 #2=OOC 추가 : (``)","in":"^``(?!`) *(.*)$","out":"(OOC: $1)","type":"editinput","ableFlag":true,"flag":"gm"}
]
for(const r of pluginRegex){
reg.push([new RegExp(r.in, r.flag),r.out])
reg.push([new RegExp(r.in, r.ableFlag ? r.flag : 'g'),r.out])
}
}
for(let i=0;i<reg.length;i++){

View File

@@ -6,6 +6,7 @@ import { alertError, alertNormal } from "../alert";
import { language } from "src/lang";
import { selectSingleFile } from "../util";
import { risuChatParser as risuChatParserOrg } from "../parser";
import { autoMarkPlugin } from "../plugins/automark";
const dreg = /{{data}}/g
const randomness = /\|\|\|/g
@@ -139,6 +140,9 @@ export function processScriptFull(char:character|groupChat, data:string, mode:Sc
}
}
}
if(db.officialplugins.automark){
data = autoMarkPlugin(data)
}
return {data, emoChanged}
}

View File

@@ -281,6 +281,7 @@ export function setDatabase(data:Database){
data.openrouterKey ??= ''
data.openrouterRequestModel ??= 'openai/gpt-3.5-turbo'
data.toggleConfirmRecommendedPreset ??= true
data.officialplugins ??= {}
changeLanguage(data.language)
DataBase.set(data)
}
@@ -465,6 +466,9 @@ export interface Database{
language: string
translator: string
plugins: RisuPlugin[]
officialplugins: {
automark?: boolean
}
currentPluginProvider: string
zoomsize:number
lastup:string