class Asciidoctor::HTML5::DocumentTemplate
def default_coderay_stylesheet
Internal: Generate the default stylesheet for CodeRay
def default_coderay_stylesheet Asciidoctor.require_library 'coderay' ::CodeRay::Encoders[:html]::CSS.new(:default).stylesheet end
def render_outline(node, to_depth = 2)
def render_outline(node, to_depth = 2) toc_level = nil sections = node.sections unless sections.empty? toc_level, indent = '' unless node.is_a?(::Asciidoctor::Document) indent = ' ' * (node.document.doctype == 'book' ? node.level + 1 : node.level) end toc_level << "#{indent}<ol>\n" sections.each do |section| toc_level << "#{indent} <li><a href=\"##{section.id}\">#{section.sectnum} #{section.title}</a></li>\n" if section.level < to_depth && (child_toc_level = render_outline(section, to_depth)) toc_level << "#{indent} <li>\n#{child_toc_level}\n#{indent} </li>\n" end end toc_level << "#{indent}</ol>" end toc_level end
def template
def template @template ||= @eruby.new <<-EOS #encoding:UTF-8%> DOCTYPE html> tml lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=<%= attr :encoding %>"> <meta name="generator" content="Asciidoctor <%= attr 'asciidoctor-version' %>"> <% if attr? :description %><meta name="description" content="<%= attr :description %>"><% end %> <% if attr? :keywords %><meta name="keywords" content="<%= attr :keywords %>"><% end %> <title><%= doctitle %></title> <% if attr? :toc %> <style> oc > ol { padding-left: 0; } oc ol { list-style-type: none; } </style> <% end %> <% unless attr(:stylesheet, '').empty? %> <link rel="stylesheet" href="<%= File.join((attr :stylesdir, '.'), (attr :stylesheet)) %>"> <% end %> <% case attr 'source-highlighter' %><% when 'coderay' %> <style> e.highlight { border: none; background-color: #F8F8F8; } e.highlight code, pre.highlight pre { color: #333; } e.highlight span.line-numbers { display: inline-block; margin-right: 4px; padding: 1px 4px; } e.highlight .line-numbers { background-color: #D5F6F6; color: gray; } e.highlight .line-numbers pre { color: gray; } if (attr 'coderay-css', 'class') == 'class' %><%= template.default_coderay_stylesheet %><% end %> </style><% when 'highlightjs' %> <link rel="stylesheet" href="<%= (attr :highlightjsdir, 'http://cdnjs.cloudflare.com/ajax/libs/highlight.js/7.3') %>/styles/<%= (attr 'highlightjs-theme', 'default') %>.min.css"> <style> e code { background-color: #F8F8F8; padding: 0; } </style> <script src="<%= (attr :highlightjsdir, 'http://cdnjs.cloudflare.com/ajax/libs/highlight.js/7.3') %>/highlight.min.js"></script> <script>hljs.initHighlightingOnLoad();</script> <% end %> </head> <body#{attribute('id', :'css-signature')} class="<%= doctype %>"<% if attr? 'max-width' %> style="max-width: <%= attr 'max-width' %>;"<% end %>> <% unless noheader %> <div id="header"> <% if has_header? %> <% unless notitle %> <h1><%= header.title %></h1> <% end %> <% if attr? :author %><span id="author"><%= attr :author %></span><br><% end %> <% if attr? :email %><span id="email" class="monospaced"><<%= attr :email %>></span><br><% end %> <% if attr? :revnumber %><span id="revnumber">version <%= attr :revnumber %><%= attr?(:revdate) ? ',' : '' %></span><% end %> <% if attr? :revdate %><span id="revdate"><%= attr :revdate %></span><% end %> <% if attr? :revremark %><br><span id="revremark"><%= attr :revremark %></span><% end %> <% end %> <% if attr? :toc %> <div id="toc"> <div id="toctitle"><%= attr 'toc-title', 'Table of Contents' %></div> = template.render_outline(self, (attr :toclevels, 2).to_i) %> </div> <% end %> </div> <% end %> <div id="content"> = content %> </div> <div id="footer"> <div id="footer-text"> Last updated <%= attr :localdatetime %> </div> </div> </body> html> EOS end