lain/util/markup.lua

67 lines
2.2 KiB
Lua
Raw Normal View History

2013-09-07 12:06:42 +02:00
--[[
Licensed under MIT License
* (c) 2013, Luca CPZ
* (c) 2009, Uli Schlachter
* (c) 2009, Majic
2013-09-07 12:06:42 +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
-- 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
-- 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
-- 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
-- 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
-- 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
-- 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
-- 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
-- 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 })