add tt script

This commit is contained in:
odrling 2022-09-16 00:54:33 +02:00
parent 470752574a
commit d8dcd00c0b
No known key found for this signature in database
GPG Key ID: A0145F975F9F8B75
1 changed files with 36 additions and 0 deletions

36
tt.lua Normal file
View File

@ -0,0 +1,36 @@
local tr = aegisub.gettext
script_name = tr"Double t"
script_description = tr"Ensure k tags are in the right place with double t's"
script_author = "amoethyst"
script_version = "1.0"
local expr = "^(.-)({\\[kK][fo]?[0-9.]+[^}]-})( -t)(t.*)$"
local function _tte(subs, i)
local line = subs[i]
local before, tag, start_tt, after = line.text:match(expr)
while after ~= nil do
line.text = before .. start_tt .. tag .. after
before, tag, start_tt, after = line.text:match(expr)
end
return line
end
local function tte(subs, sel)
for _, i in ipairs(sel) do
local ok, res = pcall(_tte, subs, i)
if ok then
subs[i] = res
else
aegisub.log("error on line " .. i .. ": " .. line.text .. "\n")
aegisub.log(res .. "\n")
end
end
end
aegisub.register_macro(script_name, script_description, tte)