2013-09-07 12:06:42 +02:00
|
|
|
--[[
|
2017-09-04 12:43:00 +02:00
|
|
|
|
|
|
|
Licensed under MIT License
|
2017-09-11 06:51:52 +02:00
|
|
|
* (c) 2013, Luca CPZ
|
2017-09-04 12:43:00 +02:00
|
|
|
* (c) 2009, Uli Schlachter
|
|
|
|
* (c) 2009, Majic
|
|
|
|
|
2013-09-07 12:06:42 +02:00
|
|
|
--]]
|
|
|
|
|
2018-09-14 12:09:11 +02:00
|
|
|
local format = string.format
|
2013-09-07 12:06:42 +02:00
|
|
|
local setmetatable = setmetatable
|
|
|
|
|
|
|
|
-- Lain markup util submodule
|
|
|
|
-- lain.util.markup
|
2017-01-22 01:27:24 +01:00
|
|
|
local markup = { fg = {}, bg = {} }
|
2013-09-07 12:06:42 +02:00
|
|
|
|
2018-09-14 12:09:11 +02:00
|
|
|
-- Convenience tags
|
|
|
|
function markup.bold(text) return format("<b>%s</b>", text) end
|
|
|
|
function markup.italic(text) return format("<i>%s</i>", text) end
|
|
|
|
function markup.strike(text) return format("<s>%s</s>", text) end
|
|
|
|
function markup.underline(text) return format("<u>%s</u>", text) end
|
|
|
|
function markup.monospace(text) return format("<tt>%s</tt>", text) end
|
|
|
|
function markup.big(text) return format("<big>%s</big>", text) end
|
|
|
|
function markup.small(text) return format("<small>%s</small>", text) end
|
2013-09-07 12:06:42 +02:00
|
|
|
|
2018-09-14 12:09:11 +02:00
|
|
|
-- Set the font
|
2013-09-07 12:06:42 +02:00
|
|
|
function markup.font(font, text)
|
2018-09-15 10:21:37 +02:00
|
|
|
return format("<span font='%s'>%s</span>", font, text)
|
2013-09-07 12:06:42 +02:00
|
|
|
end
|
|
|
|
|
2018-09-14 12:09:11 +02:00
|
|
|
-- Set the foreground
|
2017-01-22 01:27:24 +01:00
|
|
|
function markup.fg.color(color, text)
|
2018-09-15 10:21:37 +02:00
|
|
|
return format("<span foreground='%s'>%s</span>", color, text)
|
2013-09-07 12:06:42 +02:00
|
|
|
end
|
|
|
|
|
2018-09-14 12:09:11 +02:00
|
|
|
-- Set the background
|
2017-01-22 01:27:24 +01:00
|
|
|
function markup.bg.color(color, text)
|
2018-09-15 10:21:37 +02:00
|
|
|
return format("<span background='%s'>%s</span>", color, text)
|
2013-09-07 12:06:42 +02:00
|
|
|
end
|
|
|
|
|
2018-09-14 12:09:11 +02:00
|
|
|
-- Set foreground and background
|
2017-01-22 01:15:57 +01:00
|
|
|
function markup.color(fg, bg, text)
|
2018-09-15 10:21:37 +02:00
|
|
|
return format("<span foreground='%s' background='%s'>%s</span>", fg, bg, text)
|
2017-01-22 01:15:57 +01:00
|
|
|
end
|
2013-09-07 12:06:42 +02:00
|
|
|
|
2018-09-14 12:09:11 +02:00
|
|
|
-- Set font and foreground
|
2017-01-28 23:35:27 +01:00
|
|
|
function markup.fontfg(font, fg, text)
|
2018-09-15 10:21:37 +02:00
|
|
|
return format("<span font='%s' foreground='%s'>%s</span>", font, fg, text)
|
2017-01-28 23:35:27 +01:00
|
|
|
end
|
|
|
|
|
2018-09-14 12:09:11 +02:00
|
|
|
-- Set font and background
|
2017-01-28 23:35:27 +01:00
|
|
|
function markup.fontbg(font, bg, text)
|
2018-09-15 10:21:37 +02:00
|
|
|
return format("<span font='%s' background='%s'>%s</span>", font, bg, text)
|
2017-01-28 23:35:27 +01:00
|
|
|
end
|
|
|
|
|
2018-09-14 12:09:11 +02:00
|
|
|
-- Set font, foreground and background
|
2017-01-22 01:15:57 +01:00
|
|
|
function markup.fontcolor(font, fg, bg, text)
|
2018-09-15 10:21:37 +02:00
|
|
|
return format("<span font='%s' foreground='%s' background='%s'>%s</span>", font, fg, bg, text)
|
2017-01-22 01:15:57 +01:00
|
|
|
end
|
2013-09-07 12:06:42 +02:00
|
|
|
|
2017-01-22 01:27:24 +01:00
|
|
|
-- link markup.{fg,bg}(...) calls to markup.{fg,bg}.color(...)
|
|
|
|
setmetatable(markup.fg, { __call = function(_, ...) return markup.fg.color(...) end })
|
|
|
|
setmetatable(markup.bg, { __call = function(_, ...) return markup.bg.color(...) end })
|
|
|
|
|
2013-09-07 12:06:42 +02:00
|
|
|
-- link markup(...) calls to markup.fg.color(...)
|
|
|
|
return setmetatable(markup, { __call = function(_, ...) return markup.fg.color(...) end })
|