Bước tới nội dung

Mô đun:Danh sách

Bách khoa toàn thư mở Wikipedia

Đây là một phiên bản cũ của trang này, do Admin (thảo luận | đóng góp) sửa đổi vào lúc 20:38, ngày 6 tháng 8 năm 2026 (Đã nhập 1 phiên bản). Địa chỉ URL hiện tại là một liên kết vĩnh viễn đến phiên bản này của trang, có thể khác biệt rất nhiều so với phiên bản hiện hành.

(khác) ← Phiên bản cũ | Phiên bản mới nhất (khác) | Phiên bản mới → (khác)
---Các hàm để xây dựng danh sách.
local p = {}
local viet

---Cho ra các tham số như một danh sách nội dòng.
-- Hàm này hỗ trợ số tham số không hạn chế.
function p.inlineList(frame)
    local contentFrame = frame
    if not frame.args[1] then contentFrame = frame:getParent() end
    
    local start = tonumber(contentFrame.args.start or frame.args.start or 1) or 1
    
    local insep = contentFrame.args.insep
    local items = {}
    for i, arg in ipairs(contentFrame.args) do
        if i >= start then
            local item = tostring(mw.text.trim(arg))
            if #item > 0 then
            	if insep then
            		local subitems = mw.text.split(item, insep)
            		for i, subitem in ipairs(subitems) do
            			table.insert(items, subitem)
        			end
            	else
            		table.insert(items, item)
        		end
            end
        end
    end
    
    if contentFrame.args.sorted and tonumber(contentFrame.args.sorted) == 1 then
        viet = viet or require "Mô đun:Quốc ngữ"
        table.sort(items, viet.comp)
    end
    
    local format = contentFrame.args.format
    if format then
    	for i, item in ipairs(items) do
    		items[i] = mw.ustring.format(format, item)
		end
	end
    
    local space = contentFrame.args.space or frame.args.space or " "
    
    local conj = contentFrame.args.conj or frame.args.conj
    if #items > 1 and conj then
        items[#items] = conj .. space .. items[#items]
    end
    
    local output
    if #items == 2 and conj then
        output = items[1] .. space .. items[2]
    else
	    local sep = contentFrame.args.sep or frame.args.sep or ","
	    output = table.concat(items, sep .. space)
    end
    if #output < 1 and contentFrame.args.placeholder then
    	output = contentFrame.args.placeholder
	end
    return output
end

return p