Class: Prawn::Markup::Normalizer
- Inherits:
-
Object
- Object
- Prawn::Markup::Normalizer
- 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
-
#html ⇒ Object
readonly
Returns the value of attribute html.
Instance Method Summary collapse
-
#initialize(html) ⇒ Normalizer
constructor
A new instance of Normalizer.
- #normalize ⇒ Object
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
#html ⇒ Object (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
#normalize ⇒ Object
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 |