Module:Character info

local m_unicode = require('Module:Unicode data') local char_to_script = require('Module:scripts').charToScript

local export = {}

local dingbat_scripts = { ["Zsym"] = true; ["Zmth"] = true; ["Zyyy"] = true; }

local function page_exists(title) local ok, title_obj = pcall(mw.title.new, title) if ok and title_obj then local ok, exists = pcall(function return title_obj.exists end) return ok and exists else return false end end

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 = char_to_script(codepoint)

if dingbat_scripts[script_code] then return frame:expandTemplate { title = "editnotice-exotic symbols" } end

return "" end

local function get_codepoint(codepoint, param_name) if codepoint then codepoint = mw.text.trim(codepoint) 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 " .. param_name				.. " parameter") end end return codepoint end

function export._show(args, parent_title) local codepoint = args.codepoint or args[1] or ""; local image local title = mw.title.getCurrentTitle local to_boolean = require('Module:yesno') local namespace = mw.title.getCurrentTitle.nsText

if codepoint ~= "" then codepoint = get_codepoint(codepoint, "codepoint") else if title.fullText == parent_title then codepoint = 0xfffd elseif mw.ustring.len(title.fullText) == 1 then codepoint = mw.ustring.codepoint(title.fullText) else if title.nsText == "Template" then return "" end error("Page title is not a single Unicode character") end end

args.image = args.image and mw.text.trim(args.image) if args.image == "" then image = nil else image = args.image or m_unicode.lookup_image(codepoint) end

local table_markup = {} table.insert(table_markup,		'{| class="wikitable floatright" style="width:25em;"\n')

if image then if not image:match("\127") then -- ')				:format(table.concat(rows, ""))

end

return ""

end

local function present_codepoint(codepoint, np, script, combining, name, printable, title) local display local link_target if combining then combining = to_boolean(combining) else combining = m_unicode.is_combining(codepoint) end if printable then printable = to_boolean(printable) else printable = m_unicode.is_printable(codepoint) end local char = mw.ustring.char(codepoint) if title == "self" or page_exists(char) then link_target = char elseif title ~= "" then link_target = m_unicode.get_entry_title(codepoint) end

if printable then display = (' %s&#x%04X; '):format(				script or char_to_script(codepoint),				combining and "◌" or "", codepoint			) end local arrow_and_maybe_char if np then arrow_and_maybe_char = (display or "") .. ' →'		else arrow_and_maybe_char = '← ' .. (display or "") end local text = (' %s [U+%04X] ') :format(mw.text.encode(name or m_unicode.lookup_name(codepoint)),				arrow_and_maybe_char, codepoint) if link_target then return ( .. text .. ) else return text end end

local function get_next(codepoint, step) -- Skip past noncharacters and reserved characters (Cn), private-use -- characters (Co), surrogates (Cs), and control characters (Cc), all -- of which have a label beginning in "<" rather than a proper name. if step < 0 and 0 ' )

table.insert(table_markup,		middle_part	)

local previous_unassigned_first = previous_codepoint + 1 local previous_unassigned_last = codepoint - 1 local next_unassigned_first = codepoint + 1 local next_unassigned_last = next_codepoint - 1

local left_unassigned_text local right_unassigned_text

if previous_codepoint == 0 then previous_unassigned_first = 0 end

if previous_unassigned_first <= previous_unassigned_last or next_unassigned_first <= next_unassigned_last then if previous_unassigned_first < previous_unassigned_last then left_unassigned_text = ('[unassigned: U+%.4X–U+%.4X]'):format(previous_unassigned_first, previous_unassigned_last) elseif previous_unassigned_first == previous_unassigned_last then left_unassigned_text = ('[unassigned: U+%.4X]'):format(previous_unassigned_first) end

if next_unassigned_first < next_unassigned_last then right_unassigned_text = ('[unassigned: U+%.4X–U+%.4X]'):format(next_unassigned_first, next_unassigned_last) elseif next_unassigned_first == next_unassigned_last then right_unassigned_text = ('[unassigned: U+%.4X]'):format(next_unassigned_first) end end local unassignedsRow = mw.html.create('table'):css('width', '100%'):css('font-size', '80%'):css('white-space', 'nowrap') :tag('tr') :tag('td'):css('width', '50%'):css('text-align', 'left'):wikitext(left_unassigned_text or ''):done :tag('td'):css('width', '50%'):css('text-align', 'right'):wikitext(right_unassigned_text or ''):done :allDone table.insert(table_markup, tostring(unassignedsRow) ..'\n') local previous_codepoint_text = "" local next_codepoint_text = ('%s\n') :format(present_codepoint(next_codepoint, true, args.next_codepoint_sc, args.next_codepoint_combining, args.next_codepoint_name, args.next_codepoint_printable, args.next_codepoint_title))

if previous_codepoint > 0 then previous_codepoint_text = ('%s\n') :format(present_codepoint(previous_codepoint, false, args.previous_codepoint_sc, args.previous_codepoint_combining, args.previous_codepoint_name, args.previous_codepoint_printable, args.previous_codepoint_title)) end

--Here we're assuming that "Block name (Unicode block)" exists as either the name of the article or a redirect. --It would be nicer if we could check if the page title "Block name (Unicode block)" actually exists and pipe the link if it does and otherwise just link %s. --It would seem the page_exists function should work for this, but AJ is too stupid to get that to work. local block_name_text = ('%s') --on wiktionary this is ('%s'). :format(block_name, block_name) if namespace == "" then block_name_text = block_name_text .. ('\n') :format(block_name, codepoint) else block_name_text = block_name_text .. '\n' end local lastRow = mw.html.create('table'):css('width', '100%'):css('text-align', 'center') :tag('tr') :tag('td'):css('width', '20%'):wikitext(previous_codepoint_text):done --:tag('td'):css('width', '15%') --	:tag('span'):wikitext(left_unassigned_text and "..." or ""):attr('title', left_unassigned_text or ""):done:done :tag('td'):css('width', '60%'):css('font-size', '110%'):css('font-weight', 'bold'):wikitext(block_name_text) --:tag('td'):css('width', '15%') --	:tag('span'):wikitext(right_unassigned_text and "..." or ""):attr('title', right_unassigned_text or ""):done:done :tag('td'):css('width', '20%'):wikitext(next_codepoint_text):done :allDone table.insert(table_markup, tostring(lastRow) ..'\n')

table.insert(table_markup, '|}')

if cat_name and namespace == "" then table.insert(table_markup, "") end table.insert(table_markup, require("Module:TemplateStyles")("User:Alexis Reggae/Character info template/styles.css"))

return table.concat(table_markup) end

function export.show(frame) local parent_frame = frame:getParent return export._show(parent_frame.args, parent_frame:getTitle) end

return export