Formats the lists of Mandarin words at Appendix:HSK list of Mandarin words/Elementary Mandarin and Appendix:HSK list of Mandarin words/Intermediate Mandarin.
local u = require("Module:string/char")
local export = {}
local function cmn_link(word, script)
return '<span class="' .. script .. '" lang="cmn">[[' .. word
.. '#Chinese|' .. word .. ']]</span>'
end
local function cmn_tr(word)
return '<span lang="cmn-Latn" class="tr-Latn tr">' .. word .. '</span>'
end
local open_paren = '<span class="mention-gloss-paren annotation-paren">(</span>'
local close_paren = '<span class="mention-gloss-paren annotation-paren">)</span>'
function export.link(frame)
local text = frame.args or frame:getParent().args
-- Matches Latin and doesn't match Han characters; that's all that's needed.
local Latin = ""
local zh_link = require "Module:zh/link".link
text = text:gsub(
'%f%* *(+)',
function (line)
local items = mw.text.split(line, "%s*,%s*")
-- Allow multiple pinyin to be input, separated by commas.
-- Assume that if an item is pinyin, everything after it is pinyin,
-- and that if there is a fourth item, it's pinyin.
if items then
items = table.concat(items, ", ", 3)
items = nil
elseif items and mw.ustring.find(items, Latin) then
items = table.concat(items, ", ", 2)
items = nil
end
if items then
line = zh_link(nil, nil, items)
else
mw.log(line)
return ""
end
return "* " .. line
end)
return text
end
return export