模块:OfficePreview
来自异世界百科
此模块的文档可以在模块:OfficePreview/doc创建
local p = {}
function p.getDirectUrl(file)
if file ~= nil then
local fileTitle = mw.title.new(file, 6)
local title = mw.title.new('FilePath', -1):subPageTitle(fileTitle.text)
return title:fullUrl()
else
return nil
end
end
function p.preview(frame)
local fileName = frame.args[1]
if fileName ~= nil then
local fileUrl = p.getDirectUrl(fileName)
local frameUrl = "https://view.officeapps.live.com/op/embed.aspx?" .. mw.uri.buildQueryString({
src = fileUrl
})
return '<div class="office-preview">' .. frame:extensionTag("htmltag", "", {
tagname = "iframe",
frameborder = "no",
border = "0",
marginwidth = "0",
marginheight = "0",
src = frameUrl
}) .. '</div>'
else
error("输入的文件名错误: " .. fileName)
end
end
return p