blob: f89368c54d4d70398d97a51faec9c86c22e17471 (
plain)
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
|
local M = {}
--- Apply markup to a file
---@param content string
---@param args { bold: boolean, italic: boolean, fg: string, bg: string }
---@return string
function M.convert(content, args)
args = args or {}
if args.bold then
content = "<b>" .. content .. "</b>"
end
if args.italic then
content = "<i>" .. content .. "</i>"
end
local span_content = ""
if args.fg or args.bg then
if args.fg then
span_content = "foreground='" .. args.fg .. "'"
end
if args.bg then
span_content = " background='" .. args.bg .. "'"
end
content = "<span " .. span_content .. ">" .. content .. "</span>"
end
return content
end
return setmetatable(M, {
__call = function(_, ...)
return M.convert(...)
end,
})
|