1
+ script_name = " Wrap\\ Unwrap { }"
2
+ script_description = " ヽ( ゚ヮ・)ノ"
3
+ script_author = " dark_star90"
4
+ script_version = " 2.1"
5
+
6
+ -- Settings
7
+ kill_inline = true -- kill inline tags
8
+
9
+
10
+ function Kevin (subs , sel )
11
+ for x , i in ipairs (sel ) do
12
+ line = subs [i ]
13
+ line .text = line .text
14
+ :gsub (" -" ," NOTEMDASH" )
15
+ :gsub (" %(" ," FIRSTCLIP" )
16
+ :gsub (" %)" ," LASTCLIP" )
17
+ line .text = line .text
18
+ :gsub (" {" ," " )
19
+ :gsub (" }" ," " )
20
+ line .text = line .text
21
+ :gsub (" NOTEMDASH" ," -" )
22
+ :gsub (" FIRSTCLIP" ," %(" )
23
+ :gsub (" LASTCLIP" ," %)" )
24
+ subs [i ]= line
25
+ end
26
+ end
27
+
28
+ function switch (subs , sel )
29
+ for x , i in ipairs (sel ) do
30
+ line = subs [i ]
31
+ tags = line .text :match (" ^{\\ [^}]-}" )
32
+ -- keep previous commments
33
+ if line .text :match (" {<([^\\ }]-)>}" ) then line .text = line .text :gsub (" {<([^\\ }]-)>}" ," {|%1|}" ) :gsub (" {([^\\ }]-)}" ," {>%1<}" ) end
34
+ -- the actual stuff
35
+ line .text = line .text
36
+ :gsub (" -" ," NOTEMDASH" )
37
+ :gsub (" %(" ," FIRSTCLIP" )
38
+ :gsub (" %)" ," LASTCLIP" )
39
+ :gsub (" \\ N" ," _br_" ) -- save linebreak
40
+ :gsub (" {<([^\\ }]-)>}" ," {%1}" ) -- restore comment
41
+ :gsub (" {([^\\ }]-)}" ," }{<%1>}{" ) -- keep comment
42
+ :gsub (" {<>|([^\\ }]-)|<>}" ," {<%1>}" ) -- keep previous comment
43
+ :gsub (" {<>([^\\ }]-)<>}" ," %1" ) -- keep previous comment
44
+ :gsub (" ^([^{]+)" ," {%1" ) -- First { when no tags
45
+ :gsub (" ([^}]+)$" ," %1}" ) -- Last } on last collumn
46
+ :gsub (" ([^}])({\\ [^}]-})([^{])" ," %1}%2{%3" ) -- keep {} around tags
47
+ :gsub (" ^({\\ [^}]-})([^{])" ," %1{%2" ) -- First { after first set of tags
48
+ :gsub (" ([^}])({\\ [^}]-})$" ," %1}%2" )
49
+ :gsub (" {}" ," " ) -- get rid off garbage
50
+ :gsub (" _br_" ," \\ N" ) -- return linebreak
51
+ :gsub (" NOTEMDASH" ," -" )
52
+ :gsub (" FIRSTCLIP" ," %(" )
53
+ :gsub (" LASTCLIP" ," %)" )
54
+ if kill_inline == true then
55
+ line .text = line .text :gsub (" }{\\ [^}]-}{" ," " ) :gsub (" {\\ [^}]-}" ," " )
56
+ line .text = tags .. line .text
57
+ end
58
+ subs [i ]= line
59
+ end
60
+ end
61
+
62
+ -- aegisub.register_macro("unwrap", script_description, Kevin)
63
+ aegisub .register_macro (script_name , script_description , switch )
0 commit comments