Class: Cocina::Models::Mapping::EscapeHtml

Inherits:
Object
  • Object
show all
Defined in:
lib/cocina/models/mapping/escape_html.rb

Overview

Escaps HTML entities as CDATA for MODS since HTML is not permitted in MODS

Class Method Summary collapse

Class Method Details

.with_cdata(data, builder) ⇒ Object

Parameters:

  • data (String)
  • (Nokogiri::XML::Builder)


10
11
12
13
14
15
16
17
18
19
# File 'lib/cocina/models/mapping/escape_html.rb', line 10

def self.with_cdata(data, builder)
  tokens = data.split(%r{(</?(?:i|cite)>)})
  tokens.map do |token|
    if /\A<.+>\z/.match? token
      builder.cdata(token)
    else
      builder.text(token)
    end
  end
end