Модул:User:Erutuon/08
Документацију овог модула можете да направите на страници Модул:User:Erutuon/08/док
local export = {}
local function process_rows(text)
local i, j, row, row_end, match
local row_number = 1
local rows = {}
while true do
i, j, row = text:find("\n|%-[^\n]*\n+(.-)\n+|%-", row_end)
if not i then
mw.log("no row match")
break
end
row_end = j - 4 -- Move index behind the initial "\n|-"
row_number = row_number + 1
local row_table = {}
rows[row_number] = row_table
row_table[1] = row
if row_number > 5 then break end -- for now
local cell
local cell_number = 1 -- first index in row table is the whole row
j = nil
while true do
i, j, match = row:find("|( .-)|", j)
if i then
cell = match
else
break
end
local repetitions = 0
while match:find("[[", 1, true) do -- If link found, then go to end of link and look for pipe again.
mw.log("link was found")
repetitions = repetitions + 1
if repetitions > 5 then
break
end
i, j, match = row:find("([^|]*)|", j)
if i then
cell = cell .. match
mw.log(cell)
else
error("No end of template " .. cell .. " found.")
end
end
if cell then
cell_number = cell_number + 1
row_table[cell_number] = cell
end
end
end
mw.logObject(rows)
end
function export.process(frame)
local text = frame.args[1] or frame:getParent().args[1]
if mw.title.getCurrentTitle().nsText == "User" then
process_rows(text)
end
--[=[
local getByCanonicalName = require("Module:languages").getByCanonicalName
local langs = {}
local i = 0
for lang in text:gmatch("\n!\s*%[%[([^%]]+)%]%]") do
if not lang:find("IPA") then
i = i + 1
langs[i] = getByCanonicalName(lang) or error("The language name " .. lang .. " is not recognized.")
end
end
--]=]
local background_color = "#E6E6E6"
return (text
:gsub("(| +)-", "%1 " .. ' style="background: ' .. background_color .. ';" | —')
:gsub("(<big>)([^<]+)(</big>)", '%1<span class="IPA">%2</span>%3')
:gsub(
"(%[%[([^%]]+)%]%])",
function(link, link_text)
if link_text:find("'''") and not link_text:find("|") then
return "[[" .. link_text:gsub("'''", "") .. "|" .. link_text .. "]]"
else
return link
end
end))
end
return export