モジュール:Citation/Simulate CS1 errors

このモジュールについての説明文ページを モジュール:Citation/Simulate CS1 errors/doc に作成できます

require('strict')

local function main(frame)
	local cs_module = frame.args.Module or ''
	local visible = frame.args.Visible or ''
	
	if cs_module == '' then
		cs_module = 'CS1'
	end
	
	local res = require('Module:Citation/' .. cs_module).citation(frame)
	
	-- CS1/CS-jaモジュールの出力から主要部とCOinSメタデータを除去する
	res = mw.ustring.gsub(res, '%<cite .-%</cite%>', '')
	res = mw.ustring.gsub(res, '%<span title="ctx_ver=Z39%.88%-2004.-%</span%>', '')
	
	-- CS1のエラーカテゴリを内部リンクに置き換える
	res = mw.ustring.gsub(res, '%[%[Category:(テンプレート呼び出しエラーのあるページ/CS1/[^]|]+).-%]%]', '[[:Category:%1|⚠]]')
	res = mw.ustring.gsub(res, '%[%[Category:(CS1エラー:[^]|]+).-%]%]', '[[:Category:%1|⚠]]')
	
	-- その他のカテゴリを除去する
	res = mw.ustring.gsub(res, '%[%[Category:.-%]%]', '')
	
	if not mw.ustring.find(res, '<span') then
		-- 出力にメッセージが含まれていなければテンプレートスタイルのマーカーを除去する
		res = mw.ustring.gsub(res, '\127[^\127]*UNIQ%-%-templatestyles%-%x+%-QINU[^\127]*\127', '')
	elseif visible == '' then
		-- Visible引数が空ならばすべてのエラーメッセージを標準で不可視にする
		res = mw.ustring.gsub(res, 'cs1%-visible%-error', 'cs1-hidden-error')
		
		-- エラーメッセージの区切りのセミコロンも不可視化できるようにする
		res = mw.ustring.gsub(res, '</span>; ', '; </span>')
	end
	
	return res
end

return { main = main }