モジュール:DeleteCountryIcon

出典: 謎の百科事典もどき『エンペディア(Enpedia)』
ナビゲーションに移動 検索に移動

ここに呼び出す説明文 『 モジュール:DeleteCountryIcon/doc 』 が作成されていません。

local p = {}

function p.main(frame)
	local input = frame.args[1] or ""

	-- 1. 画像リンク部分([[File:...]] や [[ファイル:...]])を削除
	input = mw.ustring.gsub(input, "%[%[[Ff]ile:[^%]]+%]%]", "")
	input = mw.ustring.gsub(input, "%[%[ファイル:[^%]]+%]%]", "")

	-- 2. 通常リンク [[Page|Label]] のラベルを取得
	local label = mw.ustring.match(input, "%[%[[^|%]]+|([^%]]+)%]%]")
	if label then
		return label
	end

	-- 3. 通常リンク [[Page]] のページ名を取得
	local plain = mw.ustring.match(input, "%[%[([^%]|]+)%]%]")
	if plain then
		return plain
	end

	-- 4. それ以外はそのまま返す(リンクなし)
	return mw.text.trim(input)
end

return p