打开/关闭菜单
60
73
29
1.1K
武外梗百科
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

Module:PageSummary:修订间差异

武外梗百科 爱国好学自强图新的百科全书
无编辑摘要
无编辑摘要
第85行: 第85行:
     local cleanText = cleanFinal(step1) or ""
     local cleanText = cleanFinal(step1) or ""


    local targetLen = 120
        local targetLen = 120
     local summary = cleanText
     local summary = cleanText or ""


     local ulen = mw.ustring.len(summary) or 0
    -- 先强制清理任何可能导致编码问题的隐藏字符
    summary = mw.ustring.gsub(summary, "[%z\127-\159]", "")  -- 移除控制字符、BOM等
 
     local ulen = mw.ustring.len(summary)
     if ulen > targetLen then
     if ulen > targetLen then
         summary = mw.ustring.sub(summary, 1, targetLen)
         -- 截取到 targetLen + 一点缓冲,避免边界问题
        local temp = mw.ustring.sub(summary, 1, targetLen + 20)
          
          
         local tail = mw.ustring.sub(summary, -15) or ""
        -- 从后往前找第一个安全的断点(空格、中文标点)
        local rev_tail = tail:reverse()
         local breakPos = nil
        local pos = rev_tail:find("[ %s%p,。!?;:,…,、]") or 1
        for i = #temp, 1, -1 do
            local char = mw.ustring.sub(temp, i, i)
            if char:match("[ %s,。!?;:,…、]") then
                breakPos = i
                break
            end
        end
          
          
         if pos > 1 and pos < 15 then
         if breakPos and breakPos > targetLen - 30 then
             local cut_len = mw.ustring.len(tail) - pos + 1
             summary = mw.ustring.sub(temp, 1, breakPos)
             summary = mw.ustring.sub(summary, 1, mw.ustring.len(summary) - cut_len)
        else
             summary = mw.ustring.sub(temp, 1, targetLen)
         end
         end
          
          
         summary = mw.text.trim(summary) .. "..."
         summary = mw.text.trim(summary) .. ""
     else
     else
         summary = mw.text.trim(summary)
         summary = mw.text.trim(summary)