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.



19
20
21
# File 'lib/prawn/markup/support/normalizer.rb', line 19

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

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



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

def html
  @html
end

Instance Method Details

#normalizeObject



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

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