This script produces a comma separated list of special key symbols in Unicode for WP-Table Reloaded.
#!/usr/bin/env ruby | |
# coding: utf-8 | |
# Raw data : http://unicode.org/Public/UNIDATA/UnicodeData.txt | |
# Format : http://www.ksu.ru/eng/departments/ktk/test/perl/lib/unicode/UCDFF301.html | |
require 'csv' | |
require 'htmlentities' | |
options = { | |
:col_sep => ';', | |
:headers => headers = [ | |
'Code value', | |
'Character name', | |
'General Category', | |
'Canonical Combining Classes', | |
'Bidirectional Category', | |
'Character Decomposition Mapping', | |
'Decimal digit value', | |
'Digit value', | |
'Numeric value', | |
'Mirrored', | |
'Unicode 1.0 Name', | |
'10646 comment field', | |
'Uppercase Mapping', | |
'Lowercase Mapping', | |
'Titlecase Mapping' | |
] | |
} | |
key_symbols = ['238B','21E5','21E4','21EA','21E7','2303','2325','F8FF','2318','2423','23CE','21A9','232B','2326','20DD','21F1','2196','21B8','21F2','2198','21DE','21DF','2191','21E1','2193','21E3','2190','21E0','2192','21E2','2327','21ED','2324','23CF','233D'] | |
coder = HTMLEntities.new | |
table = [] | |
CSV.open('./UnicodeData.txt', 'r', options).each do |row| | |
next unless key_symbols.include? row['Code value'] | |
d = row['Code value'].to_i(16) | |
table << [ c = d.chr('UTF-8'), | |
sprintf("U+%02X", d), | |
coder.encode(coder.encode(c, :basic, :decimal), :named), | |
coder.encode(row['Character name'].capitalize, :named), | |
key_symbols.index(row['Code value']) ] | |
end | |
puts "Character,Hex,HTML Entity,Name" | |
table.sort_by {|row| row[row.length-1]}.each do |row| | |
row.delete_at row.length-1 | |
puts row.to_csv | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment