FANDOM


local p = {}
 
function p.test()
	return "Hello, world!"
end
 
 
function p.test2()
    StartText = "It's [[スマイレージ]] and [[ミニモニ。]]."
    _, _, long = string.find(StartText, "%[%[(.*)%]%]")
    _, _, short = string.find(StartText, "%[%[(.-)%]%]")
    EndText = StartText .. " -- LONG: " .. long .. " -- SHORT: " .. short
    return EndText
end
 
function p.test3()
    StartText = "It's [[スマイレージ]] and [[ミニモニ。]] and [[Berryz Koubou|Juice=Juice]]."
    Color = "BLACK"
 
    CurrentText = StartText
 
    itsthere, _ = string.find(CurrentText, "%[%[.*%]%]")
 
    while itsthere do --While there are wikilinks found, keep going.
        _, _, short = string.find(CurrentText, "%[%[(.-)%]%]")
        ispipe, _ = string.find(short, "|")
        if ispipe then
            _, _, shorterTarget = string.find(short, "(.-)|")
            _, _, shorterText = string.find(short, "|(.*)")
        else
            shorterTarget = short
            shorterText = short
        end
        ReplacementLink = "STARTBRACKETS" .. shorterTarget .. "|<span style='color: " .. Color .. ";'>" .. shorterText .. "</span>ENDBRACKETS"
        CurrentText = string.gsub(CurrentText, "%[%[.-%]%]", ReplacementLink, 1)
        itsthere, _ = string.find(CurrentText, "%[%[.*%]%]")
    end --end of the while
 
    --Now put the proper brackets back.
    CurrentText = string.gsub(CurrentText, "STARTBRACKETS", "[[")
    CurrentText = string.gsub(CurrentText, "ENDBRACKETS", "]]")
 
    return CurrentText
end
 
function p.HideWikiLinks(frame)
    StartText=frame.args[1]
    Color=frame.args[2] or "BLACK"
 
    CurrentText = StartText
 
    itsthere, _ = string.find(CurrentText, "%[%[.*%]%]")
 
    while itsthere do --While there are wikilinks found, keep going.
        _, _, short = string.find(CurrentText, "%[%[(.-)%]%]")
        ispipe, _ = string.find(short, "|")
        if ispipe then
            _, _, shorterTarget = string.find(short, "(.-)|")
            _, _, shorterText = string.find(short, "|(.*)")
        else
            shorterTarget = short
            shorterText = short
        end
        ReplacementLink = "STARTBRACKETS" .. shorterTarget .. "|<span style='color: " .. Color .. ";'>" .. shorterText .. "</span>ENDBRACKETS"
        CurrentText = string.gsub(CurrentText, "%[%[.-%]%]", ReplacementLink, 1)
        itsthere, _ = string.find(CurrentText, "%[%[.*%]%]")
    end --end of the while
 
    --Now put the proper brackets back.
    CurrentText = string.gsub(CurrentText, "STARTBRACKETS", "[[")
    CurrentText = string.gsub(CurrentText, "ENDBRACKETS", "]]")
 
    return CurrentText
end
 
return p