Module:GetSpanContent: Difference between revisions
		
		
		
		Jump to navigation
		Jump to search
		
 Created page with "local p = {}  function p.getSpanContent(frame)     -- 获取页面的内容     local title = mw.title.getCurrentTitle()     local content = title:getContent()      if not content then         return '<span style="color: orange;">无法获取页面内容,可能页面为空或不存在。</span>'     end      -- 从调用中获取 id 参数     local span_id = frame.args[1] or "xxx"      -- 匹配指定 id 的 span 内容     local pattern = '<span%s+id="' .. span_id ....."  | 
			
(No difference) 
 | 
Latest revision as of 14:54, 8 January 2025
Documentation for this module may be created at Module:GetSpanContent/doc
local p = {}
function p.getSpanContent(frame)
    -- 获取页面的内容
    local title = mw.title.getCurrentTitle()
    local content = title:getContent()
    if not content then
        return '<span style="color: orange;">无法获取页面内容,可能页面为空或不存在。</span>'
    end
    -- 从调用中获取 id 参数
    local span_id = frame.args[1] or "xxx"
    -- 匹配指定 id 的 span 内容
    local pattern = '<span%s+id="' .. span_id .. '".-</span>'
    local span = content:match(pattern)
    if not span then
        return '<span style="color: orange;">未找到 id 为 ' .. span_id .. ' 的 <span> 标签。</span>'
    end
    -- 提取 span 内的文字内容
    local text = span:match('>(.-)<')
    return text or '<span style="color: orange;">标签内无内容。</span>'
end
return p