<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://neo-akurasu.duckdns.org/index.php?action=history&amp;feed=atom&amp;title=Module%3ATextReplacer</id>
	<title>Module:TextReplacer - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://neo-akurasu.duckdns.org/index.php?action=history&amp;feed=atom&amp;title=Module%3ATextReplacer"/>
	<link rel="alternate" type="text/html" href="http://neo-akurasu.duckdns.org/index.php?title=Module:TextReplacer&amp;action=history"/>
	<updated>2026-04-24T19:25:24Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.3</generator>
	<entry>
		<id>http://neo-akurasu.duckdns.org/index.php?title=Module:TextReplacer&amp;diff=61470&amp;oldid=prev</id>
		<title>Daichi: New Module to replace text on a page.</title>
		<link rel="alternate" type="text/html" href="http://neo-akurasu.duckdns.org/index.php?title=Module:TextReplacer&amp;diff=61470&amp;oldid=prev"/>
		<updated>2024-09-05T05:23:55Z</updated>

		<summary type="html">&lt;p&gt;New Module to replace text on a page.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--[[&lt;br /&gt;
    Module:Example&lt;br /&gt;
&lt;br /&gt;
    This module provides a function to perform text replacements on a specified page&lt;br /&gt;
    using a template replacement table defined in a separate page.&lt;br /&gt;
&lt;br /&gt;
    Usage: {{#invoke:Example|main|BasicPage=OriginalPage|ReplaceList=ReplacementsTable}}&lt;br /&gt;
&lt;br /&gt;
    Parameters:&lt;br /&gt;
    - BasicPage: The name of the page on which the text replacements should be performed.&lt;br /&gt;
    - ReplaceList: The name of the page containing the replacement table.&lt;br /&gt;
&lt;br /&gt;
    Replacement Table Format:&lt;br /&gt;
    The replacement table should be defined in the following format:&lt;br /&gt;
    `Key1`||Replacement1;&lt;br /&gt;
    `Key2`||Replacement2;&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
    - Each line represents a single replacement entry.&lt;br /&gt;
    - The key and replacement value are separated by &amp;quot;||&amp;quot;.&lt;br /&gt;
    - The key should be enclosed in backticks (`).&lt;br /&gt;
    - The replacement value can contain wikitext formatting.&lt;br /&gt;
    - Each line should end with a semicolon (;).&lt;br /&gt;
    - Empty lines are ignored.&lt;br /&gt;
&lt;br /&gt;
    Example Replacement Table:&lt;br /&gt;
    `A`||&amp;#039;&amp;#039;&amp;#039;Apple&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
    `B`||&amp;#039;&amp;#039;Banana&amp;#039;&amp;#039;;&lt;br /&gt;
    `C`||Carrot;&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
function p.main(frame)&lt;br /&gt;
    local args = frame.args&lt;br /&gt;
    local BasicPage = frame.args[&amp;#039;BasicPage&amp;#039;]&lt;br /&gt;
    local ReplaceList = frame.args[&amp;#039;ReplaceList&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
    if not BasicPage then&lt;br /&gt;
        return &amp;quot;Error: BasicPage parameter is missing.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if not ReplaceList then&lt;br /&gt;
        return &amp;quot;Error: ReplaceList parameter is missing.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    local replaceTable = {}&lt;br /&gt;
    local replaceContent = frame:expandTemplate{title = ReplaceList}&lt;br /&gt;
    for line in replaceContent:gmatch(&amp;quot;[^\n]+&amp;quot;) do&lt;br /&gt;
        local key, value = line:match(&amp;quot;(`[^`]+`)||([^;]+)&amp;quot;)&lt;br /&gt;
        if key and value then&lt;br /&gt;
            key = mw.text.trim(key)&lt;br /&gt;
            value = mw.text.trim(value)&lt;br /&gt;
            replaceTable[key] = value&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    local page = mw.title.new(BasicPage)&lt;br /&gt;
    if page then&lt;br /&gt;
        local pageContent = page:getContent()&lt;br /&gt;
        if pageContent then&lt;br /&gt;
            -- Perform text replacements based on replaceTable&lt;br /&gt;
            for key, value in pairs(replaceTable) do&lt;br /&gt;
                pageContent = pageContent:gsub(key, value)&lt;br /&gt;
            end&lt;br /&gt;
            return pageContent&lt;br /&gt;
        else&lt;br /&gt;
            return &amp;quot;Page &amp;quot; .. BasicPage .. &amp;quot; exists but has no content.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
    else&lt;br /&gt;
        return &amp;quot;Page &amp;quot; .. BasicPage .. &amp;quot; does not exist.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Daichi</name></author>
	</entry>
</feed>