跳转到内容
打开/关闭搜索
搜索
打开/关闭菜单
384
文件
1
用户
6020
编辑
Gal中文百科
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
在其他项目中
打开/关闭外观设置菜单
无法加载偏好设置。请检查您的网络连接并重试。
重试
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
user-interface-preferences
个人工具
讨论
贡献
创建账号
登录
编辑“︁
Module
:
UnwrapConversion
”︁
来自Gal中文百科
查看
阅读
编辑源代码
查看历史
associated-pages
模块
讨论
更多操作
更多
工具
链入页面
相关更改
页面信息
警告:
您没有登录。如果您进行任何编辑,您的IP地址会公开展示。如果您
登录
或
创建账号
,您的编辑会以您的用户名署名,此外还有其他益处。
反垃圾检查。
不要
加入这个!
local p = {} local getArgs = require('Module:Arguments').getArgs local validVariantMap = {} for _, variant in ipairs({ 'zh', 'zh-hans', 'zh-hant', 'zh-cn', 'zh-hk', 'zh-mo', 'zh-my', 'zh-sg', 'zh-tw', }) do validVariantMap[variant] = true end local function validateFlag(input) local ret = {} local split = mw.text.split(input, ';') for _, item in ipairs(split) do item = mw.text.trim(item) if validVariantMap[item] then table.insert(ret, item) end end return #ret > 0 and table.concat(ret, ';') or nil end function p._main(args) local text = args.text or args[1] local convFlag = args.flag or args[2] if convFlag then convFlag = validateFlag(convFlag) end local source = {} for cp in mw.ustring.gcodepoint(text) do table.insert(source, mw.ustring.char(cp)) end local result = {} local strlen = #source local i=1 while i <= strlen do if source[i] == "-" and source[i + 1] == "{" then -- 跳掉转换标签 if source[i + 2] == "}" and source[i + 3] == "-" then -- 无视 -{}-(毕竟最后输出后这个 -{}- 的位置就会变成转换标记边界) i = i + 4 else i = i + 2 local depth = 1 -- 处理可能由其他模板引入的嵌套转换标签 table.insert(result, "-{") while i <= strlen do if source[i] == "-" and source[i + 1] == "{" then -- 嵌套开始 depth = depth + 1 table.insert(result, "-{") i = i + 2 elseif source[i] == "}" and source[i + 1] == "-" then -- 嵌套结束 depth = depth - 1 if depth == 0 then i = i + 2 break end table.insert(result, "}-") i = i + 2 else table.insert(result, source[i]) i = i + 1 end end table.insert(result, "}-") end else -- 在转换标签外,加上转换标签 local buffer = {} while i <= strlen and not (source[i] == "-" and source[i + 1] == "{") do table.insert(buffer, source[i]) i = i + 1 end if #buffer > 0 then if convFlag then table.insert( result, "-{" .. convFlag .. "|" .. table.concat(buffer) .. "}-" ) else table.insert( result, "-{" .. table.concat(buffer) .. "}-" ) end end end end return table.concat(result) end function p.main(frame) local args = getArgs(frame) return p._main(args) end return p
摘要:
请注意,所有对Gal中文百科的贡献均可能会被其他贡献者编辑、修改或删除。如果您不希望您的文字作品被随意编辑,请不要在此提交。
您同时也向我们承诺,您提交的内容为您自己所创作,或是复制自公共领域或类似自由来源(详情请见
Gal中文百科:著作权
)。
未经许可,请勿提交受著作权保护的作品!
取消
编辑帮助
(在新窗口中打开)
此页面嵌入的页面:
Module:UnwrapConversion/doc
(
编辑
)
编辑“︁
Module
:
UnwrapConversion
”︁
来自Gal中文百科