模块:PackedGallery:修订间差异

来自生物多样性知识平台

无编辑摘要
无编辑摘要
 
(未显示同一用户的4个中间版本)
第5行: 第5行:
     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 gallery = html.create('gallery')
     local galleryCode = '<gallery class="packed-gallery" mode="packed-hover">\n'
    gallery
        :attr('mode', 'packed')
        :attr('widths', '120px')


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


     return tostring(gallery)
    galleryCode = galleryCode .. '</gallery>'
 
    -- 使用 frame:preprocess() 确保输出按 wiki 文本处理
     return frame:preprocess(galleryCode)
end
end


return p
return p

2024年5月6日 (一) 10:42的最新版本

可在模块: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 galleryCode = '<gallery class="packed-gallery" mode="packed-hover">\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), mw.text.trim(fileDesc))
    end

    galleryCode = galleryCode .. '</gallery>'

    -- 使用 frame:preprocess() 确保输出按 wiki 文本处理
    return frame:preprocess(galleryCode)
end

return p