format module, no para/dash
This commit is contained in:
parent
22a76589fd
commit
8b22b1d912
|
@ -17,8 +17,7 @@ install:
|
|||
$(INSTALL) prefs.lua $(STEADPATH)/prefs.lua
|
||||
$(INSTALL) snapshot.lua $(STEADPATH)/snapshot.lua
|
||||
$(INSTALL) object.lua $(STEADPATH)/object.lua
|
||||
$(INSTALL) para.lua $(STEADPATH)/para.lua
|
||||
$(INSTALL) dash.lua $(STEADPATH)/dash.lua
|
||||
$(INSTALL) format.lua $(STEADPATH)/format.lua
|
||||
|
||||
uninstall:
|
||||
$(RM) $(STEADPATH)/stead.lua
|
||||
|
|
|
@ -14,5 +14,4 @@ install:
|
|||
copy prefs.lua ..\bin\stead
|
||||
copy snapshot.lua ..\bin\stead
|
||||
copy object.lua ..\bin\stead
|
||||
copy para.lua ..\bin\stead
|
||||
copy dash.lua ..\bin\stead
|
||||
copy format.lua ..\bin\stead
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
stead.fmt = stead.hook(stead.fmt, function(f, ...)
|
||||
local r = f(unpack(arg))
|
||||
if game.codepage ~= 'UTF-8' then
|
||||
error("You can not use dash module with non UTF-8 encoding.");
|
||||
end
|
||||
if type(r) == 'string' then
|
||||
r = r:gsub('([^-])%-%-([^-])', '%1—%2');
|
||||
end
|
||||
return r;
|
||||
end)
|
32
stead/format.lua
Normal file
32
stead/format.lua
Normal file
|
@ -0,0 +1,32 @@
|
|||
format = {
|
||||
para = true;
|
||||
para_space = ' ';
|
||||
quotes = true;
|
||||
dash = true;
|
||||
filter = nil
|
||||
}
|
||||
|
||||
stead.fmt = stead.hook(stead.fmt, function(f, ...)
|
||||
local utf8
|
||||
local r = f(unpack(arg))
|
||||
if game.codepage == 'UTF-8' or game.codepage == 'utf-8' then
|
||||
utf8 = true
|
||||
end
|
||||
if type(r) == 'string' then
|
||||
if format.dash and utf8 then
|
||||
r = r:gsub('([^-])%-%-([^-])', '%1—%2');
|
||||
r = r:gsub('^%-%-([^-])', '—%1');
|
||||
end
|
||||
if format.quotes and utf8 then
|
||||
r = r:gsub('"([^"]*)"','«%1»');
|
||||
end
|
||||
if format.para and stead.state then
|
||||
r = r:gsub('\n([^\n])', '<¶>%1'):gsub('<¶>[ \t]*', '\n'..txtnb(format.para_space));
|
||||
r = r:gsub('^[ \t]*',txtnb(format.para_space))
|
||||
end
|
||||
if type(format.filter) == 'function' and stead.state then
|
||||
r = format.filter(r);
|
||||
end
|
||||
end
|
||||
return r;
|
||||
end)
|
|
@ -1,12 +0,0 @@
|
|||
para_mod = {
|
||||
space = ' ',
|
||||
}
|
||||
|
||||
stead.fmt = stead.hook(stead.fmt, function(f, ...)
|
||||
local r = f(unpack(arg))
|
||||
if type(r) == 'string' and stead.state then
|
||||
r = r:gsub('\n([^\n])', '<¶>%1'):gsub('<¶>[ \t]*', '\n'..txtnb(para_mod.space));
|
||||
r = r:gsub('^[ \t]*',txtnb(para_mod.space))
|
||||
end
|
||||
return r;
|
||||
end)
|
Loading…
Reference in a new issue