{{#invoke:User:Suzukaze-c/zh-extract|extract_roman|度}}
{{#invoke:User:Suzukaze-c/zh-extract|extract_roman|度|yes}}
{{#invoke:User:Suzukaze-c/zh-extract|extract_roman|蘋|yes}}
local export = {}
local replace = mw.ustring.gsub
local match = mw.ustring.match
local itermatch = mw.ustring.gmatch
local split = mw.text.split
-- idea: +simplified? since we're pulling stuff from the page anyway
local default_set_separator = '//'
function export.extract_roman(word, combine, set_separator)
local plaintext = false
if type(word) == 'table' then
plaintext = true
word, combine, set_separator = word.args, word.args, word.args
end
mw.log('PROCESSING: ]')
local content = mw.title.new(word):getContent() or error('the ] entry does not exist!?')
local each = {}
local roman_final = {}
content = replace(content, "{{zh%-pron", "ⓐⓐⓐⓐⓐ")
content = replace(content, "(|cat=*)\n?}}\n", "%1ⓩⓩⓩⓩⓩ") -- making assumptions about formatting
if match(content, "ⓐ") and not match(content, "ⓩ") then
error("please add the cat param to zh-pron at ]")
end
-- Convert each {{zh-pron}} instance to a table subsumed in $each
local box_i = 1
for innards in itermatch(content, "ⓐⓐⓐⓐⓐ(+)ⓩⓩⓩⓩⓩ") do
each = {}
innards = split(innards, "\n|")
table.remove(innards, 1)
for i, item in ipairs(innards) do
local param, value = match(item, "^(+)=(.*)$")
each = value
end
box_i = box_i + 1
end
-- If told to combine tables, then combine each $each sub-table into a mega-table,
-- otherwise return the data of the first {{zh-pron}} instance
if combine then
-- make $roman_final a table containing every possible $value
for i, etable in ipairs(each) do
for param, value in pairs(etable) do
if not roman_final then roman_final = {} end
if value ~= '' then table.insert(roman_final, value) end
end
end
-- flatten $roman_final into text
for param, value in pairs(roman_final) do
roman_final = table.concat(roman_final, (set_separator or default_set_separator))
end
else
roman_final = each
end
if plaintext then
return require('module:debug').dump(roman_final)
else
return roman_final
end
end
return export