Content deleted Content added
No edit summary |
No edit summary |
||
(29 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 34 ⟶ 47:
func = function(codepoint, abbr)
return '&#x'.. string.format("%04X", (codepoint - 0xE0000)) .. ';'
end
},
Line 83 ⟶ 71:
-- Sundry small functions
-------------------------
local function expandTemplate(template, argslist)
return frame:expandTemplate{
Line 106 ⟶ 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 = mUnicode.lookup_control(codepoint.int)
if category ~= "unassigned" then
Line 135 ⟶ 118:
end
---------------------
-- A single unicode cell within the table
---------------------
local function getCellAbbr(codepoint, category, args)
local function getHardcodedNumberedAbbr(codepoint)
for key, value in pairs(hardcodedNumberedAbbrSets) do
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
--override
if (args['abbr_sub'] and args['abbr_sub'][codepoint.int]) then
return args['abbr_sub'][codepoint.int]
end
--exception listed at top
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
local function aliasesStr(codepoint)
local aliasStr = ""
Line 167 ⟶ 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 176 ⟶ 201:
end
local function abbrCell(abbr)
cell:addClass("abbr-
cell:tag("div"):addClass("abbr-box"):wikitext(abbr)
end
-- main func begins
local category = getCategory(codepoint)
cell:addClass(category)
local abbr = getCellAbbr(codepoint, category, args)
if category == "reserved" or category == "noncharacter" then
emptyCell(category)
elseif abbr then
abbrCell(abbr)
else
local unicodeChar = '&#x'.. codepoint.hex .. ';'
unicodeChar = linkChar(unicodeChar, codepoint, args) or unicodeChar
cell:addClass("modified")
end
if args['wrapper'] then
Line 210 ⟶ 226:
elseif args['font'] then
cell:css("font-family", "'" .. args['font'] .. "'")
--unicodeChar = tostring(
-- mw.html.create("div")
-- :css("font-family", "'" .. args['font'] .. "'")
-- :wikitext(unicodeChar)
--)
end
cell:wikitext(unicodeChar)
end
local name = mUnicode.lookup_name(codepoint.int)
name = string.match(name, "<([a-z]+)-%w+>") or name
cell:attr("title",
Line 245 ⟶ 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(
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 332 ⟶ 357:
end
end
-- look up block by na,e
if args['blockname'] then
local range = mUnicode.get_block_info(args['blockname'])
Line 342 ⟶ 369:
args
)
-- block given as start and end of range
elseif args['rangestart'] and args['rangeend'] then
return createTable(
|