打开/关闭菜单
331
1.7K
131
11.8K
星露谷物语扩展百科
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:Quote:修订间差异

来自星露谷物语扩展百科
Sizau留言 | 贡献
无编辑摘要
Sizau留言 | 贡献
无编辑摘要
第27行: 第27行:
     -- 分割文本
     -- 分割文本
     local afterColon = mw.ustring.sub(text, colonPos + 1)
     local afterColon = mw.ustring.sub(text, colonPos + 1)
   
    -- 处理特例:'''123:'''456 格式
    -- 检查冒号后是否紧跟着三个单引号
    if mw.ustring.sub(afterColon, 1, 3) == "'''" then
        -- 移除冒号后的三个单引号
        afterColon = mw.ustring.sub(afterColon, 4)
        -- 在冒号前添加三个单引号
        beforeColon = beforeColon .. "'''"
    end
      
      
     -- 处理冒号后文本开头的星号
     -- 处理冒号后文本开头的星号

2025年7月10日 (四) 14:05的版本

[ 创建 | 刷新 ]文档页面
当前模块文档缺失,需要扩充。
local p = {}

-- 检查文本中是否有且仅有一个中文冒号":",且冒号前面没有出现过中文逗号和中文句号
function p.split(frame)
    local text = frame.args[1] or ""
    
    -- 计算中文冒号的数量
    local colonCount = 0
    for _ in mw.ustring.gmatch(text, ":") do
        colonCount = colonCount + 1
    end
    
    -- 如果不是只有一个冒号,返回空
    if colonCount ~= 1 then
        return ""
    end
    
    -- 找到冒号的位置
    local colonPos = mw.ustring.find(text, ":")
    
    -- 检查冒号前面是否有中文逗号或中文句号
    local beforeColon = mw.ustring.sub(text, 1, colonPos - 1)
    if mw.ustring.find(beforeColon, "[,。]") then
        return ""
    end
    
    -- 分割文本
    local afterColon = mw.ustring.sub(text, colonPos + 1)
    
    -- 处理特例:'''123:'''456 格式
    -- 检查冒号后是否紧跟着三个单引号
    if mw.ustring.sub(afterColon, 1, 3) == "'''" then
        -- 移除冒号后的三个单引号
        afterColon = mw.ustring.sub(afterColon, 4)
        -- 在冒号前添加三个单引号
        beforeColon = beforeColon .. "'''"
    end
    
    -- 处理冒号后文本开头的星号
    if mw.ustring.sub(afterColon, 1, 1) == "*" then
        afterColon = "<span>*</span>" .. mw.ustring.sub(afterColon, 2)
    end
    
    -- 返回结果
    if frame.args.part == "before" then
        return beforeColon
    elseif frame.args.part == "after" then
        return afterColon
    else
        -- 默认返回两部分,用 frame.args.separator 分隔(默认为制表符)
        local separator = frame.args.separator or "\t"
        return beforeColon .. separator .. afterColon
    end
end

return p