删除的内容 添加的内容
从 zhwiki 导入完整版
 
从 zhwiki 导入并适配
 
第13行:
local TlParLib = {}
local lib_arg = {}
--主函数數
function p.main(frame)
if not getArgs then
第26行:
for arg_name, arg_value in pairs( get_args ) do
if arg_name == 1 or arg_name == '1' then
--要处處理的字符串
to_replace = arg_value
elseif arg_name == "type" then
第51行:
get_args = getArgs(frame, {parentFirst=true})
category_list = p.find_category((get_args[1] or get_args['1']) or '')
format = mw.ustring.gsub((get_args[2] or get_args['2']) or "*{{{1}}}\\n", "%{%{%{.-%}%}%}", "%%s" );
it = mw.ustring.find(format, "%%s", 1)
if it == nil then format = format .. "%s" end
format = mw.ustring.gsub(format, "\\\\n", "\\n")
 
body = ''
第63行:
end
function p.deltitle(input)
str = mw.text.trim(mw.ustring.gsub(input,"\\127\\'\\\"`UNIQ%-%-.-QINU`\\\"\\'\\127", p.nullstr))
 
begin_, end_ = mw.ustring.find(str, "=+", 1)
if begin_==nil then return input end
begin_2 = mw.ustring.find(str, "=+ *\\n", end_ + 1)
count = end_ - begin_ + 1
 
title_name = mw.text.trim(mw.ustring.sub(str, end_ + 1, begin_2-1 ))
result = "\\n;<span id=\\\"" .. title_name .. "\\\" style=\\\"font-size:" .. (({24,20,18,16,14})[count] or 14) .. "px;\\\">" .. title_name .. "</span>"
 
if count < 1 then return str
elseif count < 3 then result = result .. "\\n----" end
return result .. '\\n'
end
function p.bytelen(frame)
第107行:
mw.ustring.gsub(mw.ustring.gsub(args[1] or args['1'],
"[%c%l%u%d%p%s%z" ..
"%>%<%=%{%}%|%[%]%`%+%-%*%/%\\\\"
.. "↑↓←→№©⦸⁄⧸⁄"
.. "%−%~%~%!%@%#%$%^%&%_×÷ºª±∓"
.. "]"
,'.'),"%.+",args['gap'] or '')
第121行:
get_args = getArgs(frame, {parentFirst=true})
input = (get_args[1] or get_args['1']) or ''
input = mw.ustring.gsub(input,"\\127\\'\\\"`UNIQ%-%-ref.-QINU`\\\"\\'\\127", p.nullstr)
body = p.delete_category(input, {})
get_link = mw.ustring.gmatch( body, "%[%[.-%]%]" )
i = 1 j = 1 while mw.ustring.find(body, "\\n=+ *[^\\n]* *=+ *\\n") and j do
if i>=10 then j = nil end
body = mw.ustring.gsub(body, "\\n=+ *[^\\n]* *=+ *\\n", p.deltitle)
i = i + 1
end
第148行:
link_str = get_link()
end
body = mw.text.trim(body) .. '\\n'
body = mw.ustring.gsub( body, "[Ii][Ss][Bb][Nn]", "&#73;&#83;&#66;&#78;" );
第166行:
body = mw.ustring.gsub( body, categorys, p.nullstr );
end
--Category:使用ISBN魔术连结術連結的页頁面
body = mw.ustring.gsub( body, "[Ii][Ss][Bb][Nn]", "&#73;&#83;&#66;&#78;" );
body = mw.text.trim(body) --消除多余餘空行
return body
end
第189行:
end
end
if mw.ustring.find(body, "[Ii][Ss][Bb][Nn]") then category_list["使用ISBN魔术连结術連結的页頁面"] = "使用ISBN魔术连结術連結的页頁面" end
cat_list = {}
i=1
第206行:
get_args = getArgs(frame, {parentFirst=true})
text = mw.ustring.gsub( ((get_args[1] or get_args['1']) or ''), '\\n', "\\n ")
input = mw.ustring.gsub(text,'<',"&lt;")
input = mw.ustring.gsub(input,'>',"&gt;")
 
