Module:munge text

Hello, you have come here looking for the meaning of the word Module:munge text. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:munge text, but we will also tell you about its etymology, its characteristics and you will know how to say Module:munge text in singular and plural. Everything you need to know about the word Module:munge text you have here. The definition of the word Module:munge text will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:munge text, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

Applies a function fn to text, but not any HTML tags or wikilink targets within.


return function(text, fn)
	local has_html = text:find("<")
	local has_two_part_link = text:find("%[%[.*|")
	if not has_html and not has_two_part_link then
		return fn(text)
	end

	local function do_munge(text, pattern, functor)
		local index = 1
		local length = mw.ustring.len(text)
		local result = ""
		pattern = "(.-)(" .. pattern .. ")"
		while index <= length do
			local first, last, before, match = mw.ustring.find(text, pattern, index)
			if not first then
				result = result .. functor(mw.ustring.sub(text, index))
				break
			end
			result = result .. functor(before) .. match
			index = last + 1
		end
		return result
	end
	
	local function munge_text_with_html(txt)
		return do_munge(txt, "<->", fn)
	end

	if has_two_part_link then -- contains wikitext links
		return do_munge(text, "%|]-|", has_html and munge_text_with_html or fn)
	else -- HTML tags only
		return munge_text_with_html(text)
	end
end