
if not is_client then
    return
end

local DEFAULT = 0
local HIGHLIGHT = 1
local SPECIAL = 2

function add_text(target, text)
    local start = 1
    local mode = DEFAULT

    for i = 1, #text do
        local c = text:sub(i, i)
        if mode == DEFAULT then
            if c == '*' or c == '#' then
                target:add_child(ui.new_text(text:sub(start, i - 1)))
                start = i + 1
                if c == '*' then
                    mode = HIGHLIGHT
                elseif c == '#' then
                    mode = SPECIAL
                end
            end
        elseif mode == HIGHLIGHT then
            if c == '*' then
                local txt = ui.new_text(text:sub(start, i - 1))
                txt:set_property_bool('highlight', true)
                target:add_child(txt)
                start = i + 1
                mode = DEFAULT
            end
        elseif mode == SPECIAL then
            if c == '#' then
                local txt = ui.new_text(text:sub(start, i - 1))
                txt:set_property_bool('special', true)
                target:add_child(txt)
                start = i + 1
                mode = DEFAULT
            end
        end
    end
    target:add_child(ui.new_text(text:sub(start, #text)))
end