<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.stiles.casa/index.php?action=history&amp;feed=atom&amp;title=Module%3APlain_text%2Fsandbox</id>
	<title>Module:Plain text/sandbox - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.stiles.casa/index.php?action=history&amp;feed=atom&amp;title=Module%3APlain_text%2Fsandbox"/>
	<link rel="alternate" type="text/html" href="https://wiki.stiles.casa/index.php?title=Module:Plain_text/sandbox&amp;action=history"/>
	<updated>2026-05-18T12:46:52Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.2</generator>
	<entry>
		<id>https://wiki.stiles.casa/index.php?title=Module:Plain_text/sandbox&amp;diff=6733&amp;oldid=prev</id>
		<title>imported&gt;Ahecht: fix encode</title>
		<link rel="alternate" type="text/html" href="https://wiki.stiles.casa/index.php?title=Module:Plain_text/sandbox&amp;diff=6733&amp;oldid=prev"/>
		<updated>2021-09-02T14:22:20Z</updated>

		<summary type="html">&lt;p&gt;fix encode&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--converts text with wikilinks to plain text, e.g &amp;quot;[[foo|gah]] is [[bar]]&amp;quot; to &amp;quot;gah is bar&amp;quot;&lt;br /&gt;
--removes anything enclosed in tags that isn&amp;#039;t nested, mediawiki strip markers (references etc), files, italic and bold markup&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
function p.main(frame)&lt;br /&gt;
	local text = frame.args[1]&lt;br /&gt;
	local encode = require(&amp;#039;Module:yesno&amp;#039;)(frame.args.encode)&lt;br /&gt;
	return p._main(text, encode)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._main(text, encode)&lt;br /&gt;
	if not text then return end&lt;br /&gt;
	text = mw.text.killMarkers(text)&lt;br /&gt;
		:gsub(&amp;#039;&amp;amp;nbsp;&amp;#039;, &amp;#039; &amp;#039;) --replace nbsp spaces with regular spaces&lt;br /&gt;
		:gsub(&amp;#039;&amp;lt;br ?/?&amp;gt;&amp;#039;, &amp;#039;, &amp;#039;) --replace br with commas&lt;br /&gt;
		:gsub(&amp;#039;&amp;lt;(%a+)[^&amp;gt;]+&amp;gt;(.-)&amp;lt;/%1&amp;gt;&amp;#039;, function(tag, contents)&lt;br /&gt;
			if tag:lower() == &amp;#039;span&amp;#039; then&lt;br /&gt;
				return contents&lt;br /&gt;
			else&lt;br /&gt;
				return &amp;#039;&amp;#039;&lt;br /&gt;
			end&lt;br /&gt;
		end)&lt;br /&gt;
		:gsub(&amp;#039;&amp;lt;i[^&amp;gt;]+&amp;gt;([^&amp;lt;]+)&amp;lt;/i&amp;gt;&amp;#039;, &amp;#039;%1&amp;#039;) --remove italics while keeping text inside&lt;br /&gt;
		:gsub(&amp;#039;&amp;lt;[^&amp;gt;]+&amp;gt;[^&amp;lt;]+&amp;lt;[^&amp;gt;]+&amp;gt;&amp;#039;, &amp;#039;&amp;#039;) --strip out remaining tags and the text inside&lt;br /&gt;
		:gsub(&amp;#039;%b&amp;lt;&amp;gt;&amp;#039;, &amp;#039;&amp;#039;) --remove any other tag markup&lt;br /&gt;
		:gsub(&amp;#039;__[^_]+__&amp;#039;, &amp;#039;&amp;#039;) --remove __ markups&lt;br /&gt;
		:gsub(&amp;#039;^=+[^=]+=+&amp;#039;, &amp;#039;&amp;#039;):gsub(&amp;#039;\n=+[^=]+=+&amp;#039;, &amp;#039;&amp;#039;) --remove section titles		&lt;br /&gt;
		:gsub(&amp;#039;%b[]&amp;#039;,&lt;br /&gt;
			function(bracketed)&lt;br /&gt;
				return bracketed:gsub(&amp;#039;^%[%[%s*(%a+):.-%]%]$&amp;#039;,&lt;br /&gt;
					function(link_prefix)&lt;br /&gt;
						link_prefix = link_prefix:lower()&lt;br /&gt;
						if link_prefix == &amp;#039;image&amp;#039; or link_prefix == &amp;#039;file&amp;#039;&lt;br /&gt;
						or link_prefix == &amp;#039;media&amp;#039; or link_prefix == &amp;#039;category&amp;#039; then&lt;br /&gt;
							return &amp;quot;&amp;quot;&lt;br /&gt;
						end -- otherwise leave it alone&lt;br /&gt;
					end)&lt;br /&gt;
			end)&lt;br /&gt;
		:gsub(&amp;#039;%[%[[^%]|]+|&amp;#039;, &amp;#039;&amp;#039;) --strip out piped link text&lt;br /&gt;
		:gsub(&amp;#039;([^%[])%[[^%[%]][^%]]-%s&amp;#039;, &amp;#039;%1&amp;#039;) --strip out external link text&lt;br /&gt;
		:gsub(&amp;#039;^%[[^%[%]][^%]]-%s&amp;#039;, &amp;#039;&amp;#039;) --strip out external link text&lt;br /&gt;
		:gsub(&amp;#039;[%[%]]&amp;#039;, &amp;#039;&amp;#039;) --then strip out remaining [ and ]&lt;br /&gt;
		:gsub(&amp;quot;&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;quot;, &amp;quot;&amp;quot;) --strip out bold italic markup&lt;br /&gt;
		:gsub(&amp;quot;&amp;#039;&amp;#039;&amp;#039;?&amp;quot;, &amp;quot;&amp;quot;) --not stripping out &amp;#039;&amp;#039;&amp;#039;&amp;#039; gives correct output for bolded text in quotes&lt;br /&gt;
		:gsub(&amp;#039;----&amp;#039;, &amp;#039;&amp;#039;) --remove ---- lines&lt;br /&gt;
		:gsub(&amp;#039;^%s+&amp;#039;, &amp;#039;&amp;#039;):gsub(&amp;#039;\n%s+&amp;#039;, &amp;#039;\n&amp;#039;) --strip leading&lt;br /&gt;
		:gsub(&amp;#039;%s+$&amp;#039;, &amp;#039;&amp;#039;):gsub(&amp;#039;%s+\n&amp;#039;, &amp;#039;\n&amp;#039;) --and trailing spaces&lt;br /&gt;
		:gsub(&amp;#039;(%s)%s+&amp;#039;, &amp;#039;%1&amp;#039;) --strip redundant spaces&lt;br /&gt;
	if encode then&lt;br /&gt;
		return mw.text.encode(text)&lt;br /&gt;
	else&lt;br /&gt;
		return text&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;Ahecht</name></author>
	</entry>
</feed>