وحدة:character info
المظهر
When updating, change class="wikitable floatright" to class="wikitable floatleft".
local m_unicode = require('Module:Unicode data')
local m_uni_aliases = mw.loadData('Module:Unicode data/aliases')
local m_scripts = require("Module:scripts/data")
local export = {}
local dingbat_scripts = {
["Zsym"] = true;
["Zmth"] = true;
["Zyyy"] = true;
}
function export.exotic_symbol_warning(frame)
local title = mw.title.getCurrentTitle()
if title.exists then
return ""
end
if mw.ustring.len(title.fullText) ~= 1 then
return ""
end
local codepoint = mw.ustring.codepoint(title.fullText)
local script_code = m_unicode.get_script(codepoint)
if dingbat_scripts[script_code] then
return frame:expandTemplate { title = "editnotice-exotic symbols" }
end
return ""
end
function export.show(frame)
local args = frame:getParent().args
local codepoint = args.codepoint
if codepoint then
codepoint = tonumber(codepoint) or mw.text.decode(codepoint)
if (type(codepoint) == "string") and (mw.ustring.len(codepoint) == 1) then
codepoint = mw.ustring.codepoint(codepoint)
elseif type(codepoint) ~= "number" then
error("Unrecognised string given for the codepoint parameter")
end
else
local title = mw.title.getCurrentTitle()
if title.fullText == frame:getParent():getTitle() then
codepoint = 0xfffd
elseif mw.ustring.len(title.fullText) == 1 then
codepoint = mw.ustring.codepoint(title.fullText)
else
error("Page title is not a single Unicode character")
end
end
local table_markup = {}
table.insert(table_markup,
'{| style="border:1px solid #aaa; border-spacing:5px; background-color:#f9f9f9; color:black; margin:0 0 0.5em 0.5em; padding:4px; float:left; clear:right; width:260px; text-align:left; font-size:90%; line-height:1.5em;"\n')
local image = args.image
if image then
if image:match("^%[?%[?File:") or image:match("^%[?%[?Image:") then
image = image:gsub("^%[%[", ""):gsub("^File:", ""):gsub("^Image:", ""):gsub("|.*", ""):gsub("]]", "")
end
image = "[[ملف:" .. image .. "|280x200px]]"
table.insert(table_markup,
('|-\n| colspan="2" style="text-align: center;" | %s<br/>%s\n'):format(
image, args.caption or ""
)
)
elseif args.caption then
table.insert(table_markup,
('|-\n| colspan="2" style="text-align: center;" | %s\n'):format(
args.caption
)
)
end
local script_code = args.sc or m_unicode.get_script(codepoint)
local script_data = m_scripts[script_code]
local script_name = script_data.canonicalName
local NAMESPACE = mw.title.getCurrentTitle().namespace
local cat_name
if not args.nocat and ((NAMESPACE == 0) or (NAMESPACE == 100)) then -- main and Appendix
if script_data.character_category ~= nil then
-- false means no category, overriding the default below
cat_name = script_data.character_category or nil
elseif script_name then
cat_name = script_name .. " خصائص الخطاطة"
end
end
table.insert(table_markup,
('|-\n! الخصائص\n| style="font-size: large;" | <bdi class="%s">&#%u;</bdi>\n'):format(
script_code, codepoint
)
)
table.insert(table_markup,
('|-\n! اسم اليونيكود\n| style="font-size: smaller;" | %s\n'):format(
mw.text.encode(m_unicode.lookup_name(codepoint))
)
)
local aliases = m_uni_aliases[codepoint]
if aliases then
local classif = {}
for i, alias in ipairs(aliases) do
if not classif[alias[1]] then
classif[alias[1]] = {}
end
table.insert(classif[alias[1]], mw.text.encode(alias[2]))
end
if classif.correction then
for i, name in ipairs(classif.correction) do
table.insert(table_markup,
('|-\n! Corrected name\n| style="font-size: smaller;" | %s\n'):format(
name
)
)
end
end
if classif.abbreviation then
table.insert(table_markup,
('|-\n! Abbreviation(s)\n| | %s\n'):format(
table.concat(classif.abbreviation, ", ")
)
)
end
if classif.alternate then
for i, name in ipairs(classif.alternate) do
table.insert(table_markup,
('|-\n! Alternative name\n| style="font-size: smaller;" | %s\n'):format(
name
)
)
end
end
end
table.insert(table_markup,
('|-\n! شفرة نقطة\n| [http://unicode.org/cldr/utility/character.jsp?a=%.4X U+%.4X]\n'):format(
codepoint, codepoint
)
)
local codepointstr = ('%.4X'):format(codepoint)
table.insert(table_markup,
'|-\n! [[w:قائمة XML و HTML خصائص مراجع تعريفها |عدد كائن]]\n| &#'.. tonumber(codepointstr, 16) .. ';\n'
)
local nfd = mw.ustring.toNFD(mw.ustring.char(codepoint))
if mw.ustring.len(nfd) ~= 1 then
local nfdcps = {}
for nfdcp in mw.ustring.gcodepoint(nfd) do
table.insert(nfdcps, ("U+%.4X"):format(nfdcp))
end
table.insert(table_markup,
('|-\n! Decomposed form\n| %s\n'):format(
table.concat(nfdcps, " ")
)
)
end
local block_name = mw.text.encode(m_unicode.lookup_block(codepoint))
table.insert(table_markup,
('|-\n! كتلة اليونكود\n| [[ملحق:يونيكود/%s|%s]]\n'):format(
block_name, block_name
)
)
if args.latex then
local latex, n = { '<code>' .. args.latex .. '</code>' }, 2
while args["latex" .. n] do
table.insert(latex, '<code>' .. args["latex" .. n] .. '</code>')
n = n + 1
end
table.insert(table_markup,
('|-\n! LaTeX input\n| %s\n'):format(
table.concat(latex, ", ")
)
)
end
local function present_codepoint(codepoint, np)
local display = ""
local link_target
if m_unicode.is_printable(codepoint) then
link_target = m_unicode.get_entry_title(codepoint)
if not mw.title.new(link_target).exists then
link_target = nil
end
display = ('<bdi style="font-size: large;" class="%s">&#%u;</bdi>'):format(
m_unicode.get_script(codepoint), codepoint
)
end
return (
(link_target and '[[%s|<span title="%s">' or '<!-- %s --><span title="%s">') ..
(np and '<small>[U+%04X]</small> %s <!-- U+%04X --> →'
or '← <!-- U+%04X --> %s <small>[U+%04X]</small>') ..
(link_target and '</span>]]' or '</span>')
):format(
link_target or "", mw.text.encode(m_unicode.lookup_name(codepoint)),
codepoint, display, codepoint
)
end
table.insert(table_markup, (
'|-\n| colspan="2" |\n' ..
'{| style="width: 100%%;"\n' ..
'|-\n' ..
'| style="text-align: left;" | %s\n' ..
'| style="text-align: right;" | %s\n' ..
'|}\n'):format(
present_codepoint(codepoint - 1, false),
present_codepoint(codepoint + 1, true)
)
)
table.insert(table_markup, '|}')
if cat_name then
table.insert(table_markup, "[[تصنيف:" .. cat_name .. "| " .. mw.ustring.char(codepoint) .. "]]")
end
return table.concat(table_markup)
end
return export