!!! 5 %html{:lang=>(attr :lang, 'en')}

%head
  %meta(http-equiv='Content-Type' content="text/html; charset=#{attr :encoding}")
  %meta(name='generator' content="Asciidoctor #{attr 'asciidoctor-version'}")
  %meta(name='viewport' content='width=device-width, initial-scale=1.0')
  - [:description, :keywords, :author, :copyright].each do |key|
    - if attr? key
      %meta{:name=>key, :content=>(attr key)}
  %title=((doctitle :sanitize => true) || (attr 'untitled-label'))
  - if Asciidoctor::DEFAULT_STYLESHEET_KEYS.include?(attr :stylesheet)
    - if @safe >= Asciidoctor::SafeMode::SECURE || (attr? :linkcss)
      %link(rel='stylesheet'){:href=>normalize_web_path(Asciidoctor::DEFAULT_STYLESHEET_NAME, (attr :stylesdir, ''))}
    - else
      %style=Asciidoctor::HTML5.default_asciidoctor_stylesheet
  - elsif attr? :stylesheet
    - if @safe >= Asciidoctor::SafeMode::SECURE || (attr? :linkcss)
      %link(rel='stylesheet'){:href=>normalize_web_path((attr :stylesheet), (attr :stylesdir, ''))}
    - else
      %style=read_asset(normalize_system_path((attr :stylesheet), (attr :stylesdir, '')), true)
  - if attr? :icons, 'font'
    - if !(attr 'iconfont-remote', '').nil?
      %link(rel='stylesheet'){:href=>(attr 'iconfont-cdn', 'http://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.2.1/css/font-awesome.min.css')}
    - else
      %link(rel='stylesheet'){:href=>normalize_web_path("#{attr 'iconfont-name', 'font-awesome'}.css", (attr :stylesdir, ''))}
  - case attr 'source-highlighter'
  - when 'coderay'
    - if (attr 'coderay-css', 'class') == 'class'
      - if @safe >= Asciidoctor::SafeMode::SECURE || (attr? :linkcss)
        %link(rel='stylesheet'){:href=>normalize_web_path('asciidoctor-coderay.css', (attr :stylesdir, ''))}
      - else
        %style=Asciidoctor::HTML5.default_coderay_stylesheet
  - when 'pygments'
    - if (attr 'pygments-css', 'class') == 'class'
      - if @safe >= Asciidoctor::SafeMode::SECURE || (attr? :linkcss)
        %link(rel='stylesheet'){:href=>normalize_web_path('asciidoctor-pygments.css', (attr :stylesdir, ''))}
      - else
        %style=Asciidoctor::HTML5.pygments_stylesheet(attr 'pygments-style')
  - when 'highlightjs'
    %link(rel='stylesheet' href="#{attr :highlightjsdir, 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4'}/styles/#{attr 'highlightjs-theme', 'default'}.min.css")
    %script(src="#{attr :highlightjsdir, 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4'}/highlight.min.js")
    %script hljs.initHighlightingOnLoad()
  - when 'prettify'
    %link(rel='stylesheet' href="#{attr :prettifydir, 'http://cdnjs.cloudflare.com/ajax/libs/prettify/r298'}/#{attr 'prettify-theme', 'prettify'}.min.css")
    %script(src="#{attr :prettifydir, 'http://cdnjs.cloudflare.com/ajax/libs/prettify/r298'}/prettify.min.js")
    %script document.addEventListener('DOMContentLoaded', prettyPrint)
  - if attr? 'math'
    %script(type='text/x-mathjax-config')
      :plain
        MathJax.Hub.Config({
          tex2jax: {
            inlineMath: [['\\(','\\)']],
            displayMath: [['\\[','\\]']],
            ignoreClass: 'nomath|nolatexmath'
          },
          asciimath2jax: {
            delimiters: [['\\$','\\$']],
            ignoreClass: 'nomath|noasciimath'
          }
        });
    %script(type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_HTMLorMML')
    %script(type='text/javascript')
      :plain
        document.addEventListener('DOMContentLoaded', MathJax.Hub.TypeSet)
  - unless (docinfo_content = docinfo).empty?
    =docinfo_content
%body{:id => @id, :class=>[doctype, ((attr? 'toc-class') && (attr? :toc) && (attr? 'toc-placement', 'auto') ? "#{attr 'toc-class'} toc-#{attr 'toc-position', 'left'}" : nil)], :style=>("max-width: #{attr 'max-width'};" if (attr? 'max-width'))}
  - unless noheader
    -# AsciiDoc leaves an empty header div even if there's no doctitle
    #header
      - if has_header?
        - unless notitle
          %h1=@header.title
        - if attr? :author
          %span#author=attr :author
          %br
          - if attr? :email
            %span#email=sub_macros(attr :email)
            %br
          - if (authorcount = (attr :authorcount).to_i) > 1
            - (2..authorcount).each do |idx|
              %span{:id=>"author#{idx}", :class=>"author"}=(attr "author_#{idx}")
              %br
              - if attr? "email_#{idx}"
                %span{:id=>"email#{idx}", :class=>"email"}= sub_macros(attr "email_#{idx}")
        - if attr? :revnumber
          %span#revnumber #{((attr 'version-label') || '').downcase} #{attr :revnumber}#{',' if (attr? :revdate)}
        - if attr? :revdate
          %span#revdate=attr :revdate
        - if attr? :revremark
          %br
          %span#revremark=attr :revremark
      - if (attr? :toc) && (attr? 'toc-placement', 'auto')
        #toc{:class=>(attr 'toc-class', 'toc')}
          #toctitle=attr 'toc-title'
          -# hackish, find a way to make the toc generator more generic
          =Asciidoctor::HTML5::DocumentTemplate.outline(self, (attr :toclevels, 2).to_i)
  #content=content.chomp
  - unless !footnotes? || attr?(:nofootnotes)
    #footnotes
      %hr
      - footnotes.each do |fn|
        .footnote{:id=>['_footnote', fn.index]}
          = succeed ". #{fn.text}" do
            %a(href="#_footnoteref_#{fn.index}")=fn.index
  #footer
    #footer-text
      - if attr? :revnumber
        #{attr 'version-label'} #{attr :revnumber}
      - if attr? 'last-update-label'
        %br
        #{attr 'last-update-label'} #{attr :localdatetime}
    - unless (docinfo_content = (docinfo :footer)).empty?
      =docinfo_content