--return mw.ustring.gsub( input .. "\\n*匹配数數:", "\\127\\'\\\"`UNIQ%-%-ref.-QINU`\\\"\\'\\127", p.nullstr );
input = mw.ustring.gsub( input, "\\127\\'\\\"`", p.nullstr );
return mw.ustring.gsub( input, "`\\\"\\'\\127", p.nullstr );
end
function p.get_title(frame)
第222行:
for arg_name, arg_value in pairs( get_args ) do
if arg_name == 1 or arg_name == '1' then
--要处處理的字符串
input = arg_value
elseif arg_name == "title" or arg_name == "2" or arg_name == 2 then
第309行:
full_include = yesno(mw.ustring.lower(arg_value) or 'no')
elseif arg_name == "\\1" then new_args["1"] = arg_value
elseif frame ~= mw.getCurrentFrame() and arg_name == "NoPreprocess" then preprocess = not require('Module:Yesno')(arg_value) -- lua专專用,使目标暂时標暫時不展开開,不允许許直接呼叫避免惨慘案发發生
else new_args[arg_name] = arg_value end
end
第333行:
InIsSubst = InIsSubst > 0 or InIsMsgnw > 0
InIsMsgnw = InIsMsgnw > 0
local mark_pos,_ = mw.ustring.find(pagename, '%#') --分析章节语節語法(#)
if mark_pos then
chaptername = mw.ustring.sub(pagename,mark_pos+1,#pagename)
第340行:
local chapterfullname = tostring(chaptername)
local chapterid = 1
mark_pos = mw.ustring.find(chapterfullname, "%_%d+$") --分析章节语節語法(_)
if mark_pos then
chaptername = mw.ustring.sub(chapterfullname,1,mark_pos-1)
第350行:
if mw.text.trim(pagename) == '' then return '' end
--取得引用页頁名称稱
local check_includetitle, is_namespace0 = mw.text.trim(pagename), 0
check_includetitle, is_namespace0 = mw.ustring.gsub(check_includetitle, "^%s-:","")
第357行:
local check_isExternal = check_includetitle_obj.isExternal
if check_isExternal == nil then check_isExternal = false end
if check_includetitle_namespace == 0 and is_namespace0 > 0 and not check_isExternal then --有冒号號表示指名名字空间間(预设預設是 Template )
check_includetitle = mw.title.new( check_includetitle )
elseif check_includetitle_namespace == 0 and not check_isExternal then --没沒有冒号號表示预设預設是 Template
check_includetitle = mw.title.new( "Template:" .. check_includetitle )
else --其余餘情况況就用解析到的名字空间間
check_includetitle = mw.title.new( check_includetitle )
end
第367行:
fullText = mw.text.trim(pagename) , text = mw.text.trim(pagename), isErrorTitle=true
} end
--建立解析器,解析模板语語法
local include_frame = mw.getCurrentFrame()
local include_parent_frame = include_frame:getParent()
if include_parent_frame and not mw.isSubsting() then include_frame = include_parent_frame end
--定位为為由呼叫者直接执執行
if not mw.isSubsting() then
working_frame = include_frame:newChild{ title = include_frame:getTitle(), args = new_args }
end
 
local input_str = working_frame:preprocess( "{{msgnw:" .. pagename .. "}}" ) --析出页頁面源码原碼
local redirectTarget = check_includetitle.redirectTarget
if redirectTarget ~= false and redirectTarget ~= nil then check_includetitle = redirectTarget end
local subst_error = false
 
if mw.isSubsting() then
-- [[Module:Delcat]] include --包含
--這部份似乎無解,subst:和msgnw:無法同時疊加
-- 将模板源码以源码形式包含进来,并试图节选特定章节内容
xpcall( function()
 
input_str = working_frame:expandTemplate{ title = ":" .. check_includetitle.fullText, args = new_args }
--去除扩展标签之前,由于章节(== XX ==)也是一种列入strip的扩展标签,因此要先储存起来,避免资料遗失▼
--針對章節標提移除擴展標籤,使subst後系統自動生成新的
input_str = mw.text.trim(mw.ustring.gsub(input_str,"\127\'\"`UNIQ%-%-h%-.-QINU`\"\'\127", p.nullstr))
end, function(message)
input_str = ''
subst_error = true
end )
else
input_str = mw.text.decode(input_str) --解析網頁符號 (&#XXX;)
end
if (#input_str <= (12 + #check_includetitle.fullText) ) or subst_error==true then
if TlParLib._getEscapeString == nil then TlParLib = require('Module:TemplateParameters') end
local new_str, replaced = mw.ustring.gsub(mw.ustring.lower(input_str),
"[%[%{][%[%{][^%]%}]-:(" ..
TlParLib._getEscapeString(mw.ustring.lower(check_includetitle.fullText)) ..
")[%]%}][%]%}]"
,"[[:%1"
)
if replaced > 0 or subst_error==true then
if subst_error==true then new_str = "[[:" .. check_includetitle.fullText end
if check_includetitle.isErrorTitle then return check_includetitle.fullText end
input_str = new_str .. '#' .. chapterfullname .. '|'
if mw.text.trim(check_includetitle.nsText or '') ~= '' then input_str = input_str .. check_includetitle.nsText .. ':' end
input_str = input_str .. check_includetitle.text
if mw.text.trim(chapterfullname) ~= '' then input_str = input_str .. '#' .. chaptername end
input_str = input_str .. "]]"
return input_str
end
end
▲ --去除扩擴展标签標籤之前,由于於章节節(== XX ==)也是一种種列入strip的扩擴展标签標籤,因此要先储儲存起来來,避免资資料遗遺失
local htagstrip_table = {}
if not mw.isSubsting() then --subst需保留扩擴展标签標籤 (subst后会後會自动还動還原)
local htagstrip_matcher = "\\127\\'\\\"`UNIQ%-%-h%-.-QINU`\\\"\\'\\127%s-[^\\n]-%s-=+%s-\\n"
local htagstrip_start, htagstrip_end = mw.ustring.find(input_str, htagstrip_matcher, 1)
while htagstrip_start do
local temp_htagstrip = mw.ustring.sub(input_str, htagstrip_start, htagstrip_end)
local htagstrip_str = mw.ustring.match(temp_htagstrip, "\\127\\'\\\"`UNIQ%-%-h%-.-QINU`\\\"\\'\\127")
local htag_tail = mw.ustring.gsub(temp_htagstrip, "\\127\\'\\\"`UNIQ%-%-h%-.-QINU`\\\"\\'\\127", "")
local begin_, end_ = mw.ustring.find(htag_tail, "=+", 1)
local htag_name = mw.text.trim(mw.ustring.gsub(htag_tail, '=', ''))
第402行 ⟶ 第432行:
htagstrip_start, htagstrip_end = mw.ustring.find(input_str, htagstrip_matcher, htagstrip_end+1)
end
input_str = mw.text.killMarkers( input_str ) --去除扩擴展标签標籤
end
 
input_str = '\\n\\n' .. input_str .. '\\n\\n' --使规規表达達式不会會在首行和末行出现边現邊界情况況
if TlParLib._getEscapeString == nil then TlParLib = require('Module:TemplateParameters') end
local chapterfullname_regex_pattern = TlParLib._getEscapeString(chapterfullname)
第412行 ⟶ 第442行:
local is_htag = false
local function htag_regex(chname)
--用于处於處理subst不同的载載入方式
if mw.isSubsting() then return "\\n=+ -" .. chname .. " -=+ -\\n" end
return "\\n=+%s-" .. chname .. "%s-=+%s-\\n"
end
local function spantag_regex(chname) return "%<%s-span[^%>]+id=[%\\\"%\\']" .. chname .. "[%\\\"%\\']" end
local function anchortag_regex(chname) return "%{%{[Aa][Nn][Cc][Hh][Oo][Rr][^%}]-%|%s-" .. chname .. "%s-[%|%}]" end
local function find_chtag(chname, alltext)
第428行 ⟶ 第458行:
if finded_title_begin then return finded_title_begin, finded_title_end end
end
local next_title_matcher = htag_regex("[^\\n]-")
 
if mw.text.trim(chapterfullname) ~= '' then
第434行 ⟶ 第464行:
local next_title_begin, next_title_end = #input_str, nil; next_title_end = next_title_begin
if finded_title_begin then --匹配全名
else --从從非全名寻尋找
finded_title_begin, finded_title_end =find_chtag(chaptername_regex_pattern, input_str)
end
第456行 ⟶ 第486行:
finded_title_end = 1
else
if is_htag == false then --分析章节标题節標題
local re_find = mw.ustring.sub(input_str, 1, finded_title_begin)
re_find = re_find:reverse()
local temp_title_begin, temp_title_end
if(mw.ustring.isutf8(re_find) == true )then
temp_title_begin, temp_title_end = mw.ustring.find(re_find, htag_regex("[^\\n]-"), 1)
if temp_title_begin then finded_title_string = mw.ustring.sub(re_find, temp_title_begin, temp_title_end) end
else
temp_title_begin, temp_title_end = re_find:find(htag_regex("[^\\n]-"), 1)
if temp_title_begin then finded_title_string = re_find:sub(temp_title_begin, temp_title_end) end
end
第474行 ⟶ 第504行:
end
end
--获獲得章节标题節標題的级数級數
if htag_level==nil then
local begin_, end_ = mw.ustring.find(finded_title_string, "=+", 1)
第499行 ⟶ 第529行:
body = mw.ustring.sub(input_str, ch_start, next_title_begin - 1)
 
if show_t == false then --不显顯示章节标头節標頭者,移除章节标头節標頭
local i = 1 j = 1 while mw.ustring.find(body, "\\n=+ *[^\\n]* *=+ *\\n") and j do if i>=10 then j = nil end
body = mw.ustring.gsub(body, "\\n=+ *[^\\n]* *=+ *\\n", p.deltitle)
i = i + 1
end
第513行 ⟶ 第543行:
body = input_str
end
if full_include==true then --设設定为為 "全面引用" 将將noinclude等标记標記移除
--匹配noinclude等标记標記的规正規表达達式 (适適用於lua的版本)
local include_pattern = "[Ii][Nn][Cc][Ll][Uu][Dd][Ee]"
local only_pattern = "[Oo][Nn][Ll][Yy]"
第527行 ⟶ 第557行:
local min_title = 0
if show_t == true and not mw.isSubsting() then --显顯示章节标头節標頭者,须須使章节标头節標頭正常运運作
--将扩將擴展标签標籤 (== XX ==) 摆擺回去
body = '\\n\\n' .. body .. '\\n\\n' --使规規表达達式不会會在首行和末行出现边現邊界情况況
local back_title_start, back_title_end = mw.ustring.find(body, next_title_matcher, 1)
local title_first_match = true
while back_title_start do --逐一搜索标题標題
local check_title=mw.ustring.sub(body, back_title_start, back_title_end)
check_title=mw.text.trim(mw.ustring.gsub(check_title, '=', ''))
check_title=mw.text.trim(check_title) --确確定标题標題名称稱
local check_title_matcher=TlParLib._getEscapeString(check_title)
local htagstrip_table_item={} --获獲得原始标题標題的扩擴展标签標籤strip标记標記符号號
for ik, iv in ipairs(htagstrip_table) do
if iv.name == check_title or iv.name == chapterothername then
第549行 ⟶ 第579行:
end
 
--将扩將擴展标签標籤strip标记標記符号號放回内內文
if htagstrip_table_item.htagstrip then
body = mw.ustring.gsub(body, "(=+)(%s-" .. check_title_matcher .. "%s-=+)", "%1" .. htagstrip_table_item.htagstrip .. "%2")
第558行 ⟶ 第588行:
 
body = mw.text.trim(body)
--subst无须复無須復位
if mw.isSubsting() then return body end
if min_title > 1 then body = "\\127\\'\\\"`UNIQ____TITLE__TAG__PATTERN____QINU`\\\"\\'\\127\\n" .. body
for _=2,min_title do body = "== ==\\n" .. body end
end
working_frame = include_frame:newChild{ title = check_includetitle.fullText, args = new_args }
if preprocess then -- lua专專用,使目标暂时標暫時不展开開
body = working_frame:preprocess( body )
end
if min_title > 1 then local start;_,start = mw.ustring.find(body,"\\127\\'\\\"`UNIQ____TITLE__TAG__PATTERN____QINU`\\\"\\'\\127\\n")
if start then body =mw.ustring.sub(body, start+1, #body) end
body = mw.text.trim(body)
第602行 ⟶ 第632行:
end
str = '\\n'..mw.text.trim(mw.ustring.gsub(str,"\\127\\'\\\"`UNIQ%-%-h%-.-QINU`\\\"\\'\\127", p.nullstr))
 
--^$()%.[]*+-?
第615行 ⟶ 第645行:
cutted_title_matcher = mw.ustring.gsub(mw.ustring.gsub(cutted_title_matcher, "%{", "%{") , "%}", "%}")
 
cutted_title_matcher = "\\n=+ *" .. cutted_title_matcher .. " *=+ *\\n"
title_matcher = "\\n=+ *" .. title_matcher .. " *=+ *\\n"
finded_title_begin, finded_title_end = mw.ustring.find(str, title_matcher, 1)
第638行 ⟶ 第668行:
begin_, end_ = mw.ustring.find(finded_title, "=+", 1)
begin_2, end_2 = mw.ustring.find(finded_title, "=+ *\\n", end_ + 1)
count = end_ - begin_ + 1
end
next_title_matcher = "\\n=+ *[^=\\n]* *=+ *\\n"
next_title_find_begin, next_title_find_end = mw.ustring.find(str, next_title_matcher, finded_title_end + 1)
flag = true while next_title_find_begin and flag do
第660行 ⟶ 第690行:
body = mw.ustring.sub(str, finded_title_end + 1, next_title_begin - 1)
i = 1 j = 1 while mw.ustring.find(body, "\\n=+ *[^\\n]* *=+ *\\n") and j do if i>=10 then j = nil end
body = mw.ustring.gsub(body, "\\n=+ *[^\\n]* *=+ *\\n", p.deltitle)
i = i + 1
end
第690行 ⟶ 第720行:
for k, v in pairs( get_args ) do
if k == 1 or k == '1' then
--要处處理的字符串
to_replace = v
else