Bearbeiten von „Modul:TemplUtl“
Zur Navigation springen
Zur Suche springen
Die Bearbeitung kann rückgängig gemacht werden. Bitte prüfe den Vergleich unten, um sicherzustellen, dass du dies tun möchtest, und veröffentliche dann unten deine Änderungen, um die Bearbeitung rückgängig zu machen.
Aktuelle Version | Dein Text | ||
Zeile 1: | Zeile 1: | ||
local TemplUtl = { suite = "TemplUtl", | local TemplUtl = { suite = "TemplUtl", | ||
serial = " | serial = "2016-02-28" }; | ||
local Delimiters; | |||
local | |||
Zeile 39: | Zeile 10: | ||
-- accept -- string; trimmed title | -- accept -- string; trimmed title | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns string with pattern | ||
local start = mw.ustring.sub( accept, 1, 1 ); | local start = mw.ustring.sub( accept, 1, 1 ); | ||
local r; | local r; | ||
Zeile 52: | Zeile 23: | ||
if r:match( " " ) then | if r:match( " " ) then | ||
r = r:gsub( "%", "%%" ) | r = r:gsub( "%", "%%" ) | ||
:gsub( "[ | :gsub( "[^.?+*()$]+", "%$1" ) | ||
:gsub( "_", " " ) | :gsub( "_", " " ) | ||
:gsub( "%s+", "[%s_]+" ); | :gsub( "%s+", "[%s_]+" ); | ||
Zeile 58: | Zeile 29: | ||
return r; | return r; | ||
end -- fiatTitleRegExp() | end -- fiatTitleRegExp() | ||
Zeile 260: | Zeile 37: | ||
-- address -- string; what to inspect, URL presumed | -- address -- string; what to inspect, URL presumed | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns true, if URL beginning | ||
local start, r = address:match( "^%s*((%a*:?)//)" ); | local start, r = address:match( "^%s*((%a*:?)//)" ); | ||
if start then | if start then | ||
Zeile 290: | Zeile 67: | ||
-- after -- true, if only to search for "}}" | -- after -- true, if only to search for "}}" | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns | ||
-- -- number; byte position in area | -- -- number; byte position in area | ||
-- -- before "|" or "}}", may be at end | -- -- before "|" or "}}", may be at end | ||
Zeile 427: | Zeile 204: | ||
-- at -- optional number; byte position in area of "{{" | -- at -- optional number; byte position in area of "{{" | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns | ||
-- -- table | -- -- table | ||
-- [0] -- template, page, parser function name | -- [0] -- template, page, parser function name | ||
Zeile 494: | Zeile 271: | ||
-- ask -- string; parameter name | -- ask -- string; parameter name | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns string with trimmed parameter value, or nil | ||
-- Does not return value if template inside | -- Does not return value if template inside | ||
local r; | local r; | ||
Zeile 525: | Zeile 302: | ||
-- no colon (:) | -- no colon (:) | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns ustring position of "{{" in area, or false | ||
-- Requires: | -- Requires: | ||
-- fiatTitleRegExp() | -- fiatTitleRegExp() | ||
Zeile 591: | Zeile 368: | ||
-- 3 4 5 6 | -- 3 4 5 6 | ||
-- more like 2 | -- more like 2 | ||
Zeile 608: | Zeile 374: | ||
-- Remove syntax elements that hide effective syntax only | -- Remove syntax elements that hide effective syntax only | ||
-- Precondition: | -- Precondition: | ||
-- area -- string; | -- area -- string; wikitext to be reduced | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns cleared wikitext | ||
local delimiters = { { "<%s*NOWIKI%s*>", "<%s*/%s*NOWIKI%s*>" }, | local delimiters = { { "<%s*NOWIKI%s*>", "<%s*/%s*NOWIKI%s*>" }, | ||
{ "<!--", "-->", true }, | { "<!--", "-->", true }, | ||
Zeile 619: | Zeile 385: | ||
local r = area; | local r = area; | ||
local k, m, n; | local k, m, n; | ||
if not | if not Delimiters then | ||
local c, sD, sP; | local c, sD, sP; | ||
Delimiters = { }; | |||
for j = 1, #delimiters do | for j = 1, #delimiters do | ||
table.insert( | table.insert( Delimiters, { } ); | ||
for ji = 1, 2 do | for ji = 1, 2 do | ||
sD = delimiters[ j ][ ji ]; | sD = delimiters[ j ][ ji ]; | ||
Zeile 636: | Zeile 402: | ||
end | end | ||
end -- for js | end -- for js | ||
table.insert( | table.insert( Delimiters[ j ], sP ); | ||
end -- for ji | end -- for ji | ||
end -- for j | end -- for j | ||
Zeile 643: | Zeile 409: | ||
k = false; | k = false; | ||
for j = 1, #delimiters do | for j = 1, #delimiters do | ||
m = r:find( | m = r:find( Delimiters[ j ][ 1 ], | ||
i, | i, | ||
Delimiters[ j ][ 3 ] ); | |||
if m and ( not k or m < k ) then | if m and ( not k or m < k ) then | ||
k = m; | k = m; | ||
Zeile 659: | Zeile 425: | ||
s = ""; | s = ""; | ||
end | end | ||
j, m = r:find( | j, m = r:find( Delimiters[ n ][ 2 ], | ||
k + 1, | k + 1, | ||
Delimiters[ n ][ 3 ] ); | |||
if m then | if m then | ||
r = s .. r:sub( m + 1 ); | r = s .. r:sub( m + 1 ); | ||
Zeile 674: | Zeile 440: | ||
return r; | return r; | ||
end -- TemplUtl.flat() | end -- TemplUtl.flat() | ||
Zeile 735: | Zeile 446: | ||
local p = { }; | local p = { }; | ||
function p. | function p.failsafe() | ||
return TemplUtl.serial | |||
end | |||
return | |||
p.TemplUtl = function () | p.TemplUtl = function () | ||
return TemplUtl; | return TemplUtl; | ||
end | end | ||
return p; | return p; |