]> git.madduck.net Git - etc/awesome.git/blob - util/markup.lua

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge pull request #413 from seregaxvm/master
[etc/awesome.git] / util / markup.lua
1 --[[
2
3      Licensed under MIT License
4       * (c) 2013, Luca CPZ
5       * (c) 2009, Uli Schlachter
6       * (c) 2009, Majic
7
8 --]]
9
10 local format = string.format
11 local setmetatable = setmetatable
12
13 -- Lain markup util submodule
14 -- lain.util.markup
15 local markup = { fg = {}, bg = {} }
16
17 -- Convenience tags
18 function markup.bold(text)      return format("<b>%s</b>",         text) end
19 function markup.italic(text)    return format("<i>%s</i>",         text) end
20 function markup.strike(text)    return format("<s>%s</s>",         text) end
21 function markup.underline(text) return format("<u>%s</u>",         text) end
22 function markup.monospace(text) return format("<tt>%s</tt>",       text) end
23 function markup.big(text)       return format("<big>%s</big>",     text) end
24 function markup.small(text)     return format("<small>%s</small>", text) end
25
26 -- Set the font
27 function markup.font(font, text)
28     return format("<span font='%s'>%s</span>", font, text)
29 end
30
31 -- Set the foreground
32 function markup.fg.color(color, text)
33     return format("<span foreground='%s'>%s</span>", color, text)
34 end
35
36 -- Set the background
37 function markup.bg.color(color, text)
38     return format("<span background='%s'>%s</span>", color, text)
39 end
40
41 -- Set foreground and background
42 function markup.color(fg, bg, text)
43     return format("<span foreground='%s' background='%s'>%s</span>", fg, bg, text)
44 end
45
46 -- Set font and foreground
47 function markup.fontfg(font, fg, text)
48     return format("<span font='%s' foreground='%s'>%s</span>", font, fg, text)
49 end
50
51 -- Set font and background
52 function markup.fontbg(font, bg, text)
53     return format("<span font='%s' background='%s'>%s</span>", font, bg, text)
54 end
55
56 -- Set font, foreground and background
57 function markup.fontcolor(font, fg, bg, text)
58     return format("<span font='%s' foreground='%s' background='%s'>%s</span>", font, fg, bg, text)
59 end
60
61 -- link markup.{fg,bg}(...) calls to markup.{fg,bg}.color(...)
62 setmetatable(markup.fg, { __call = function(_, ...) return markup.fg.color(...) end })
63 setmetatable(markup.bg, { __call = function(_, ...) return markup.bg.color(...) end })
64
65 -- link markup(...) calls to markup.fg.color(...)
66 return setmetatable(markup, { __call = function(_, ...) return markup.fg.color(...) end })