Module:add etymology: Difference between revisions

ਕੋਈ ਸੋਧ ਸਾਰ ਨਹੀਂ
No edit summary
No edit summary
Line 12: Line 12:
local content = current:getContent()
local content = current:getContent()
content = assert(mw.ustring.match(content, "(==%s*" .. language.name .. "%s*==.+)\n==[^=]+==\n") or mw.ustring.match(content, "==%s*" .. language.name .. "%s*==.+"), "No " .. language.name .. " section found in:\n" .. content)
content = assert(mw.ustring.match(content, "(==%s*" .. language.name .. "%s*==.+)%s==[^=]+==%s") or mw.ustring.match(content, "==%s*" .. language.name .. "%s*==.+"), "No " .. language.name .. " section found in:\n" .. content)


local etymology_i = 1
local etymology_i = 1
Line 38: Line 38:
-- reformats single-etymology pages
-- reformats single-etymology pages
local regex_pronunciation = "(===%s*Pronunciation%s*===.+)\n===[^=]+===\n"
local regex_pronunciation = "(===%s*Pronunciation%s*===.+)%s===[^=]+===%s"
local regex_etymology = "(===%s*{{Etymology%|" .. language.code .. "}}%s*===.+)\n===[^=]+===\n"
local regex_etymology = "(===%s*{{Etymology%|" .. language.code .. "}}%s*===.+)%s===[^=]+===%s"
local section, index = {}, {}
local section, index = {}, {}
index.h1, index.h2, section.heading = mw.ustring.find(content, "(==%s*" .. language.name .. "%s*==\n)")
index.h1, index.h2, section.heading = mw.ustring.find(content, "(==%s*" .. language.name .. "%s*==%s)")
index.pron1, index.pron2, section.pronunciation = mw.ustring.find(content, regex_pronunciation)
index.pron1, index.pron2, section.pronunciation = mw.ustring.find(content, regex_pronunciation)
index.e1, index.e2, section.etymology = mw.ustring.find(content, regex_etymology)
index.e1, index.e2, section.etymology = mw.ustring.find(content, regex_etymology)
local check_init = 1
local check_init = 1
while mw.ustring.find(content, "===[^=]+===%s.+", check_init) do
while mw.ustring.find(content, "===[^=]+===.+", check_init) do
local match_start, _, section_check = mw.ustring.find(content, "(===[^=]+===\n.+)", check_init)
local match_start, _, section_check = mw.ustring.find(content, "(===[^=]+===.+)", check_init)
if mw.ustring.find(frame:preprocess(section_check), "^===[^=]+===%s+<strong class=\"headword\"") then
if mw.ustring.find(frame:preprocess(section_check), "^===[^=]+===%s+<strong class=\"headword\"") then
index.m1 = mw.ustring.find(content, section_check, check_init, true)
index.m1 = mw.ustring.find(content, section_check, check_init, true)
Line 54: Line 54:
break
break
else
else
check_init = match_start + 2
check_init = match_start + 1
end
end
end
end
Line 88: Line 88:
section.main = mw.ustring.gsub(section.main, "===", "====")
section.main = mw.ustring.gsub(section.main, "===", "====")
return section.heading .. (section.pronunciation or "") .. section.etymology .. (section.pre or "") .. section.main .. "\n\n=== {{Etymology|" .. language.code .. "|2}} ==="
return section.heading .. ("\n" .. (section.pronunciation or "")) .. "\n" .. section.etymology .. (section.pre or "") .. section.main .. "\n=== {{Etymology|" .. language.code .. "|2}} ==="


end
end