Module:HasTag: Difference between revisions

From bg3.wiki
Jump to navigation Jump to search
(Created page with "local p = {} function p.main(frame) return p.hasTag(frame.args[1], frame.args[2]) end function p.hasTag(tag, wikitext) if tag:len() > 50 then error("Tag too long: " .. tag) end local i = wikitext:find('\'"`UNIQ%-%-' .. tag .. '%-') if i == nil then return '' else return i end end return p")
 
No edit summary
Line 10: Line 10:
end
end
local i = wikitext:find('\'"`UNIQ%-%-' .. tag .. '%-')
local i = wikitext:find('\'"`UNIQ%-%-' .. tag .. '%-')
if i == nil then
return ''
else
return i
end
end
function p.main2(frame)
return p.hasTag2(frame.args[1], frame.args[2])
end
function p.hasTag2(tag, wikitext)
if tag:len() > 50 then
error("Tag too long: " .. tag)
end
local i = wikitext:find('UNIQ.-' .. tag)
if i == nil then
if i == nil then
return ''
return ''

Revision as of 22:15, 10 June 2024

Doc page: Module:HasTag/doc

{{#invoke:HasTag | main | TAG | WIKITEXT }}

Checks whether the tag named TAG occurs within WIKITEXT. Returns the position of the tag if found, empty otherwise.

Example: {{#invoke:HasTag | main | nowiki | Blah <nowiki>blep</nowiki> blub. }}

Result:

Note: This only works with parser tags, not HTML tags. For example, it wouldn't work with <div> or <code>, but it works with <gallery> or <nowiki>. (HTML tags can be searched for with regular parser string functions.)


local p = {}

function p.main(frame)
	return p.hasTag(frame.args[1], frame.args[2])
end

function p.hasTag(tag, wikitext)
	if tag:len() > 50 then
		error("Tag too long: " .. tag)
	end
	local i = wikitext:find('\'"`UNIQ%-%-' .. tag .. '%-')
	if i == nil then
		return ''
	else
		return i
	end
end

function p.main2(frame)
	return p.hasTag2(frame.args[1], frame.args[2])
end

function p.hasTag2(tag, wikitext)
	if tag:len() > 50 then
		error("Tag too long: " .. tag)
	end
	local i = wikitext:find('UNIQ.-' .. tag)
	if i == nil then
		return ''
	else
		return i
	end
end

return p