Module:RequirementBox: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 4: Line 4:
     if list == "" then return "" end
     if list == "" then return "" end


     local out = ""
     local blocks = {}
    local current = nil


     -- Split by lines
     -- Split into lines and group into bullet blocks
     for line in list:gmatch("[^\r\n]+") do
     for line in list:gmatch("[^\r\n]+") do
         line = mw.text.trim(line)
         line = mw.text.trim(line)


        -- Only process bullet lines
         if line:sub(1,1) == "*" then
         if line:sub(1, 1) == "*" then
             -- start new requirement block
             local item = mw.text.trim(line:sub(2))
            if current then
                table.insert(blocks, current)
            end
            current = mw.text.trim(line:sub(2))
        elseif current then
            -- continuation of previous requirement
            current = current .. "\n" .. line
        end
    end


            if item:find("||OR||", 1, true) then
    if current then
                -- OR requirement
        table.insert(blocks, current)
                local parts = mw.text.split(item, "||OR||", true)
    end
                out = out .. '<li class="vp-requirement-or">'
 
                for i, part in ipairs(parts) do
    local out = ""
                    out = out .. '<div class="vp-requirement-or-option">' ..
 
                        mw.text.trim(part) .. '</div>'
    for _, block in ipairs(blocks) do
                    if i < #parts then
        if block:find("||OR||", 1, true) then
                        out = out .. '<div class="vp-requirement-or-divider">OR</div>'
            local parts = mw.text.split(block, "||OR||", true)
                    end
            out = out .. '<li class="vp-requirement-or">'
            for i, part in ipairs(parts) do
                out = out .. '<div class="vp-requirement-or-option">' ..
                    mw.text.trim(part) .. '</div>'
                if i < #parts then
                    out = out .. '<div class="vp-requirement-or-divider">OR</div>'
                 end
                 end
                out = out .. '</li>'
            else
                -- Normal requirement
                out = out .. '<li>' .. item .. '</li>'
             end
             end
            out = out .. '</li>'
        else
            out = out .. '<li>' .. block .. '</li>'
         end
         end
     end
     end
Line 43: Line 56:
</div>]], title, out)
</div>]], title, out)
end
end