require "sanitize" module AozoraSsml class Builder def html2ssml(html) doc = ::AozoraSsml::Document.parse(html.encode("utf-8")) ssml_body = create_body_ssml(doc) create_ssml(doc, ssml_body) end def create_body_ssml(doc) Sanitize. fragment(doc.main_text, elements: %w(br ruby rb rp rt div h1 h2 h3 h4 h5)). gsub(%r(), ''). gsub(%r(<(?:h\d|div)[^>]*>), '

'). gsub(%r(), '

'). gsub(%r([^<]+), '') end def create_ssml(doc, ssml_body) <<-XML

#{doc.title}

#{doc.author}

#{ssml_body}
XML end end end