-
Notifications
You must be signed in to change notification settings - Fork 21
/
fmt.lua
77 lines (59 loc) · 1.4 KB
/
fmt.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
local md_colors = require "md_colors"
local fmt = {}
function fmt.bold(str)
return "<b>"..str.."</b>"
end
function fmt.italic(str)
return "<i>"..str.."</i>"
end
function fmt.underline(str)
return "<u>"..str.."</u>"
end
function fmt.primary(str)
return fmt.colored(str, ui:get_colors().primary_text)
end
function fmt.secondary(str)
return fmt.colored(str, ui:get_colors().secondary_text)
end
function fmt.colored(str, color)
return "<font color=\""..color.."\">"..str.."</font>"
end
function fmt.bg_colored(str, color)
return "<span style=\"background-color: "..color.."\">"..str.."</span>"
end
function fmt.red(str)
return fmt.colored(str, md_colors.red_500)
end
function fmt.green(str)
return fmt.colored(str, md_colors.green_500)
end
function fmt.blue(str)
return fmt.colored(str, md_colors.blue_500)
end
function fmt.small(str)
return "<small>"..str.."</small>"
end
function fmt.big(str)
return "<big>"..str.."</big>"
end
function fmt.strike(str)
return "<strike>"..str.."</strike>"
end
function fmt.space(n)
local num = 1
if n ~= nil and n > 1 then
num = n
end
return string.rep(" ", num)
end
function fmt.escape(str)
return (string.gsub(str, "[}{\">/<'&]", {
["&"] = "&",
["<"] = "<",
[">"] = ">",
['"'] = """,
["'"] = "'",
["/"] = "/"
}))
end
return fmt