summaryrefslogtreecommitdiff
path: root/script/unicodify.rb
blob: aac8cbdb7cb1d211e6234fac2850a2e5a6bae84f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
# unicodify.rb
# Charlotte Koch <charlotte@magentastripe.com>
#
# This file is part of Willora.
#
# This script translates HTML entities on the standard input to numerical
# Unicode codepoints on the standard output. This script uses a whole bunch
# of memory in order to keep it fast.
#

require 'json'

entities = JSON.load(File.read("./private/entities.min.json"))

out = $stdin.read

entities.each do |entity, value|
  result = value["codepoints"].map { |n| sprintf('&#%d;', n) }.join("")
  out.gsub!(entity, result)
end

$stdout.write(out)