Class: Prawn::Markup::Normalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/prawn/markup/support/normalizer.rb

Overview

Normalizes HTML markup:

* assert that self-closing tags are always closed
* replace html entities with their UTF-8 correspondent string
* normalize white space
* wrap entire content into <root> tag

Constant Summary collapse

SELF_CLOSING_ELEMENTS =
%w[br img hr].freeze
REPLACE_ENTITIES =
{
  nbsp: ' '
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ Normalizer

Returns a new instance of Normalizer.



17
18
19
# File 'lib/prawn/markup/support/normalizer.rb', line 17

def initialize(html)
  @html = html.dup
end

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



15
16
17
# File 'lib/prawn/markup/support/normalizer.rb', line 15

def html
  @html
end

Instance Method Details

#normalizeObject



21
22
23
24
25
26
# File 'lib/prawn/markup/support/normalizer.rb', line 21

def normalize
  close_self_closing_elements
  normalize_spaces
  replace_html_entities
  "<root>#{html}</root>"
end