Modul:TemplUtl: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
2015-02-12
K (Schützte „Modul:TemplUtl“: Häufig eingebundenes Modul ([Bearbeiten=Nur angemeldete, nicht neue Benutzer] (unbeschränkt) [Verschieben=Nur Administratoren] (unbeschränkt))) |
(2015-02-12) |
||
Zeile 1: | Zeile 1: | ||
local TemplUtl = { suite = "TemplUtl", | |||
serial = "2015-02-12" }; | |||
local Delimiters; | |||
Zeile 11: | Zeile 11: | ||
-- Postcondition: | -- Postcondition: | ||
-- Returns string with pattern | -- Returns string with pattern | ||
local start = mw.ustring.sub( accept, 1, 1 ); | |||
local r; | local r; | ||
if mw.ustring.match( start, "%a" ) then | if mw.ustring.match( start, "%a" ) then | ||
r = string.format( "[%s%s]%s", | r = string.format( "[%s%s]%s", | ||
Zeile 29: | Zeile 29: | ||
return r; | return r; | ||
end -- fiatTitleRegExp() | end -- fiatTitleRegExp() | ||
Zeile 208: | Zeile 204: | ||
-- at -- optional number; byte position in area of "{{" | -- at -- optional number; byte position in area of "{{" | ||
-- Postcondition: | -- Postcondition: | ||
-- Returns | -- Returns | ||
-- [0] template, page, parser function name | -- -- table | ||
-- [0] -- template, page, parser function name | |||
-- [1] -- unnamed parameter | |||
-- ["name"] -- named parameter | |||
-- -- string; error message, if any, else nil | |||
local n = 0; | local n = 0; | ||
local j, k, p, r, r2, s, v; | local j, k, p, r, r2, s, v; | ||
Zeile 305: | Zeile 305: | ||
-- Requires: | -- Requires: | ||
-- fiatTitleRegExp() | -- fiatTitleRegExp() | ||
local scan = string.format( "{{%s%s%s", | local scan = string.format( "{{%s%s%s", | ||
"([%w_%s:]*)%s*", | "([%w_%s:]*)%s*", | ||
fiatTitleRegExp( access ), | fiatTitleRegExp( access ), | ||
"%s*([|}<]!?)" ); | "%s*([|}<]!?)" ); | ||
local r, space, start, suffix; | |||
if type( at ) == "number" then | if type( at ) == "number" then | ||
r = at; | r = at; | ||
Zeile 361: | Zeile 361: | ||
return r; | return r; | ||
end -- TemplUtl.find() | end -- TemplUtl.find() | ||
-- finder() | |||
-- 1 page name | |||
-- 2 template title / page name | |||
-- 3 4 5 6 | |||
-- more like 2 | |||
TemplUtl.flat = function ( area ) | |||
-- Remove syntax elements that hide effective syntax only | |||
-- Precondition: | |||
-- area -- string; wikitext to be reduced | |||
-- Postcondition: | |||
-- Returns cleared wikitext | |||
local delimiters = { { "<%s*NOWIKI%s*>", "<%s*/%s*NOWIKI%s*>" }, | |||
{ "<!--", "-->" }, | |||
{ "<%s*PRE%s*>", "<%s*/%s*PRE%s*>" }, | |||
{ "<%s*SYNTAXHIGHLIGHT[^<>]*>", | |||
"<%s*/%s*SYNTAXHIGHLIGHT%s*>" } }; | |||
local i = 1; | |||
local r = area; | |||
local k, m, n; | |||
if not Delimiters then | |||
local c, sD, sP; | |||
Delimiters = { }; | |||
for j = 1, #delimiters do | |||
table.insert( Delimiters, { } ); | |||
for ji = 1, 2 do | |||
sD = delimiters[ j ][ ji ]; | |||
sP = ""; | |||
for js = 1, #sD, 1 do | |||
c = sD:byte( js, js ); | |||
if c >= 65 and c <= 90 then | |||
sP = string.format( "%s[%c%c]", | |||
sP, c, c + 32 ); | |||
else | |||
sP = sP .. string.char( c ); | |||
end | |||
end -- for js | |||
table.insert( Delimiters[ j ], sP ); | |||
end -- for ji | |||
end -- for j | |||
end | |||
while ( true ) do | |||
k = false; | |||
for j = 1, #delimiters do | |||
m = r:find( Delimiters[ j ][ 1 ], i ); | |||
if m and ( not k or m > k ) then | |||
k = m; | |||
n = j; | |||
end | |||
end -- for j | |||
if k then | |||
local s | |||
if k > 1 then | |||
s = r:sub( 1, k - 1 ); | |||
else | |||
s = ""; | |||
end | |||
j, m = r:find( Delimiters[ n ][ 2 ], k + 1 ); | |||
if m then | |||
r = s .. r:sub( m + 1 ); | |||
else | |||
r = s; | |||
break; -- while true | |||
end | |||
else | |||
break; -- while true | |||
end | |||
end -- while true | |||
return r; | |||
end -- TemplUtl.flat() | |||