Module:Unicode chart/sandbox: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
 
(44 intermediate revisions by the same user not shown)
Line 26:
flag = false
}
}
 
local hardcodedNumberedAbbrSets = {
-- Block: Variation Selectors
{first = 0xFE00, last = 0xFE0F, str = "VS<br>", startNum = 1},
-- Block: Variation Selectors Supplement
{first = 0xE0100, last = 0xE01EF, str = "VS<br>", startNum = 17},
-- Block: Sutton SignWriting
-- SIGNWRITING FILL MODIFIER-2 -> SW F#
{first = 0x1DA9B, last = 0x1DA9F, str = 'SW<br>F', startNum = 2},
-- Block: Sutton SignWriting
-- SIGNWRITING ROTATION MODIFIER-2 -> SW R#
{first = 0x1DAA1, last = 0x1DAAF, str = 'SW<br>R', startNum = 2},
}
 
Line 36 ⟶ 49:
end
},
-- Unicode block: Variation Selectors Supplement
-- adding line breaks
{first = 0xE0100, last = 0xE01EF,
func = function(codepoint, abbr)
return abbr:gsub("VS", "VS<br>")
end
}
}
 
Line 74 ⟶ 80:
local function fromHex(hexStr)
return tonumber(hexStr, 16)
end
 
local function splitColonList(strList)
local tab = {}
local segments = mw.text.split(strList, '[;\n\t]')
for _,v in pairs(segments) do
local tmp = mw.text.split(v, ':')
if tmp[1] and tmp[2] then
tab[fromHex(tmp[1])] = mw.text.trim(tmp[2])
end
end
return tab
end
 
local function getCategory(codepoint)
-- local category = mCategory.long_names[
-- mUnicode.lookup_category(codepoint.int)
-- ]
local category = mUnicode.lookup_control(codepoint.int)
if category ~= "unassigned" then
Line 103 ⟶ 118:
end
 
