]> 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:

pulseaudio -> pulse; scallback merged into cmd (read wiki)
[etc/awesome.git] / util / markup.lua
1 --[[
2
3      Licensed under MIT License
4       * (c) 2013, Luke Bonham
5       * (c) 2009, Uli Schlachter
6       * (c) 2009, Majic
7
8 --]]
9
10 local string       = { 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 '<b>'     .. text .. '</b>'     end
19 function markup.italic(text)    return '<i>'     .. text .. '</i>'     end
20 function markup.strike(text)    return '<s>'     .. text .. '</s>'     end
21 function markup.underline(text) return '<u>'     .. text .. '</u>'     end
22 function markup.monospace(text) return '<tt>'    .. text .. '</tt>'    end
23 function markup.big(text)       return '<big>'   .. text .. '</big>'   end
24 function markup.small(text)     return '<small>' .. text .. '</small>' end
25
26 -- Set the font.
27 function markup.font(font, text)
28   return '<span font="'  .. font  .. '">' .. text ..'</span>'
29 end
30
31 -- Set the foreground.
32 function markup.fg.color(color, text)
33   return '<span foreground="' .. color .. '">' .. text .. '</span>'
34 end
35
36 -- Set the background.
37 function markup.bg.color(color, text)
38   return '<span background="' .. color .. '">' .. text .. '</span>'
39 end
40
41 -- Set foreground and background.
42 function markup.color(fg, bg, text)
43   return string.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 string.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 string.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 string.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 })