local p =
local Array = require 'Module:Array'
local function pattern_escape(str) return (str:gsub('%p', '%%%1'))end
function p.make_script_name_to_code(page_name) local property_value_aliases = assert(assert(mw.title.new(page_name)):getContent)
local script_aliases = property_value_aliases:match(pattern_escape '# Script (sc)' .. '%s+(.-)%s+' .. pattern_escape '# Script_Extensions (scx)')
local script_name_to_code = for code, name in script_aliases:gmatch 'sc%s+;%s+(%a+)%s+;%s+([%a_]+)' do script_name_to_code[name] = code end return script_name_to_codeend
function p.make_script_data(scripts_txt, property_value_aliases_txt) local script_data = assert(assert(mw.title.new(scripts_txt)):getContent) local script_name_to_code = p.make_script_name_to_code(property_value_aliases_txt) setmetatable(script_name_to_code,) local script_ranges = Array local prev_codepoint, prev_script_name, prev_script_range for codepoint1, codepoint2, script_name in script_data:gmatch '%f[^\n%z](%x+)%.?%.?(%x*)%s+;%s*([%w_]+)' do codepoint1, codepoint2 = tonumber(codepoint1, 16), tonumber(codepoint2, 16) local script_range if prev_script_range and script_name
1 then prev_script_range[2] = codepoint2 or codepoint1 else script_range = script_ranges:insert(script_range) end prev_codepoint, prev_script_name, prev_script_range = codepoint2 or codepoint1, script_name, script_range or prev_script_range end local singles = local i = 1 while script_ranges[i] do local low, high, script_code = unpack(script_ranges[i]) if low
function p.highlight(lua_code) return mw.getCurrentFrame:extensionTagend
function p.main(frame) local dir = 'User:Erutuon/Unicode' local scripts_txt = dir .. '/Scripts.txt' local property_value_aliases_txt = dir ..'/PropertyValueAliases.txt' return p.highlight(p.make_script_data(scripts_txt, property_value_aliases_txt))end
return p