Module:Unicode chart
Appearance
![]() | This module is rated as pre-alpha. It is unfinished, and may or may not be in active development. It should not be used from article namespace pages. Modules remain pre-alpha until the original editor (or someone who takes one over if it is abandoned for some time) is satisfied with the basic structure. |
![]() | This module uses TemplateStyles: |
Implements {{unicode chart}}
-- This module constructs Unicode tables.
local p = {}
local getArgs = require('Module:Arguments').getArgs
function p._main(args)
local cellpadding = tonumber(args.cellpadding) or 5
local header0 = '{| border="1" cellspacing="0" cellpadding="' .. cellpadding
local titlesize = args.titlesize or "large"
local header1 = '" class="wikitable nounderlines Unicode" style="border-collapse:collapse;background:#FFFFFF;font-size:' .. titlesize
local rowbackground = args.rowbackground or "#F8F8F8"
local header2 = ';text-align:center"\n| colspan="17" style="background:' .. rowbackground
local header3 = ';font-size:small" |'
local name = args.name
if type(name) ~= "string" then
error("name must be a string", 1)
end
local headtext
if args.headtext then
headtext = args.headtext
else
if type(args.link) == "string" then
local titleObject = mw.title.new(args.link)
headtext = "'''[[" .. args.link .. "|" .. args.name .. "]]'''"
else
headtext = args.name
end
end
local noterefs = args.noterefs or ""
local header4 = '<br />[https://www.unicode.org/charts/PDF/U'
-- start must be a number or a decimal string
if not (type(args.start) == "number" or type(args.start) == "string") then
error("start is not a string or a number")
end
local start = tonumber(args.start)
local header5 = '.pdf Official Unicode Consortium chart] (PDF)\n|- style="background:'
local header6 = ';font-size:small"\n| style="width:'
local firstColumnWidth = args.first_column_width or "45pt"
local header7 = '" '
local columnWidth = args.column_width or "20pt"
-- do not hardcode the hexadecimal part: generate it here
local hexchars = "0123456789ABCDEF"
local header8 = ''
for i = 1, 16 do
local c = string.sub(hexchars, i, i)
header8 = header8 .. ' || style="width:' .. columnWidth .. ';" | ' .. c
end
-- Finally, create the header.
local header =
header0 .. header1 .. header2 .. header3
.. name .. noterefs .. header4 .. string.format("%04X", start)
.. header5 .. rowbackground .. header6 .. firstColumnWidth
.. header7 .. header8
-- Use the positional arguments as the names of the characters.
local argnum = 1
local current = start
local body = ''
while args[argnum] ~= nil do
local row = '|-\n| style="background:' .. rowbackground .. ';font-size:small" | '
row = row .. string.format('U+%04Xx\n', current / 16)
local nxt = current + 16
while current < nxt do
local prefix = ""
local suffix = ""
local ch = mw.ustring.char(border)
if args[argnum] == "border" then
argnum = argnum + 1
prefix = '<span style="display: inline-block; border: 1px dashed' .. (args.borderColor or "black") .. '>'
suffix = '</span>'
end
if args.show_codepoint == false or args.show_codepoint == "false" then
row = row .. mw.ustring.format('| title="%s" | %s&#x%04X;%s\n', args[argnum], prefix, current, suffix)
else
row = row .. mw.ustring.format('| title="U+%04X: %s" | %s&#x%04X;%s\n', current, args[argnum], prefix, current, suffix)
end
current = current + 1
argnum = argnum + 1
end
body = body .. row
end
-- Make the final return string.
local footer
= '|-\n| colspan="17" style="background:' .. rowbackground
.. ";font-size:small\" | '''Notes'''"
.. notes .. "\n|}"
return header .. body .. footer
end
function p.main(frame)
return p._main(getArgs(frame))
end
return p