Class: Roadie::MarkupImprover Private

Inherits:
Object
  • Object
show all
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.

Note:

Due to a Nokogiri bug, the HTML5 doctype cannot be added under JRuby. No doctype is outputted under JRuby. See github.com/sparklemotion/nokogiri/issues/984

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

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.



20
21
22
23
# File 'lib/roadie/markup_improver.rb', line 20

def initialize(dom, original_html)
  @dom = dom
  @html = original_html
end

Instance Method Details

#improvenil

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.

Returns:

  • (nil)

    passed DOM will be mutated



26
27
28
29
30
# File 'lib/roadie/markup_improver.rb', line 26

def improve
  ensure_doctype_present
  head = ensure_head_element_present
  ensure_declared_charset head
end