Module:Cat: Difference between revisions

From Xenharmonic Reference
mNo edit summary
mNo edit summary
 
Line 4: Line 4:


-- Turns arguments into a string "[[Category:Cat1]][[Category:Cat2]]..."
-- Turns arguments into a string "[[Category:Cat1]][[Category:Cat2]]..."
-- Expects double quotes around each category name
-- Expects category names separated by newlines
function p.toCategories(frame)
function p.toCategories(frame)
     local args = getArgs(frame)
     local args = getArgs(frame)
     local unparsed = args[1]
     local unparsed = args[1]
     local cats = ""
     local cats = ""
     for cat in unparsed:gmatch('"([^"]+)"') do
     for cat in unparsed:gmatch('([^\n]+)') do
         cats = cats .. "[[Category:" .. cat .. "]]"
         cats = cats .. "[[Category:" .. cat .. "]]"
     end
     end

Latest revision as of 16:23, 23 December 2025

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

local getArgs = require('Module:Arguments').getArgs

local p = {}

-- Turns arguments into a string "[[Category:Cat1]][[Category:Cat2]]..."
-- Expects category names separated by newlines
function p.toCategories(frame)
    local args = getArgs(frame)
    local unparsed = args[1]
    local cats = ""
    for cat in unparsed:gmatch('([^\n]+)') do
        cats = cats .. "[[Category:" .. cat .. "]]"
    end
    return cats
end

return p