Module:Delcat:修订间差异
删除的内容 添加的内容
从 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}}}
it = mw.ustring.find(format, "%%s", 1)
if it == nil then format = format .. "%s" end
format = mw.ustring.gsub(format, "
body = ''
第63行:
end
function p.deltitle(input)
str = mw.text.trim(mw.ustring.gsub(input,"
begin_, end_ = mw.ustring.find(str, "=+", 1)
if begin_==nil then return input end
begin_2 = mw.ustring.find(str, "=+ *
count = end_ - begin_ + 1
title_name = mw.text.trim(mw.ustring.sub(str, end_ + 1, begin_2-1 ))
result = "
if count < 1 then return str
elseif count < 3 then result = result .. "
return result .. '
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,"
body = p.delete_category(input, {})
get_link = mw.ustring.gmatch( body, "%[%[.-%]%]" )
i = 1 j = 1 while mw.ustring.find(body, "
if i>=10 then j = nil end
body = mw.ustring.gsub(body, "
i = i + 1
end
第148行:
link_str = get_link()
end
body = mw.text.trim(body) .. '
body = mw.ustring.gsub( body, "[Ii][Ss][Bb][Nn]", "ISBN" );
第166行:
body = mw.ustring.gsub( body, categorys, p.nullstr );
end
--Category:使用ISBN魔
body = mw.ustring.gsub( body, "[Ii][Ss][Bb][Nn]", "ISBN" );
body = mw.text.trim(body) --消除多
return body
end
第189行:
end
end
if mw.ustring.find(body, "[Ii][Ss][Bb][Nn]") then category_list["使用ISBN魔
cat_list = {}
i=1
第206行:
get_args = getArgs(frame, {parentFirst=true})
text = mw.ustring.gsub( ((get_args[1] or get_args['1']) or ''), '
input = mw.ustring.gsub(text,'<',"<")
input = mw.ustring.gsub(input,'>',">")
--return mw.ustring.gsub( input .. "
input = mw.ustring.gsub( input, "
return mw.ustring.gsub( input, "`
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 --有冒
check_includetitle = mw.title.new( check_includetitle )
elseif check_includetitle_namespace == 0 and not check_isExternal then --
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
--這部份似乎無解,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
local htagstrip_table = {}
if not mw.isSubsting() then --subst需保留
local htagstrip_matcher = "
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, "
local htag_tail = mw.ustring.gsub(temp_htagstrip, "
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 = '
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)
--用
if mw.isSubsting() then return "
return "
end
local function spantag_regex(chname) return "%<%s-span[^%>]+id=[%
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("[^
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("[^
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("[^
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, "
body = mw.ustring.gsub(body, "
i = i + 1
end
第513行 ⟶ 第543行:
body = input_str
end
if full_include==true then --
--匹配noinclude等
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 --
--
body = '
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={} --
for ik, iv in ipairs(htagstrip_table) do
if iv.name == check_title or iv.name == chapterothername then
第549行 ⟶ 第579行:
end
--
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 = "
for _=2,min_title do body = "== ==
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,"
if start then body =mw.ustring.sub(body, start+1, #body) end
body = mw.text.trim(body)
第602行 ⟶ 第632行:
end
str = '
--^$()%.[]*+-?
第615行 ⟶ 第645行:
cutted_title_matcher = mw.ustring.gsub(mw.ustring.gsub(cutted_title_matcher, "%{", "%{") , "%}", "%}")
cutted_title_matcher = "
title_matcher = "
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, "=+ *
count = end_ - begin_ + 1
end
next_title_matcher = "
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, "
body = mw.ustring.gsub(body, "
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
| |||