Module:CSVToBulletList

From Dune: Awakening Community Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:CSVToBulletList/doc

-- Usage: {{#invoke:CSVToBulletList|main|CSV_STRING}}


local p = {}

function p.main(frame)
    local input = frame.args[1]

    if not input or input == '' then
        return ''
    end

    local items = {}
    
    -- split string by commas
    for item in mw.text.gsplit(input, ',') do

        -- trim whitespace
        item = mw.text.trim(item)

        if item ~= '' then
            table.insert(items, '* ' .. item)
        end
    end

    -- join items back into bullet list
    return table.concat(items, '\n')
end

return p