---------------------
local function lastAbbr(codepoint)
-- A single unicode cell within the table
local tbl = getAliasValues(codepoint.int, "abbreviation")
---------------------
local alias = tbl[#tbl] or nil -- last one
local function getCellAbbr(codepoint, category, args)
for key, value in pairs(specialFormatSets) do
local function getHardcodedNumberedAbbr(codepoint)
if codepoint.int >= value.first
for key, value in pairs(hardcodedNumberedAbbrSets) do
and codepoint.int <= value.last then
returnif value.func(codepoint.int, alias)>= value.first
and codepoint.int <= value.last then
return value.str .. (codepoint.int - value.first + value.startNum)
end
end
return nil
end
--for key, value in pairs(specialFormatSets) do
-- if codepoint.int >= value.first
-- and codepoint.int <= value.last then
-- return value.func(codepoint.int, alias)
-- end
--end
local function getAliasAbbr(codepoint)
local tbl = getAliasValues(codepoint.int, "abbreviation")
return tbl[1] or nil
end
local function abbrFromString(codepoint, args)
local abbr = ""
local name = mUnicode.lookup_name(codepoint.int)
local words = mw.text.split(name, ' ')
for _,w in pairs(words) do
abbr = abbr .. string.sub(w, 1, 1)
end
return abbr
end
return alias
end
 
--override
local function abbrFromString(str)
if (args['abbr_sub'] and args['abbr_sub'][codepoint.int]) then
local words = mw.text.split(str, ' ')
return args['abbr_sub'][codepoint.int]
local abbr = ""
for _,w in pairs(words) do
abbr = abbr .. string.sub(w, 1, 1)
end
--exception listed at top
return abbr
local abbr1 = getHardcodedNumberedAbbr(codepoint)
if abbr1 then return abbr1 end
--abbr on list
local abbr2 = getAliasAbbr(codepoint)
if abbr2 then return abbr2 end
--make own abbr
if category == "control" or category == "format" then
return '<span class="red">' .. abbrFromString(codepoint) .. '</span>'
end
return false
end
 
---------------------
-- A single unicode cell within the table
---------------------
local function aliasesStr(codepoint)
local aliasStr = ""
Line 135 ⟶ 179:
end
return aliasStr
end
 
local function linkChar(unicodeChar, codepoint, args)
if (args['link_sub'] and args['link_sub'][codepoint.int]) then
return '[[' .. args['link_sub'][codepoint.int]
.. '|' .. unicodeChar .. ']]'
elseif args['link'] == "wiki" then
local redir = mRedirect.luaMain(unicodeChar, false)
-- '[[' .. redir .. '|' .. unicodeChar .. ']]'
return expandTemplate('Link if exists', {unicodeChar})
elseif args['link'] == "wikt" then
return '[[wikt:' .. unicodeChar .. '|' .. unicodeChar .. ']]'
end
end
 
Line 144 ⟶ 201:
end
local function abbrCell(abbr)
cell:addClass("abbr-boxcell")
cell:tag("div"):addClass("abbr-box"):wikitext(abbr)
end
-- main func begins
local name = mUnicode.lookup_name(codepoint.int)
local abbr = lastAbbr(codepoint)
local category = getCategory(codepoint)
cell:addClass(category)
local abbr = getCellAbbr(codepoint, category, args)
if category == "reserved" or category == "noncharacter" then
or category == "noncharacter" then
emptyCell(category)
elseif (args['abbr_sub'] and args['abbr_sub'][codepoint.int]) then
abbrCell(args['abbr_sub'][codepoint.int])
elseif abbr then
abbrCell(abbr)
elseif category == "control"
or category == "format"
or category == "space-separator" then
cell:addClass("red")
abbrCell(abbrFromString(name))
else
local unicodeChar = '&#x'.. codepoint.hex .. ';'
unicodeChar = linkChar(unicodeChar, codepoint, args) or unicodeChar
if args['link'] == "wiki" then
if args['suffix'] and args['suffix'][codepoint.int] then
local redir = mRedirect.luaMain(unicodeChar, false)
unicodeChar = '[[' .. redir .. '|' .. unicodeChar .. ']]'
.. '&#x' .. args['suffix'][codepoint.int] .. ';'
--unicodeChar = expandTemplate('Link if exists', {unicodeChar})
cell:addClass("modified")
elseif args['link'] == "wikt" then
unicodeChar = '[[wikt:' .. unicodeChar .. '|' .. unicodeChar .. ']]'
end
if args['wrapper'] then
unicodeChar = expandTemplate(args['wrapper'], {unicodeChar})
elseif args['font'] then
cell:css("font-family", "'" .. args['font'] .. "'")
--unicodeChar = tostring(
-- mw.html.create("div")
-- :css("font-family", "'" .. args['font'] .. "'")
-- :wikitext(unicodeChar)
--)
end
--else
cell:wikitext(unicodeChar)
--end
end
local name = mUnicode.lookup_name(codepoint.int)
name = string.match(name, "<([a-z]+)-%w+>") or name
cell:attr("title",
Line 210 ⟶ 263:
local row = body:tag("tr")
row:tag("th"):wikitext("U+".. rowHex .. "<i>x</i>")
:attr("rowspan", "2")
for colIndex=0, 15 do
local cell = row:tag("td")
--rowHex .. string.format("%X", colIndex)
createCell(cell,
newCodepoint(rowHexrowIndex*16 .. string.format("%X",+ colIndex)),
args
)
end
local subrow = body:tag("tr")
for colIndex=0, 15 do
subrow:tag("td"):addClass("codepoint")
:wikitext(string.format("%04X", rowIndex*16 + colIndex))
end
end
Line 242 ⟶ 302:
:addClass("footer")
:attr("colspan", "100%")
:wikitext("'''<b>Notes'''</b>")
local list = th:tag("ol")
list:tag("li"):wikitext(
Line 256 ⟶ 316:
list:tag("li"):wikitext(value.note)
end
end
--Manual note
if note then
list:tag("li"):wikitext(note)
end
end
Line 284 ⟶ 348:
-- Main
---------------------
 
local function splitColonList(strList)
local tab = {}
local str = ""
local abbs = mw.text.split(strList, '[;\n\t]')
for _,v in pairs(abbs) do
local tmp = mw.text.split(v, ':')
str = str .. '['
local tmp = mw.text.split(v, ':')
for _,v in pairs(tmp) do
if tmp[1] and tmp[2] then
tab[fromHex(tmp[1])] = mw.text.trim(tmp[2])
str = str .. '(' .. fromHex(tmp[1]) .. ':' .. tmp[2] .. ')'
end
end
str = str .. ']'
end
return tab
end
 
function p.main(frameArg)
frame = frameArg
local args = getArgs(frame)
 
for _, argName in ipairs({'abbr_sub', 'link_sub', 'suffix'}) do
if args['abbr_sub'] then
if args[argName] then
args['abbr_sub'] = splitColonList(args['abbr_sub'])
args[argName] = splitColonList(args[argName])
end
end
-- look up block by na,e
if args['blockname'] then
local range = mUnicode.get_block_info(args['blockname'])
Line 321 ⟶ 369:
args
)
-- block given as start and end of range
elseif args['rangestart'] and args['rangeend'] then
return createTable(