#!/usr/pkg/bin/ruby34
# -*- coding: utf-8 -*-

require 'rexml/document'
require 'kramdown-rfc/rexml-formatters-conservative'
require 'kramdown-rfc/svg-id-cleanup'

def svg_clean_ids(s)
  d = REXML::Document.new(s)
  d.context[:attribute_quote] = :quote  # Set double-quote as the attribute value delimiter

  svg_id_cleanup(d)

  tr = REXML::Formatters::Conservative.new
  o = ''
  tr.write(d, o)
  o
rescue => detail
  warn "*** Can't clean SVG: #{detail}"
  d.to_s
end

puts svg_clean_ids(ARGF.read)
