asciidoctor-htmlbook 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.adoc +7 -0
- data/README.adoc +0 -22
- data/asciidoctor-htmlbook.gemspec +1 -1
- data/lib/asciidoctor/htmlbook/converter.rb +47 -70
- data/lib/asciidoctor/htmlbook/version.rb +1 -1
- data/templates/document.html +8 -1
- data/templates/embedded.html +7 -0
- data/templates/inline_anchor.html +0 -6
- data/templates/section.html +3 -3
- metadata +4 -5
- data/templates/toc.html +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84191fe5cc45f3e8edc81303b20799f6a44ed3774cfd6dfd2f7245bd2a242099
|
4
|
+
data.tar.gz: cf845626c0e4fbedccbcc6038a9096364939a54209d5cd7ff866596c6b3d6ef0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38badaa8c38b42a6c99954f2b1c478fa8658d5d40c196cea664e0ad5128a387fa29b0b198abd7bc60986b18e2b2600cb41d39653de894b724b4522ade57ef300
|
7
|
+
data.tar.gz: dfdd788a982e8c1e4bdc32eeaac3b0464867ca6c41e241f1da8eb3858e80d8ae12eb77f13dee33ca37668b85e2c634030085aadd41bd8c07e9ca3843de8d31da
|
data/.travis.yml
CHANGED
data/CHANGELOG.adoc
CHANGED
data/README.adoc
CHANGED
@@ -102,11 +102,6 @@ Asciidoctor.convert '*This* is Asciidoctor.', backend: 'htmlbook', header_footer
|
|
102
102
|
|
103
103
|
You can overwrite default templates by adding `:template_dir` option:
|
104
104
|
|
105
|
-
[source, console]
|
106
|
-
----
|
107
|
-
$ asciidoctor-htmlbook -T path/to/templates basic-example.adoc
|
108
|
-
----
|
109
|
-
|
110
105
|
[source, ruby]
|
111
106
|
----
|
112
107
|
Asciidoctor.convert '*This* is Asciidoctor.', backend: 'htmlbook', template_dir: 'path/to/templates'
|
@@ -119,23 +114,6 @@ asciidoctor-htmlbook template do not compatible with asciidoctor built-in templa
|
|
119
114
|
View link:./templates[] for more info.
|
120
115
|
--
|
121
116
|
|
122
|
-
== Add Table of Contents
|
123
|
-
|
124
|
-
Asciidoctor-htmlbook ignore `:toc:` attribute in Asciidoctor, instead you can use toc section:
|
125
|
-
|
126
|
-
[source, asciidoc]
|
127
|
-
--
|
128
|
-
[preface]
|
129
|
-
== Preface
|
130
|
-
|
131
|
-
[toc]
|
132
|
-
== Table of Contents
|
133
|
-
|
134
|
-
== Chapter
|
135
|
-
--
|
136
|
-
|
137
|
-
So that you can control position of toc.
|
138
|
-
|
139
117
|
== Development
|
140
118
|
|
141
119
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_runtime_dependency "asciidoctor", "~> 2.0"
|
25
25
|
spec.add_runtime_dependency "liquid", "~> 4.0"
|
26
26
|
|
27
|
-
spec.add_development_dependency "bundler", "~> 2.
|
27
|
+
spec.add_development_dependency "bundler", "~> 2.1"
|
28
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
29
29
|
spec.add_development_dependency "minitest", "~> 5.0"
|
30
30
|
end
|
@@ -7,20 +7,13 @@ module Asciidoctor
|
|
7
7
|
|
8
8
|
def initialize(backend, options = {})
|
9
9
|
super
|
10
|
-
|
10
|
+
init_backend_traits outfilesuffix: '.html'
|
11
|
+
@template_dirs = (options[:template_dirs] || []).prepend(DEFAULT_TEMPLATE_PATH)
|
11
12
|
@templates = {}
|
12
13
|
end
|
13
14
|
|
14
|
-
def convert(node, transform =
|
15
|
-
|
16
|
-
get_template('embedded')
|
17
|
-
elsif node.node_name == 'section' && node.sectname == 'toc'
|
18
|
-
get_template('toc')
|
19
|
-
else
|
20
|
-
get_template(node.node_name)
|
21
|
-
end
|
22
|
-
|
23
|
-
template.render 'node' => node_to_liquid(node)
|
15
|
+
def convert(node, transform = node.node_name, options = {})
|
16
|
+
get_template(transform).render 'node' => node_to_hash(node)
|
24
17
|
end
|
25
18
|
|
26
19
|
private
|
@@ -28,7 +21,7 @@ module Asciidoctor
|
|
28
21
|
def get_template(name)
|
29
22
|
return @templates[name] if @templates[name]
|
30
23
|
|
31
|
-
@template_dirs.each do |template_dir|
|
24
|
+
@template_dirs.reverse.each do |template_dir|
|
32
25
|
path = File.join template_dir, "#{name}.html"
|
33
26
|
if File.exist?(path)
|
34
27
|
@templates[name] = Liquid::Template.parse(File.read(path))
|
@@ -43,48 +36,36 @@ module Asciidoctor
|
|
43
36
|
@templates[name]
|
44
37
|
end
|
45
38
|
|
46
|
-
def
|
39
|
+
def node_to_hash(node)
|
47
40
|
case node
|
48
41
|
when Asciidoctor::Document
|
49
|
-
|
42
|
+
document_to_hash(node)
|
50
43
|
when Asciidoctor::Section
|
51
|
-
|
44
|
+
section_to_hash(node)
|
52
45
|
when Asciidoctor::Block
|
53
|
-
|
46
|
+
block_to_hash(node)
|
54
47
|
when Asciidoctor::List
|
55
|
-
|
48
|
+
list_to_hash(node)
|
56
49
|
when Asciidoctor::Table
|
57
|
-
|
50
|
+
table_to_hash(node)
|
58
51
|
when Asciidoctor::Inline
|
59
|
-
|
52
|
+
inline_to_hash(node)
|
60
53
|
else
|
61
|
-
raise "
|
54
|
+
raise "Uncatched type #{node} #{node.attributes}"
|
62
55
|
end
|
63
56
|
end
|
64
57
|
|
65
|
-
def
|
58
|
+
def abstract_node_to_hash(node)
|
66
59
|
{
|
67
60
|
'context' => node.context.to_s,
|
68
61
|
'node_name' => node.node_name,
|
69
62
|
'id' => node.id,
|
70
|
-
'attributes' => node.attributes
|
71
|
-
'document' => document_info(node.document)
|
72
|
-
}
|
73
|
-
end
|
74
|
-
|
75
|
-
def document_info(document)
|
76
|
-
@document_info ||= {
|
77
|
-
'references' => {
|
78
|
-
'refs' => document.references[:refs].map { |refid, node|
|
79
|
-
[refid, { 'xreftext' => node.xreftext }]
|
80
|
-
}.to_h
|
81
|
-
},
|
82
|
-
'attributes' => document.attributes
|
63
|
+
'attributes' => node.attributes
|
83
64
|
}
|
84
65
|
end
|
85
66
|
|
86
|
-
def
|
87
|
-
|
67
|
+
def abstract_block_to_hash(node)
|
68
|
+
abstract_node_to_hash(node).merge!({
|
88
69
|
'level' => node.level,
|
89
70
|
'title' => node.title,
|
90
71
|
'caption' => node.caption,
|
@@ -95,16 +76,18 @@ module Asciidoctor
|
|
95
76
|
})
|
96
77
|
end
|
97
78
|
|
98
|
-
def
|
99
|
-
|
79
|
+
def document_to_hash(node)
|
80
|
+
abstract_block_to_hash(node).merge!({
|
100
81
|
'header' => {
|
101
82
|
'title' => (node.header && node.header.title)
|
102
|
-
}
|
83
|
+
},
|
84
|
+
'title' => node.attributes['doctitle'],
|
85
|
+
'toc' => outline(node)
|
103
86
|
})
|
104
87
|
end
|
105
88
|
|
106
|
-
def
|
107
|
-
|
89
|
+
def section_to_hash(node)
|
90
|
+
abstract_block_to_hash(node).merge!({
|
108
91
|
'index' => node.index,
|
109
92
|
'number' => node.number,
|
110
93
|
'sectname' => (node.sectname == 'section' ? "sect#{node.level}" : node.sectname),
|
@@ -112,30 +95,24 @@ module Asciidoctor
|
|
112
95
|
'numbered' => node.numbered,
|
113
96
|
'sectnum' => node.sectnum
|
114
97
|
})
|
115
|
-
|
116
|
-
if node.sectname == 'toc'
|
117
|
-
attributes['content'] = outline(node.document)
|
118
|
-
end
|
119
|
-
|
120
|
-
attributes
|
121
98
|
end
|
122
99
|
|
123
|
-
def
|
124
|
-
|
100
|
+
def block_to_hash(node)
|
101
|
+
abstract_block_to_hash(node).merge!({
|
125
102
|
'blockname' => node.blockname
|
126
103
|
})
|
127
104
|
end
|
128
105
|
|
129
106
|
def outline(node)
|
130
|
-
result =
|
131
|
-
if node.sections.any? && node.level < (node.document.attributes['toclevels'] || 2)
|
107
|
+
result = ''
|
108
|
+
if node.sections.any? && node.level < (node.document.attributes['toclevels'] || 2).to_i
|
132
109
|
result << "<ol>"
|
133
110
|
node.sections.each do |section|
|
134
111
|
next if section.sectname == 'toc'
|
135
112
|
|
136
113
|
result << "<li>"
|
137
114
|
result << %Q(<a href="##{section.id}">)
|
138
|
-
result << "#{section.sectnum} " if section.numbered && section.level < (node.document.attributes['sectnumlevels'] || 3)
|
115
|
+
result << "#{section.sectnum} " if section.numbered && section.level < (node.document.attributes['sectnumlevels'] || 3).to_i
|
139
116
|
result << section.title
|
140
117
|
result << "</a>"
|
141
118
|
result << outline(section)
|
@@ -146,43 +123,43 @@ module Asciidoctor
|
|
146
123
|
result
|
147
124
|
end
|
148
125
|
|
149
|
-
def
|
126
|
+
def list_to_hash(node)
|
150
127
|
case node.context
|
151
128
|
when :dlist
|
152
|
-
|
129
|
+
abstract_block_to_hash(node).merge!({
|
153
130
|
'items' => node.items.map { |terms, item|
|
154
131
|
{
|
155
|
-
'terms' => terms.map {|term|
|
156
|
-
'description' =>
|
132
|
+
'terms' => terms.map {|term| listitem_to_hash(term) },
|
133
|
+
'description' => listitem_to_hash(item)
|
157
134
|
}
|
158
135
|
}
|
159
136
|
})
|
160
137
|
else
|
161
|
-
|
162
|
-
'items' => node.blocks.map { |item|
|
138
|
+
abstract_block_to_hash(node).merge!({
|
139
|
+
'items' => node.blocks.map { |item| listitem_to_hash(item) }
|
163
140
|
})
|
164
141
|
end
|
165
142
|
end
|
166
143
|
|
167
|
-
def
|
168
|
-
|
144
|
+
def listitem_to_hash(node)
|
145
|
+
abstract_block_to_hash(node).merge!({
|
169
146
|
'text' => (node.text? ? node.text : nil)
|
170
147
|
})
|
171
148
|
end
|
172
149
|
|
173
|
-
def
|
174
|
-
|
150
|
+
def table_to_hash(node)
|
151
|
+
abstract_block_to_hash(node).merge!({
|
175
152
|
'columns' => node.columns,
|
176
153
|
'rows' => {
|
177
|
-
'head' => node.rows.head.map { |row| row.map {|cell|
|
178
|
-
'body' => node.rows.body.map { |row| row.map {|cell|
|
179
|
-
'foot' => node.rows.foot.map { |row| row.map {|cell|
|
154
|
+
'head' => node.rows.head.map { |row| row.map {|cell| cell_to_hash(cell) } },
|
155
|
+
'body' => node.rows.body.map { |row| row.map {|cell| cell_to_hash(cell) } },
|
156
|
+
'foot' => node.rows.foot.map { |row| row.map {|cell| cell_to_hash(cell) } }
|
180
157
|
}
|
181
158
|
})
|
182
159
|
end
|
183
160
|
|
184
|
-
def
|
185
|
-
|
161
|
+
def cell_to_hash(node)
|
162
|
+
abstract_node_to_hash(node).merge!({
|
186
163
|
'text' => node.text,
|
187
164
|
'content' => node.content,
|
188
165
|
'style' => node.style,
|
@@ -191,9 +168,9 @@ module Asciidoctor
|
|
191
168
|
})
|
192
169
|
end
|
193
170
|
|
194
|
-
def
|
195
|
-
|
196
|
-
'text' => node.text,
|
171
|
+
def inline_to_hash(node)
|
172
|
+
abstract_node_to_hash(node).merge!({
|
173
|
+
'text' => node.text || node.document.references[:refs][node.attributes['refid']]&.xreftext || "[#{node.attributes['refid']}]",
|
197
174
|
'type' => node.type.to_s,
|
198
175
|
'target' => node.target,
|
199
176
|
'xreftext' => node.xreftext
|
data/templates/document.html
CHANGED
@@ -2,9 +2,16 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<meta charset="utf-8" />
|
5
|
-
<title>{{ node.
|
5
|
+
{% if node.title %}<title>{{ node.title }}</title>{% endif %}
|
6
6
|
</head>
|
7
7
|
<body data-type="book">
|
8
|
+
{% if node.title %}<h1>{{ node.title }}</h1>{% endif %}
|
9
|
+
{% if node.attributes.toc %}
|
10
|
+
<nav data-type="toc">
|
11
|
+
<h1>{{ node.attributes.toc-title }}</h1>
|
12
|
+
{{ node.toc }}
|
13
|
+
</nav>
|
14
|
+
{% endif %}
|
8
15
|
{{ node.content }}
|
9
16
|
</body>
|
10
17
|
</html>
|
data/templates/embedded.html
CHANGED
@@ -1,12 +1,6 @@
|
|
1
1
|
{% case node.type %}
|
2
2
|
{% when 'xref' %}
|
3
|
-
{% if node.text %}
|
4
3
|
<a data-type="xref" href="{{ node.target }}">{{ node.text }}</a>
|
5
|
-
{% elsif node.document.references.refs[node.attributes.refid] %}
|
6
|
-
<a data-type="xref" href="{{ node.target }}">{{ node.document.references.refs[node.attributes.refid].xreftext }}</a>
|
7
|
-
{% else %}
|
8
|
-
<a data-type="xref" href="{{ node.target }}">[{{ node.attributes.refid }}]</a>
|
9
|
-
{% endif %}
|
10
4
|
{% when 'ref' %}
|
11
5
|
<a id="{{ node.id }}"></a>
|
12
6
|
{% when 'link' %}
|
data/templates/section.html
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
{% case node.sectname %}
|
2
|
-
{% when '
|
3
|
-
<
|
2
|
+
{% when 'part' %}
|
3
|
+
<div id="{{node.id}}" data-type="part">
|
4
4
|
<h1>{% if node.numbered %}{{ node.sectnum }} {% endif %}{{ node.title }}</h1>
|
5
5
|
{{ node.content }}
|
6
|
-
</
|
6
|
+
</div>
|
7
7
|
{% when 'sect1' %}
|
8
8
|
<section id="{{node.id}}" data-type="chapter">
|
9
9
|
<h1>{% if node.numbered %}{{ node.sectnum }} {% endif %}{{ node.title }}</h1>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-htmlbook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rei
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '2.
|
47
|
+
version: '2.1'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '2.
|
54
|
+
version: '2.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -133,7 +133,6 @@ files:
|
|
133
133
|
- templates/stem.html
|
134
134
|
- templates/table.html
|
135
135
|
- templates/thematic_break.html
|
136
|
-
- templates/toc.html
|
137
136
|
- templates/ulist.html
|
138
137
|
- templates/verse.html
|
139
138
|
- templates/video.html
|
data/templates/toc.html
DELETED