Module:Transcluder: Difference between revisions
Richardpruen (talk | contribs) m 1 revision imported: Templates and CSS files |
imported>Sophivorus m Set enwiki as central version |
||
Line 1: | Line 1: | ||
-- Module:Transcluder is a general-purpose transclusion engine | -- Module:Transcluder is a general-purpose transclusion engine | ||
-- | -- Central version and documentation at https://en.wikipedia.org/wiki/Module:Transcluder | ||
-- By User:Sophivorus, User:Certes & others | -- By User:Sophivorus, User:Certes & others | ||
-- Version 1. | -- Version 1.4.1 | ||
-- License CC-BY-SA-3.0 | -- License CC-BY-SA-3.0 | ||
Line 267: | Line 267: | ||
local params, count, parts, key, value | local params, count, parts, key, value | ||
for template in string.gmatch(text, '{%b{}}') do | for template in string.gmatch(text, '{%b{}}') do | ||
params = string.match(template, '{{[^|}]-|(. | params = string.match(template, '{{[^|}]-|(.*)}}') | ||
if params then | if params then | ||
count = 0 | count = 0 | ||
-- Temporarily replace pipes in subtemplates, tables and links to avoid chaos | -- Temporarily replace pipes in subtemplates, tables and links to avoid chaos | ||
for subtemplate in string.gmatch(params, '%b{}') do | for subtemplate in string.gmatch(params, '%b{}') do | ||
params = string.gsub(params, escapeString(subtemplate), | params = string.gsub(params, escapeString(subtemplate), string.gsub(subtemplate, ".", {["%"]="%%", ["|"]="@@:@@", ["="]="@@_@@"}) ) | ||
end | end | ||
for link in string.gmatch(params, '%b[]') do | for link in string.gmatch(params, '%b[]') do | ||
params = string.gsub(params, escapeString( | params = string.gsub(params, escapeString(link), string.gsub(link, ".", {["%"]="%%", ["|"]="@@:@@", ["="]="@@_@@"}) ) | ||
end | end | ||
for parameter in mw.text.gsplit(params, '|') do | for parameter in mw.text.gsplit(params, '|') do | ||
parts = mw.text.split(parameter, '=') | parts = mw.text.split(parameter, '=') | ||
key = mw.text.trim(parts[1]) | key = mw.text.trim(parts[1]) | ||
if #parts == 1 then | |||
value = key | value = key | ||
count = count + 1 | count = count + 1 | ||
key = count | key = count | ||
else | else | ||
value = mw.text.trim( | value = mw.text.trim(table.concat(parts, '=', 2)) | ||
end | end | ||
value = string.gsub(value, '@@@', '|') | value = string.gsub(string.gsub(value, '@@:@@', '|'), '@@_@@', '=') | ||
if not blacklist and ( not flags or matchFlag(key, flags) ) | if not blacklist and ( not flags or matchFlag(key, flags) ) | ||
or blacklist and flags and not matchFlag(key, flags) then | or blacklist and flags and not matchFlag(key, flags) then | ||
Line 571: | Line 570: | ||
local lang = mw.language.getContentLanguage() | local lang = mw.language.getContentLanguage() | ||
local page = escapeString(mw.title.getCurrentTitle().prefixedText) | local page = escapeString(mw.title.getCurrentTitle().prefixedText) | ||
local ucpage = lang:ucfirst(page) | |||
local lcpage = lang:lcfirst(page) | |||
text = text | text = text | ||
:gsub('%[%[(' .. | :gsub('%[%[(' .. ucpage .. ')%]%]', '%1') | ||
:gsub('%[%[(' .. | :gsub('%[%[(' .. lcpage .. ')%]%]', '%1') | ||
:gsub('%[%[' .. | :gsub('%[%[' .. ucpage .. '|([^]]+)%]%]', '%1') | ||
:gsub('%[%[' .. | :gsub('%[%[' .. lcpage .. '|([^]]+)%]%]', '%1') | ||
return text | return text | ||
end | end |