模块:PackedGallery:修订间差异

来自生物多样性知识平台

(创建页面,内容为“local p = {} function p.renderGallery(frame) local images = frame.args.images or "" local imageList = mw.text.split(images, ",") local galleryCode = '<gallery mode="packed" widths="120px">\n' for i, image in ipairs(imageList) do local parts = mw.text.split(image, ";") local fileName = parts[1] or "" local fileDesc = parts[2] or "" galleryCode = galleryCode .. string.format('File:%s|%s\n', mw.text.trim(fileName),…”)
 
无编辑摘要
第1行: 第1行:
local p = {}
local p = {}
local html = require('mw.html')


function p.renderGallery(frame)
function p.renderGallery(frame)
     local images = frame.args.images or ""
     local images = frame.args.images or ""
     local imageList = mw.text.split(images, ",")
     local imageList = mw.text.split(images, ",")
     local galleryCode = '<gallery mode="packed" widths="120px">\n'
     local gallery = html.create('gallery')
    gallery
        :attr('mode', 'packed')
        :attr('widths', '120px')


     for i, image in ipairs(imageList) do
     for i, image in ipairs(imageList) do
第10行: 第14行:
         local fileName = parts[1] or ""
         local fileName = parts[1] or ""
         local fileDesc = parts[2] or ""
         local fileDesc = parts[2] or ""
         galleryCode = galleryCode .. string.format('File:%s|%s\n', mw.text.trim(fileName), mw.text.trim(fileDesc))
         gallery:wikitext(string.format('File:%s|%s', mw.text.trim(fileName), mw.text.trim(fileDesc)))
     end
     end


     galleryCode = galleryCode .. '</gallery>'
     return tostring(gallery)
    return galleryCode
end
end


return p
return p

2024年5月3日 (五) 10:29的版本

可在模块:PackedGallery/doc创建此模块的帮助文档

local p = {}
local html = require('mw.html')

function p.renderGallery(frame)
    local images = frame.args.images or ""
    local imageList = mw.text.split(images, ",")
    local gallery = html.create('gallery')
    gallery
        :attr('mode', 'packed')
        :attr('widths', '120px')

    for i, image in ipairs(imageList) do
        local parts = mw.text.split(image, ";")
        local fileName = parts[1] or ""
        local fileDesc = parts[2] or ""
        gallery:wikitext(string.format('File:%s|%s', mw.text.trim(fileName), mw.text.trim(fileDesc)))
    end

    return tostring(gallery)
end

return p