name Convert entities <> for HTML output uuid 5AF8503F-DC1B-416C-9475-AF3DB77D4E48 input selection output replaceSelectedText command #!/usr/bin/env ruby $KCODE = 'U' $char_to_entity = { } File.open("#{ENV['TM_BUNDLE_SUPPORT']}/entities.txt").read.scan(/^(\d+)\t(.+)$/) do |key, value| $char_to_entity[[key.to_i].pack('U')] = value end def encode (text) text.gsub(/[<>&]/) do |ch| ent = $char_to_entity[ch] ent ? "&#{ent};" : sprintf("&#x%02X;", ch.unpack("U")[0]) end end print encode(STDIN.read) fallbackInput document keyEquivalent @& scope text.html