-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path文本规范化.lua
106 lines (79 loc) · 2.51 KB
/
文本规范化.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
local gt=aegisub.gettext
script_name = gt"文本规范化"
script_description = gt"按自定义标准规范化文本"
script_author = "op200"
script_version = "0.1"
-- https://github.com/op200/Tag-Replace_for_Aegisub
local function debug(text)
aegisub.dialog.display({{class="label",label=tostring(text):gsub("&", "&&")}})
end
local replace_table={
{"吗%?$","吗"},{"吧%?$","吧"},{"呢%?$","呢"},{"吗?$","吗"},{"吧?$","吧"},{"呢?$","呢"},
{"吗%?","吗 "},{"吧%?","吧 "},{"呢%?","呢 "},{"吗?","吗 "},{"吧?","吧 "},{"呢?","呢 "},
{"“([^“”]*)”","\"".."%1".."\""},{"“([^“”]*)“","\"".."%1".."\""},
{"”([^“”]*)”","\"".."%1".."\""},{"”([^“”]*)“","\"".."%1".."\""},
{"帐号","账户"},{"锻链","锻炼"}
}
local warning_table={
"!","%-","—","`","%.%.",
"[%(%)]","(",")"
}
local function find_event(sub)
for i=1,#sub do
if sub[i].section=="[Events]" then
return i
end
end
end
local function mark(sub, line_num)
local new = sub[line_num]
new.actor = new.actor.."[文本规范化 WARNING]"
sub[line_num] = new
end
local function unmark(sub, line_num)
local new = sub[line_num]
new.actor = new.actor:gsub("%[文本规范化 WARNING%]","")
sub[line_num] = new
end
local function initialize(sub,begin)
for i = begin,#sub do
unmark(sub,i)
end
end
local function replace(sub, line_num)
local new = sub[line_num]
local text = new.text
for _,compare in ipairs(replace_table) do
text = text:gsub(compare[1],compare[2])
end
new.text = text
sub[line_num] = new
end
local function warning(sub, line_num)
local new = sub[line_num]
local text = new.text
for _,compare in ipairs(warning_table) do
if text:gsub("{[^}]-}",""):find(compare) then
mark(sub, line_num)
return
end
end
end
local function do_macro(sub)
local begin = find_event(sub)
initialize(sub,begin)
for i = begin,#sub do
if not sub[i].comment and not sub[i].style:find("[oO][pP]") and not sub[i].style:find("[eE][dD]") then
replace(sub,i)
warning(sub,i)
end
end
end
local function macro_processing_function(subtitles)
do_macro(subtitles)
end
local function macro_processing_function_initialize(subtitles)
initialize(subtitles,find_event(subtitles))
end
aegisub.register_macro(script_name, script_description, macro_processing_function)
aegisub.register_macro(gt"清除文本规范化标记", gt"清除文本规范化标记", macro_processing_function_initialize)