--[=[
Module for implementing miscellaneous definition-line templates. Currently supports
only &lit.
Author: Benwing2
]=]--
local export = {}
local m_links = require("Module:links")
-- Uppercase first letter.
local function ucfirst(text)
return mw.ustring.upper(mw.ustring.sub(text, 1, 1)) .. mw.ustring.sub(text, 2)
end
local function is_valid_page_name(pagename)
return not not mw.title.new(pagename)
end
-- Implementation of {{&lit}}
function export.and_lit(terms, qualifier, dot, nodot)
local output = {}
table.insert(output, '<span class="use-with-mention">')
if qualifier then
table.insert(output, ucfirst(qualifier) .. "")
else
table.insert(output, "")
end
table.insert(output, "仅按字面意思,并无比喻或俗语义")
if #terms > 0 then
table.insert(output, ";")
if terms[1].term == "-" or not is_valid_page_name(terms[1].term) then
table.insert(output, terms[1].term)
table.insert(output, "[[Category:&lit not valid pagename]]")
else
for i, term in ipairs(terms) do
if i == 1 then
table.insert(output, "参见")
else
table.insert(output, "、")
end
table.insert(output, m_links.full_link(term, nil, nil))
end
end
else
table.insert(output, "[[Category:&lit without 1]]")
end
if not nodot then
table.insert(output, dot or "。")
end
table.insert(output, "</span>")
return table.concat(output)
end
return export