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

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