steed/stead/format.lua

37 lines
938 B
Lua
Raw Normal View History

2010-07-02 20:57:09 +03:00
format = {
2010-07-02 21:37:59 +03:00
para = false;
2010-07-02 20:57:09 +03:00
para_space = ' ';
2010-07-02 21:37:59 +03:00
quotes = false;
dash = false;
2010-07-02 20:57:09 +03:00
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
2010-07-03 15:38:27 +03:00
if type(r) == 'string' and stead.state then
2010-07-02 22:29:18 +03:00
if type(format.filter) == 'function' and stead.state then
r = format.filter(r);
end
2010-07-03 08:36:47 +03:00
if call_bool(format, 'dash') and utf8 then
2010-07-02 20:57:09 +03:00
r = r:gsub('([^-])%-%-([^-])', '%1—%2');
r = r:gsub('^%-%-([^-])', '—%1');
end
2010-07-03 08:36:47 +03:00
if call_bool(format, 'quotes') and utf8 then
2010-07-02 21:25:51 +03:00
r = r:gsub('_"','«'):gsub('"_',"»");
2010-07-02 20:57:09 +03:00
r = r:gsub('"([^"]*)"','«%1»');
2010-07-03 15:38:27 +03:00
r = r:gsub(',,',''):gsub("''",'');
2010-07-02 20:57:09 +03:00
end
2010-07-03 15:38:27 +03:00
if call_bool(format, 'para') then
2010-07-02 20:57:09 +03:00
r = r:gsub('\n([^\n])', '<&para;>%1'):gsub('<&para;>[ \t]*', '\n'..txtnb(format.para_space));
r = r:gsub('^[ \t]*',txtnb(format.para_space))
end
end
return r;
end)
2010-07-06 13:15:27 +03:00
-- vim:ts=4