Class: Roadie::MarkupImprover Private
- Inherits:
-
Object
- Object
- Roadie::MarkupImprover
- Defined in:
- lib/roadie/markup_improver.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Class that improves the markup of a HTML DOM tree
This class will improve the following aspects of the DOM:
-
A HTML5 doctype will be added if missing, other doctypes will be left as-is.
-
Basic HTML elements will be added if missing.
-
‘<html>`
-
‘<head>`
-
‘<body>`
-
‘<meta>` declaring charset and content-type (text/html)
-
Instance Method Summary collapse
-
#improve ⇒ nil
private
Passed DOM will be mutated.
-
#initialize(dom, original_html) ⇒ MarkupImprover
constructor
private
The original HTML must also be passed in in order to handle the doctypes since a
Nokogiri::HTML::Document
will always have a doctype, no matter if the original source had it or not.
Constructor Details
#initialize(dom, original_html) ⇒ MarkupImprover
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The original HTML must also be passed in in order to handle the doctypes since a Nokogiri::HTML::Document
will always have a doctype, no matter if the original source had it or not. Reading the raw HTML is the only way to determine if we want to add a HTML5 doctype or not.
19 20 21 22 |
# File 'lib/roadie/markup_improver.rb', line 19 def initialize(dom, original_html) @dom = dom @html = original_html end |
Instance Method Details
#improve ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns passed DOM will be mutated.
25 26 27 28 29 30 |
# File 'lib/roadie/markup_improver.rb', line 25 def improve ensure_doctype_present ensure_html_element_present head = ensure_head_element_present ensure_declared_charset head end |