<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://linguifex.com/w/index.php?action=history&amp;feed=atom&amp;title=Module%3Astring%2FremoveComments</id>
	<title>Module:string/removeComments - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://linguifex.com/w/index.php?action=history&amp;feed=atom&amp;title=Module%3Astring%2FremoveComments"/>
	<link rel="alternate" type="text/html" href="https://linguifex.com/w/index.php?title=Module:string/removeComments&amp;action=history"/>
	<updated>2026-04-22T00:13:33Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://linguifex.com/w/index.php?title=Module:string/removeComments&amp;diff=494884&amp;oldid=prev</id>
		<title>Sware: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://linguifex.com/w/index.php?title=Module:string/removeComments&amp;diff=494884&amp;oldid=prev"/>
		<updated>2026-04-21T11:22:50Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 11:22, 21 April 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Sware</name></author>
	</entry>
	<entry>
		<id>https://linguifex.com/w/index.php?title=Module:string/removeComments&amp;diff=494883&amp;oldid=prev</id>
		<title>wikt&gt;Theknightwho at 00:43, 22 May 2025</title>
		<link rel="alternate" type="text/html" href="https://linguifex.com/w/index.php?title=Module:string/removeComments&amp;diff=494883&amp;oldid=prev"/>
		<updated>2025-05-22T00:43:51Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local concat = table.concat&lt;br /&gt;
local find = string.find&lt;br /&gt;
local sub = string.sub&lt;br /&gt;
&lt;br /&gt;
local function remove_comments(str, pre)&lt;br /&gt;
	local pos1 = find(str, &amp;quot;&amp;lt;!--&amp;quot;, nil, true)&lt;br /&gt;
	if not pos1 then&lt;br /&gt;
		return str&lt;br /&gt;
	end&lt;br /&gt;
	local pos2 = find(str, &amp;quot;--&amp;gt;&amp;quot;, pos1 + 4, true)&lt;br /&gt;
	if not pos2 then&lt;br /&gt;
		return pre and sub(str, 1, pos1 - 1) or str&lt;br /&gt;
	end&lt;br /&gt;
	local ret = sub(str, 1, pos1 - 1)&lt;br /&gt;
	pos1 = pos2 + 3&lt;br /&gt;
	pos2 = find(str, &amp;quot;&amp;lt;!--&amp;quot;, pos1, true)&lt;br /&gt;
	if not pos2 then&lt;br /&gt;
		return ret .. sub(str, pos1)&lt;br /&gt;
	end&lt;br /&gt;
	local pos3 = find(str, &amp;quot;--&amp;gt;&amp;quot;, pos2 + 4, true)&lt;br /&gt;
	if not pos3 then&lt;br /&gt;
		return ret .. sub(str, pos1, pre and pos2 - 1 or nil)&lt;br /&gt;
	end&lt;br /&gt;
	ret = {ret, sub(str, pos1, pos2 - 1)}&lt;br /&gt;
	local n = 2&lt;br /&gt;
	while true do&lt;br /&gt;
		pos1 = pos3 + 3&lt;br /&gt;
		pos2 = find(str, &amp;quot;&amp;lt;!--&amp;quot;, pos1, true)&lt;br /&gt;
		if not pos2 then&lt;br /&gt;
			return concat(ret) .. sub(str, pos1)&lt;br /&gt;
		end&lt;br /&gt;
		pos3 = find(str, &amp;quot;--&amp;gt;&amp;quot;, pos2 + 4, true)&lt;br /&gt;
		if not pos3 then&lt;br /&gt;
			return concat(ret) .. sub(str, pos1, pre and pos2 - 1 or nil)&lt;br /&gt;
		end&lt;br /&gt;
		n = n + 1&lt;br /&gt;
		ret[n] = sub(str, pos1, pos2 - 1)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[==[Removes any HTML comments from the input text. `stage` can be one of three options:&lt;br /&gt;
* {&amp;quot;PRE&amp;quot;} (default) applies the method used by MediaWiki&amp;#039;s preprocessor: all {{code|html|&amp;lt;nowiki&amp;gt;&amp;lt;!-- ... --&amp;gt;&amp;lt;/nowiki&amp;gt;}} pairs are removed, as well as any text after an unclosed {{code|html|&amp;lt;nowiki&amp;gt;&amp;lt;!--&amp;lt;/nowiki&amp;gt;}}. This is generally suitable when parsing raw template or [[mw:Parser extension tags|parser extension tag]] code. (Note, however, that the actual method used by the preprocessor is considerably more complex and differs under certain conditions (e.g. comments inside nowiki tags); if full accuracy is absolutely necessary, use [[Module:template parser]] instead).&lt;br /&gt;
* {&amp;quot;POST&amp;quot;} applies the method used to generate the final page output once all templates have been expanded: it loops over the text, removing any {{code|html|&amp;lt;nowiki&amp;gt;&amp;lt;!-- ... --&amp;gt;&amp;lt;/nowiki&amp;gt;}} pairs until no more are found (e.g. {{code|html|&amp;lt;nowiki&amp;gt;&amp;lt;!-&amp;lt;!-- ... --&amp;gt;- ... --&amp;gt;&amp;lt;/nowiki&amp;gt;}} would be fully removed), but any unclosed {{code|html|&amp;lt;nowiki&amp;gt;&amp;lt;!--&amp;lt;/nowiki&amp;gt;}} is ignored. This is suitable for handling links embedded in template inputs, where the {&amp;quot;PRE&amp;quot;} method will have already been applied by the native parser.&lt;br /&gt;
* {&amp;quot;BOTH&amp;quot;} applies {&amp;quot;PRE&amp;quot;} then {&amp;quot;POST&amp;quot;}.]==]&lt;br /&gt;
return function(str, stage)&lt;br /&gt;
	if stage == nil or stage == &amp;quot;PRE&amp;quot; then&lt;br /&gt;
		return remove_comments(str, true)&lt;br /&gt;
	elseif stage == &amp;quot;BOTH&amp;quot; then&lt;br /&gt;
		str = remove_comments(str, true)&lt;br /&gt;
	elseif stage ~= &amp;quot;POST&amp;quot; then&lt;br /&gt;
		error(&amp;quot;bad argument #2 to &amp;#039;remove_comments&amp;#039; (expected PRE, POST, or BOTH)&amp;quot;, 2)&lt;br /&gt;
	end&lt;br /&gt;
	while true do&lt;br /&gt;
		local processed = remove_comments(str)&lt;br /&gt;
		if processed == str then&lt;br /&gt;
			return str&lt;br /&gt;
		end&lt;br /&gt;
		str = processed&lt;br /&gt;
	end&lt;br /&gt;
end&lt;/div&gt;</summary>
		<author><name>wikt&gt;Theknightwho</name></author>
	</entry>
</feed>