summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2014-03-03 01:30:00 -0700
committerDan Allen <dan.j.allen@gmail.com>2014-03-03 01:33:39 -0700
commite37eb56a0aa5c0dfa82c150caa50afbfad1c29ae (patch)
treeea824bf3cdab83ca7ba72f353a41a08c4b44b393
parentf2225b2fa97a8879b06dcef6648aa384493b07c7 (diff)
cleanup html header and optimize
- remove http-equiv="Content-Type" meta tag - add meta hint for IE to use latest rendering engine - add charset meta element - optimize xmldoc_from_string test helper method
-rw-r--r--lib/asciidoctor/converter/html5.rb14
-rw-r--r--test/test_helper.rb4
2 files changed, 10 insertions, 8 deletions
diff --git a/lib/asciidoctor/converter/html5.rb b/lib/asciidoctor/converter/html5.rb
index 401896b6..a5d12379 100644
--- a/lib/asciidoctor/converter/html5.rb
+++ b/lib/asciidoctor/converter/html5.rb
@@ -19,22 +19,24 @@ module Asciidoctor
QUOTE_TAGS.default = [nil, nil, nil]
def initialize backend, opts = {}
- @short_tag_slash = ((@htmlsyntax = opts[:htmlsyntax]) == 'xml' ? '/' : nil)
+ @xml_mode = opts[:htmlsyntax] == 'xml'
+ @short_tag_slash = @xml_mode ? '/' : nil
@stylesheets = Stylesheets.instance
end
def document node
- xml = node.document.attr? 'htmlsyntax', 'xml'
result = []
short_tag_slash_local = @short_tag_slash
br = %(<br#{short_tag_slash_local}>)
linkcss = node.safe >= SafeMode::SECURE || (node.attr? 'linkcss')
result << '<!DOCTYPE html>'
- result << ((node.attr? 'nolang') ? '<html' : %(<html lang="#{node.attr 'lang', 'en'}")) + (xml ? %( xmlns="http://www.w3.org/1999/xhtml">) : ">")
+ lang_attribute = (node.attr? 'nolang') ? nil : %( lang="#{node.attr 'lang', 'en'}")
+ result << %(<html#{@xml_mode ? ' xmlns="http://www.w3.org/1999/xhtml"' : nil}#{lang_attribute}>)
result << %(<head>
-<meta http-equiv="Content-Type" content="text/html; charset=#{node.attr 'encoding'}"#{short_tag_slash_local}>
-<meta name="generator" content="Asciidoctor #{node.attr 'asciidoctor-version'}"#{short_tag_slash_local}>
-<meta name="viewport" content="width=device-width, initial-scale=1.0"#{short_tag_slash_local}>)
+<meta charset="#{node.attr 'encoding', 'UTF-8'}"#{short_tag_slash_local}>
+<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"#{short_tag_slash_local}><![endif]-->
+<meta name="viewport" content="width=device-width, initial-scale=1.0"#{short_tag_slash_local}>
+<meta name="generator" content="Asciidoctor #{node.attr 'asciidoctor-version'}"#{short_tag_slash_local}>)
['description', 'keywords', 'author', 'copyright'].each do |key|
result << %(<meta name="#{key}" content="#{node.attr key}"#{short_tag_slash_local}>) if node.attr? key
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 32e22384..605f05bd 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -17,6 +17,7 @@ autoload :Pathname, 'pathname'
ENV['SUPPRESS_DEBUG'] ||= 'true'
RE_XMLNS_ATTRIBUTE = / xmlns="[^"]+"/
+RE_DOCTYPE = /\s*<!DOCTYPE (.*)/
class Test::Unit::TestCase
def windows?
@@ -133,10 +134,9 @@ class Test::Unit::TestCase
end
def xmldoc_from_string(content)
- doctype_match = content.match(/\s*<!DOCTYPE (.*)/)
if content.match(RE_XMLNS_ATTRIBUTE)
doc = Nokogiri::XML::Document.parse(content)
- elsif !doctype_match
+ elsif !(doctype_match = content.match(RE_DOCTYPE))
doc = Nokogiri::HTML::DocumentFragment.parse(content)
elsif doctype_match[1].start_with? 'html'
doc = Nokogiri::HTML::Document.parse(content)