Module:TemplateListEntry

From Soyjak Wiki, the free ensoyclopedia
Jump to navigationJump to search

Fixes a bug in {{TemplateListEntry}} that caused /doc category links to bleed into the index page and categorize the index page erroneously.



local p = {}

function p.main(frame)
	local name = frame.args[1]
	local title = name and mw.title.new("Template:" .. name .. "/doc")
	if title and title.redirectTarget then
		title = title.redirectTarget
	end
	local text = title and title:getContent()

	if not text then
		return frame.args[2] or ""
	end

	text = text:gsub("<includeonly%s*>.-</includeonly%s*>", "")
	text = text:gsub("<includeonly%s*>.*$", "")
	local child = frame:newChild({ title = title.prefixedText, args = {} })
	text = child:preprocess(text)

	return child:preprocess(
		'<details><summary class="expand-summary">'
			.. "''Click to expand documentation''"
			.. "</summary>\n__NOEDITSECTION__\n"
			.. text
			.. "\n</details>"
	)
end

return p