Class: AsciidoctorVaped::Converter::HTML

Inherits:
BaseConverter show all
Includes:
Node
Defined in:
lib/asciidoctor_vaped/converter/html.rb

Constant Summary

Constants included from Node

Node::NODE_RENDERERS

Constants inherited from BaseConverter

BaseConverter::TEXT_NODE_CONTEXTS

Instance Method Summary collapse

Methods inherited from BaseConverter

#initialize

Constructor Details

This class inherits a constructor from AsciidoctorVaped::Converter::BaseConverter

Instance Method Details

#admonition(node) ⇒ Object



65
66
67
68
# File 'lib/asciidoctor_vaped/converter/html.rb', line 65

def admonition(node)
  name = node.attributes.fetch(:name, "note").to_s
  %(<div class="admonitionblock #{escape_attr name.downcase}">\n<table>\n<tr>\n<td class="icon"><div class="title">#{escape name.capitalize}</div></td>\n<td class="content">#{render_content node}</td>\n</tr>\n</table>\n</div>)
end

#convert(document) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/asciidoctor_vaped/converter/html.rb', line 8

def convert(document)
  title = document.doctitle || "Untitled"
  body = render_nodes(document)
  return body if @options[:header_footer] == false

%(<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>#{escape title}</title>
  </head>
  <body>
    #{body}
  </body>
</html>)
end

#emphasis_tagObject



102
103
104
# File 'lib/asciidoctor_vaped/converter/html.rb', line 102

def emphasis_tag
  "em"
end

#example(node) ⇒ Object



70
71
72
# File 'lib/asciidoctor_vaped/converter/html.rb', line 70

def example(node)
  wrapped_node("exampleblock", node)
end


94
95
96
# File 'lib/asciidoctor_vaped/converter/html.rb', line 94

def link_attrs(node)
  { href: node.attributes.fetch(:target) }
end


90
91
92
# File 'lib/asciidoctor_vaped/converter/html.rb', line 90

def link_tag
  "a"
end

#list(node) ⇒ Object



45
46
47
48
49
# File 'lib/asciidoctor_vaped/converter/html.rb', line 45

def list(node)
  tag_name = list_tag(node)
  items = node.children.map { |item| list_item(item) }.join("\n")
  %(<div class="#{node.context}">\n<#{tag_name}>\n#{items}\n</#{tag_name}>\n</div>)
end

#list_item(node) ⇒ Object



51
52
53
# File 'lib/asciidoctor_vaped/converter/html.rb', line 51

def list_item(node)
  "<li>#{render_content node}</li>"
end

#list_tag(node) ⇒ Object



114
115
116
# File 'lib/asciidoctor_vaped/converter/html.rb', line 114

def list_tag(node)
  node.context == :olist ? "ol" : "ul"
end

#listing(node) ⇒ Object



35
36
37
38
39
# File 'lib/asciidoctor_vaped/converter/html.rb', line 35

def listing(node)
  language = node.attributes[:language]
  code_attrs = language ? %( class="language-#{escape_attr language}" data-lang="#{escape_attr language}") : ""
  %(<div class="listingblock">\n#{title node}\n<div class="content">\n<pre class="highlight"><code#{code_attrs}>#{escape node.text}</code></pre>\n</div>\n</div>)
end

#literal_tagObject



41
42
43
# File 'lib/asciidoctor_vaped/converter/html.rb', line 41

def literal_tag
  "pre"
end

#monospace_tagObject



106
107
108
# File 'lib/asciidoctor_vaped/converter/html.rb', line 106

def monospace_tag
  "code"
end

#paragraph_tagObject



25
26
27
# File 'lib/asciidoctor_vaped/converter/html.rb', line 25

def paragraph_tag
  "p"
end

#quote(node) ⇒ Object



74
75
76
# File 'lib/asciidoctor_vaped/converter/html.rb', line 74

def quote(node)
  wrapped_node("quoteblock", node)
end

#section(node) ⇒ Object



29
30
31
32
33
# File 'lib/asciidoctor_vaped/converter/html.rb', line 29

def section(node)
  level = node.attributes.fetch(:level, 1)
  heading = "h#{[level + 1, 6].min}"
  %(<div class="sect#{level}">\n<#{heading}>#{render_text node}</#{heading}>\n#{render_nodes node}\n</div>)
end


78
79
80
# File 'lib/asciidoctor_vaped/converter/html.rb', line 78

def sidebar(node)
  wrapped_node("sidebarblock", node)
end

#strong_tagObject



98
99
100
# File 'lib/asciidoctor_vaped/converter/html.rb', line 98

def strong_tag
  "strong"
end

#table(node) ⇒ Object



55
56
57
58
# File 'lib/asciidoctor_vaped/converter/html.rb', line 55

def table(node)
  rows = node.children.map { |row| table_row(row) }.join("\n")
  %(<table class="tableblock frame-all grid-all stretch">\n<tbody>\n#{rows}\n</tbody>\n</table>)
end

#table_row(row) ⇒ Object



60
61
62
63
# File 'lib/asciidoctor_vaped/converter/html.rb', line 60

def table_row(row)
  cells = row.children.map { |cell| %(<td class="tableblock halign-left valign-top">#{render_text cell}</td>) }
  "<tr>\n#{cells.join("\n")}\n</tr>"
end

#title_attrsObject



86
87
88
# File 'lib/asciidoctor_vaped/converter/html.rb', line 86

def title_attrs
  { class: "title" }
end

#title_tagObject



82
83
84
# File 'lib/asciidoctor_vaped/converter/html.rb', line 82

def title_tag
  "div"
end

#wrapped_node(class_name, node) ⇒ Object



110
111
112
# File 'lib/asciidoctor_vaped/converter/html.rb', line 110

def wrapped_node(class_name, node)
  %(<div class="#{class_name}">\n#{title node}\n<div class="content">#{render_content node}</div>\n</div>)
end