Module:Sandbox/Erutuon/charinsert names: Difference between revisions

Content deleted Content added
No edit summary
Hope you don't mind me editing your userspace, but Module:Table has been merged
 
(5 intermediate revisions by one other user not shown)
Line 4:
local codepoint_set = {}
for codepoint in mw.ustring.gcodepoint(str) do
if codepoint_set[codepoint] > 0x7F= thentrue
codepoint_set[codepoint] = true
end
end
return require "Module:tableTableTools".keysToList(codepoint_set)
end
 
function p.print_namesJSON_character_names(str)
local codepoint_list = get_all_codepoints(str)
Line 20 ⟶ 18:
for i, codepoint in ipairs(codepoint_list) do
local key_and_value = '"' .. codepoint .. '":"' .. Unicode.lookup_name(codepoint) .. '"'
iflocal lenadded_len += #key_and_value >+ 1 -- 80for thencomma
if len + added_len > 79 then
key_and_value = '\n' .. key_and_value
len = #key_and_value0
else
len = len + #key_and_value
end
len = len + #key_and_valueadded_len
table.insert(JSON, key_and_value)
Line 31 ⟶ 30:
return "{" .. table.concat(JSON, ",") .. "}"
end
 
-- copied from [[wikt:Module:debug]]
function p.highlight(content, options)
if type(content) == "table" then
options = content
options = {
lang = options.lang or "lua",
inline = options.inline and true
}
return function(content)
return mw.getCurrentFrame():extensionTag{
name = "syntaxhighlight",
content = content,
args = options
}
end
else
return mw.getCurrentFrame():extensionTag{
name = "syntaxhighlight",
content = content,
args = {
lang = options and options.lang or "lua",
inline = options and options.inline and true or nil
}
}
end
end
 
-- Usage:
-- {{#invoke:Sandbox/Erutuon/charinsert_names|highlighted_character_names|abc}}
-- ↓
-- {"97":"LATIN SMALL LETTER A","98":"LATIN SMALL LETTER B",
-- "99":"LATIN SMALL LETTER C"}
function p.highlighted_character_names(frame)
local chars = frame.args[1]
if not chars or chars == "" then
error("Supply characters in parameter 1")
end
return p.highlight(p.JSON_character_names(chars))
end
 
Line 39 ⟶ 78:
if not charinsert then return "Could not find charinsert" end
return p.print_nameshighlight(p.JSON_character_names(charinsert))
end