Sha256: 4d8343bd5d335b1178c932ca8abd8ccc0d73c356905af38b0de05bb973b02a21

Contents?: true

Size: 761 Bytes

Versions: 52

Compression:

Stored size: 761 Bytes

Contents

# frozen_string_literal: true

class Nokogiri::XML::Text
  def normalize
    content =~ /\S/ ? content.gsub(/\s+/, ' ').strip : content
  end

  def normalize!
    self.content = normalize
  end
end

class Nokogiri::XML::Node
  def normalize_text!
    xpath('//text()').each(&:normalize!)
  end
end

class Nokogiri::XML::Document
  PRETTIFY_XSLT = Nokogiri::XSLT <<-EOC
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output omit-xml-declaration="yes" indent="yes"/>
      <xsl:template match="node()|@*">
        <xsl:copy>
          <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
      </xsl:template>
    </xsl:stylesheet>
  EOC

  def prettify
    PRETTIFY_XSLT.transform(self).to_xml
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
dor-services-9.6.2 lib/dor/utils/ng_tidy.rb
dor-services-9.6.1 lib/dor/utils/ng_tidy.rb
dor-services-9.6.0 lib/dor/utils/ng_tidy.rb
dor-services-9.5.0 lib/dor/utils/ng_tidy.rb
dor-services-9.4.0 lib/dor/utils/ng_tidy.rb
dor-services-9.3.0 lib/dor/utils/ng_tidy.rb
dor-services-9.2.1 lib/dor/utils/ng_tidy.rb
dor-services-9.2.0 lib/dor/utils/ng_tidy.rb
dor-services-9.1.0 lib/dor/utils/ng_tidy.rb
dor-services-9.0.0 lib/dor/utils/ng_tidy.rb
dor-services-8.6.0 lib/dor/utils/ng_tidy.rb
dor-services-8.5.0 lib/dor/utils/ng_tidy.rb
dor-services-8.4.0 lib/dor/utils/ng_tidy.rb
dor-services-8.3.0 lib/dor/utils/ng_tidy.rb
dor-services-8.2.0 lib/dor/utils/ng_tidy.rb
dor-services-8.1.1 lib/dor/utils/ng_tidy.rb
dor-services-8.1.0 lib/dor/utils/ng_tidy.rb
dor-services-8.0.0 lib/dor/utils/ng_tidy.rb
dor-services-7.2.4 lib/dor/utils/ng_tidy.rb
dor-services-7.2.3 lib/dor/utils/ng_tidy.rb