asciidoctor 2.0.10 → 2.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +211 -22
- data/LICENSE +1 -1
- data/README-de.adoc +12 -13
- data/README-fr.adoc +11 -15
- data/README-jp.adoc +9 -17
- data/README-zh_CN.adoc +17 -18
- data/README.adoc +140 -132
- data/asciidoctor.gemspec +6 -6
- data/data/locale/attributes-ar.adoc +4 -3
- data/data/locale/attributes-be.adoc +23 -0
- data/data/locale/attributes-bg.adoc +4 -3
- data/data/locale/attributes-ca.adoc +6 -5
- data/data/locale/attributes-cs.adoc +4 -3
- data/data/locale/attributes-da.adoc +6 -5
- data/data/locale/attributes-de.adoc +4 -4
- data/data/locale/attributes-en.adoc +4 -4
- data/data/locale/attributes-es.adoc +6 -5
- data/data/locale/attributes-fa.adoc +4 -3
- data/data/locale/attributes-fi.adoc +4 -3
- data/data/locale/attributes-fr.adoc +6 -5
- data/data/locale/attributes-hu.adoc +4 -3
- data/data/locale/attributes-id.adoc +4 -3
- data/data/locale/attributes-it.adoc +6 -5
- data/data/locale/attributes-ja.adoc +4 -3
- data/data/locale/{attributes-kr.adoc → attributes-ko.adoc} +4 -3
- data/data/locale/attributes-nb.adoc +4 -3
- data/data/locale/attributes-nl.adoc +6 -5
- data/data/locale/attributes-nn.adoc +4 -3
- data/data/locale/attributes-pl.adoc +8 -7
- data/data/locale/attributes-pt.adoc +6 -5
- data/data/locale/attributes-pt_BR.adoc +6 -5
- data/data/locale/attributes-ro.adoc +4 -3
- data/data/locale/attributes-ru.adoc +6 -5
- data/data/locale/attributes-sr.adoc +4 -4
- data/data/locale/attributes-sr_Latn.adoc +4 -4
- data/data/locale/attributes-sv.adoc +4 -4
- data/data/locale/attributes-tr.adoc +4 -3
- data/data/locale/attributes-uk.adoc +6 -5
- data/data/locale/attributes-zh_CN.adoc +4 -3
- data/data/locale/attributes-zh_TW.adoc +4 -3
- data/data/reference/syntax.adoc +14 -7
- data/data/stylesheets/asciidoctor-default.css +27 -28
- data/lib/asciidoctor.rb +38 -12
- data/lib/asciidoctor/abstract_block.rb +9 -4
- data/lib/asciidoctor/abstract_node.rb +16 -6
- data/lib/asciidoctor/attribute_list.rb +64 -72
- data/lib/asciidoctor/cli/invoker.rb +2 -0
- data/lib/asciidoctor/cli/options.rb +10 -9
- data/lib/asciidoctor/convert.rb +167 -162
- data/lib/asciidoctor/converter.rb +13 -12
- data/lib/asciidoctor/converter/docbook5.rb +29 -12
- data/lib/asciidoctor/converter/html5.rb +69 -46
- data/lib/asciidoctor/converter/manpage.rb +68 -49
- data/lib/asciidoctor/converter/template.rb +3 -0
- data/lib/asciidoctor/document.rb +43 -50
- data/lib/asciidoctor/extensions.rb +2 -4
- data/lib/asciidoctor/helpers.rb +20 -15
- data/lib/asciidoctor/load.rb +102 -101
- data/lib/asciidoctor/parser.rb +40 -32
- data/lib/asciidoctor/path_resolver.rb +14 -12
- data/lib/asciidoctor/reader.rb +22 -13
- data/lib/asciidoctor/rx.rb +7 -6
- data/lib/asciidoctor/substitutors.rb +78 -57
- data/lib/asciidoctor/syntax_highlighter.rb +8 -5
- data/lib/asciidoctor/syntax_highlighter/coderay.rb +1 -1
- data/lib/asciidoctor/syntax_highlighter/highlightjs.rb +12 -4
- data/lib/asciidoctor/syntax_highlighter/prettify.rb +7 -4
- data/lib/asciidoctor/syntax_highlighter/pygments.rb +6 -7
- data/lib/asciidoctor/syntax_highlighter/rouge.rb +33 -19
- data/lib/asciidoctor/table.rb +52 -23
- data/lib/asciidoctor/version.rb +1 -1
- data/man/asciidoctor.1 +8 -8
- data/man/asciidoctor.adoc +4 -4
- metadata +16 -15
data/lib/asciidoctor/convert.rb
CHANGED
@@ -1,193 +1,198 @@
|
|
1
1
|
module Asciidoctor
|
2
|
-
|
2
|
+
class << self
|
3
|
+
# Public: Parse the AsciiDoc source input into an Asciidoctor::Document and
|
4
|
+
# convert it to the specified backend format.
|
5
|
+
#
|
6
|
+
# Accepts input as an IO (or StringIO), String or String Array object. If the
|
7
|
+
# input is a File, the object is expected to be opened for reading and is not
|
8
|
+
# closed afterwards by this method. Information about the file (filename,
|
9
|
+
# directory name, etc) gets assigned to attributes on the Document object.
|
10
|
+
#
|
11
|
+
# If the :to_file option is true, and the input is a File, the output is
|
12
|
+
# written to a file adjacent to the input file, having an extension that
|
13
|
+
# corresponds to the backend format. Otherwise, if the :to_file option is
|
14
|
+
# specified, the file is written to that file. If :to_file is not an absolute
|
15
|
+
# path, it is resolved relative to :to_dir, if given, otherwise the
|
16
|
+
# Document#base_dir. If the target directory does not exist, it will not be
|
17
|
+
# created unless the :mkdirs option is set to true. If the file cannot be
|
18
|
+
# written because the target directory does not exist, or because it falls
|
19
|
+
# outside of the Document#base_dir in safe mode, an IOError is raised.
|
20
|
+
#
|
21
|
+
# If the output is going to be written to a file, the header and footer are
|
22
|
+
# included unless specified otherwise (writing to a file implies creating a
|
23
|
+
# standalone document). Otherwise, the header and footer are not included by
|
24
|
+
# default and the converted result is returned.
|
25
|
+
#
|
26
|
+
# input - the String AsciiDoc source filename
|
27
|
+
# options - a String, Array or Hash of options to control processing (default: {})
|
28
|
+
# String and Array values are converted into a Hash.
|
29
|
+
# See Asciidoctor::Document#initialize for details about options.
|
30
|
+
#
|
31
|
+
# Returns the Document object if the converted String is written to a
|
32
|
+
# file, otherwise the converted String
|
33
|
+
def convert input, options = {}
|
34
|
+
(options = options.merge).delete :parse
|
35
|
+
to_dir = options.delete :to_dir
|
36
|
+
mkdirs = options.delete :mkdirs
|
3
37
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# path, it is resolved relative to :to_dir, if given, otherwise the
|
17
|
-
# Document#base_dir. If the target directory does not exist, it will not be
|
18
|
-
# created unless the :mkdirs option is set to true. If the file cannot be
|
19
|
-
# written because the target directory does not exist, or because it falls
|
20
|
-
# outside of the Document#base_dir in safe mode, an IOError is raised.
|
21
|
-
#
|
22
|
-
# If the output is going to be written to a file, the header and footer are
|
23
|
-
# included unless specified otherwise (writing to a file implies creating a
|
24
|
-
# standalone document). Otherwise, the header and footer are not included by
|
25
|
-
# default and the converted result is returned.
|
26
|
-
#
|
27
|
-
# input - the String AsciiDoc source filename
|
28
|
-
# options - a String, Array or Hash of options to control processing (default: {})
|
29
|
-
# String and Array values are converted into a Hash.
|
30
|
-
# See Asciidoctor::Document#initialize for details about options.
|
31
|
-
#
|
32
|
-
# Returns the Document object if the converted String is written to a
|
33
|
-
# file, otherwise the converted String
|
34
|
-
def convert input, options = {}
|
35
|
-
(options = options.merge).delete :parse
|
36
|
-
to_dir = options.delete :to_dir
|
37
|
-
mkdirs = options.delete :mkdirs
|
38
|
-
|
39
|
-
case (to_file = options.delete :to_file)
|
40
|
-
when true, nil
|
41
|
-
unless (write_to_target = to_dir)
|
42
|
-
sibling_path = ::File.absolute_path input.path if ::File === input
|
38
|
+
case (to_file = options.delete :to_file)
|
39
|
+
when true, nil
|
40
|
+
unless (write_to_target = to_dir)
|
41
|
+
sibling_path = ::File.absolute_path input.path if ::File === input
|
42
|
+
end
|
43
|
+
to_file = nil
|
44
|
+
when false
|
45
|
+
to_file = nil
|
46
|
+
when '/dev/null'
|
47
|
+
return load input, options
|
48
|
+
else
|
49
|
+
options[:to_file] = write_to_target = to_file unless (stream_output = to_file.respond_to? :write)
|
43
50
|
end
|
44
|
-
to_file = nil
|
45
|
-
when false
|
46
|
-
to_file = nil
|
47
|
-
when '/dev/null'
|
48
|
-
return load input, options
|
49
|
-
else
|
50
|
-
options[:to_file] = write_to_target = to_file unless (stream_output = to_file.respond_to? :write)
|
51
|
-
end
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
unless options.key? :standalone
|
53
|
+
if sibling_path || write_to_target
|
54
|
+
options[:standalone] = options.fetch :header_footer, true
|
55
|
+
elsif options.key? :header_footer
|
56
|
+
options[:standalone] = options[:header_footer]
|
57
|
+
end
|
58
58
|
end
|
59
|
-
end
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
60
|
+
# NOTE outfile may be controlled by document attributes, so resolve outfile after loading
|
61
|
+
if sibling_path
|
62
|
+
options[:to_dir] = outdir = ::File.dirname sibling_path
|
63
|
+
elsif write_to_target
|
64
|
+
if to_dir
|
65
|
+
if to_file
|
66
|
+
options[:to_dir] = ::File.dirname ::File.expand_path to_file, to_dir
|
67
|
+
else
|
68
|
+
options[:to_dir] = ::File.expand_path to_dir
|
69
|
+
end
|
70
|
+
elsif to_file
|
71
|
+
options[:to_dir] = ::File.dirname ::File.expand_path to_file
|
70
72
|
end
|
71
|
-
elsif to_file
|
72
|
-
options[:to_dir] = ::File.dirname ::File.expand_path to_file
|
73
73
|
end
|
74
|
-
end
|
75
74
|
|
76
|
-
|
77
|
-
|
78
|
-
|
75
|
+
# NOTE :to_dir is always set when outputting to a file
|
76
|
+
# NOTE :to_file option only passed if assigned an explicit path
|
77
|
+
doc = load input, options
|
79
78
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
79
|
+
if sibling_path # write to file in same directory
|
80
|
+
outfile = ::File.join outdir, %(#{doc.attributes['docname']}#{doc.outfilesuffix})
|
81
|
+
raise ::IOError, %(input file and output file cannot be the same: #{outfile}) if outfile == sibling_path
|
82
|
+
elsif write_to_target # write to explicit file or directory
|
83
|
+
working_dir = (options.key? :base_dir) ? (::File.expand_path options[:base_dir]) : ::Dir.pwd
|
84
|
+
# QUESTION should the jail be the working_dir or doc.base_dir???
|
85
|
+
jail = doc.safe >= SafeMode::SAFE ? working_dir : nil
|
86
|
+
if to_dir
|
87
|
+
outdir = doc.normalize_system_path(to_dir, working_dir, jail, target_name: 'to_dir', recover: false)
|
88
|
+
if to_file
|
89
|
+
outfile = doc.normalize_system_path(to_file, outdir, nil, target_name: 'to_dir', recover: false)
|
90
|
+
# reestablish outdir as the final target directory (in the case to_file had directory segments)
|
91
|
+
outdir = ::File.dirname outfile
|
92
|
+
else
|
93
|
+
outfile = ::File.join outdir, %(#{doc.attributes['docname']}#{doc.outfilesuffix})
|
94
|
+
end
|
95
|
+
elsif to_file
|
96
|
+
outfile = doc.normalize_system_path(to_file, working_dir, jail, target_name: 'to_dir', recover: false)
|
97
|
+
# establish outdir as the final target directory (in the case to_file had directory segments)
|
92
98
|
outdir = ::File.dirname outfile
|
93
|
-
else
|
94
|
-
outfile = ::File.join outdir, %(#{doc.attributes['docname']}#{doc.outfilesuffix})
|
95
99
|
end
|
96
|
-
elsif to_file
|
97
|
-
outfile = doc.normalize_system_path(to_file, working_dir, jail, target_name: 'to_dir', recover: false)
|
98
|
-
# establish outdir as the final target directory (in the case to_file had directory segments)
|
99
|
-
outdir = ::File.dirname outfile
|
100
|
-
end
|
101
100
|
|
102
|
-
|
103
|
-
|
101
|
+
if ::File === input && outfile == (::File.absolute_path input.path)
|
102
|
+
raise ::IOError, %(input file and output file cannot be the same: #{outfile})
|
103
|
+
end
|
104
|
+
|
105
|
+
if mkdirs
|
106
|
+
Helpers.mkdir_p outdir
|
107
|
+
else
|
108
|
+
# NOTE we intentionally refer to the directory as it was passed to the API
|
109
|
+
raise ::IOError, %(target directory does not exist: #{to_dir} (hint: set :mkdirs option)) unless ::File.directory? outdir
|
110
|
+
end
|
111
|
+
else # write to stream
|
112
|
+
outfile = to_file
|
113
|
+
outdir = nil
|
104
114
|
end
|
105
115
|
|
106
|
-
if
|
107
|
-
|
116
|
+
if outfile && !stream_output
|
117
|
+
output = doc.convert 'outfile' => outfile, 'outdir' => outdir
|
108
118
|
else
|
109
|
-
|
110
|
-
raise ::IOError, %(target directory does not exist: #{to_dir} (hint: set :mkdirs option)) unless ::File.directory? outdir
|
119
|
+
output = doc.convert
|
111
120
|
end
|
112
|
-
else # write to stream
|
113
|
-
outfile = to_file
|
114
|
-
outdir = nil
|
115
|
-
end
|
116
|
-
|
117
|
-
if outfile && !stream_output
|
118
|
-
output = doc.convert 'outfile' => outfile, 'outdir' => outdir
|
119
|
-
else
|
120
|
-
output = doc.convert
|
121
|
-
end
|
122
121
|
|
123
|
-
|
124
|
-
|
122
|
+
if outfile
|
123
|
+
doc.write output, outfile
|
125
124
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
end
|
137
|
-
copy_syntax_hl_stylesheet = (syntax_hl = doc.syntax_highlighter) && (syntax_hl.write_stylesheet? doc)
|
138
|
-
if copy_asciidoctor_stylesheet || copy_user_stylesheet || copy_syntax_hl_stylesheet
|
139
|
-
stylesoutdir = doc.normalize_system_path(stylesdir, outdir, doc.safe >= SafeMode::SAFE ? outdir : nil)
|
140
|
-
if mkdirs
|
141
|
-
Helpers.mkdir_p stylesoutdir
|
142
|
-
else
|
143
|
-
raise ::IOError, %(target stylesheet directory does not exist: #{stylesoutdir} (hint: set :mkdirs option)) unless ::File.directory? stylesoutdir
|
125
|
+
# NOTE document cannot control this behavior if safe >= SafeMode::SERVER
|
126
|
+
# NOTE skip if stylesdir is a URI
|
127
|
+
if !stream_output && doc.safe < SafeMode::SECURE && (doc.attr? 'linkcss') && (doc.attr? 'copycss') &&
|
128
|
+
(doc.basebackend? 'html') && !((stylesdir = (doc.attr 'stylesdir')) && (Helpers.uriish? stylesdir))
|
129
|
+
if (stylesheet = doc.attr 'stylesheet')
|
130
|
+
if DEFAULT_STYLESHEET_KEYS.include? stylesheet
|
131
|
+
copy_asciidoctor_stylesheet = true
|
132
|
+
elsif !(Helpers.uriish? stylesheet)
|
133
|
+
copy_user_stylesheet = true
|
134
|
+
end
|
144
135
|
end
|
145
|
-
|
146
|
-
if copy_asciidoctor_stylesheet
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
if (stylesheet_src = doc.attr 'copycss').empty?
|
151
|
-
stylesheet_src = doc.normalize_system_path stylesheet
|
136
|
+
copy_syntax_hl_stylesheet = (syntax_hl = doc.syntax_highlighter) && (syntax_hl.write_stylesheet? doc)
|
137
|
+
if copy_asciidoctor_stylesheet || copy_user_stylesheet || copy_syntax_hl_stylesheet
|
138
|
+
stylesoutdir = doc.normalize_system_path(stylesdir, outdir, doc.safe >= SafeMode::SAFE ? outdir : nil)
|
139
|
+
if mkdirs
|
140
|
+
Helpers.mkdir_p stylesoutdir
|
152
141
|
else
|
153
|
-
|
154
|
-
stylesheet_src = doc.normalize_system_path stylesheet_src
|
142
|
+
raise ::IOError, %(target stylesheet directory does not exist: #{stylesoutdir} (hint: set :mkdirs option)) unless ::File.directory? stylesoutdir
|
155
143
|
end
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
144
|
+
|
145
|
+
if copy_asciidoctor_stylesheet
|
146
|
+
Stylesheets.instance.write_primary_stylesheet stylesoutdir
|
147
|
+
# FIXME should Stylesheets also handle the user stylesheet?
|
148
|
+
elsif copy_user_stylesheet
|
149
|
+
if (stylesheet_src = doc.attr 'copycss') == '' || stylesheet_src == true
|
150
|
+
stylesheet_src = doc.normalize_system_path stylesheet
|
151
|
+
else
|
152
|
+
# NOTE in this case, copycss is a source location (but cannot be a URI)
|
153
|
+
stylesheet_src = doc.normalize_system_path stylesheet_src.to_s
|
154
|
+
end
|
155
|
+
stylesheet_dest = doc.normalize_system_path stylesheet, stylesoutdir, (doc.safe >= SafeMode::SAFE ? outdir : nil)
|
156
|
+
# NOTE don't warn if src can't be read and dest already exists (see #2323)
|
157
|
+
if stylesheet_src != stylesheet_dest && (stylesheet_data = doc.read_asset stylesheet_src,
|
158
|
+
warn_on_failure: !(::File.file? stylesheet_dest), label: 'stylesheet')
|
159
|
+
if (stylesheet_outdir = ::File.dirname stylesheet_dest) != stylesoutdir && !(::File.directory? stylesheet_outdir)
|
160
|
+
if mkdirs
|
161
|
+
Helpers.mkdir_p stylesheet_outdir
|
162
|
+
else
|
163
|
+
raise ::IOError, %(target stylesheet directory does not exist: #{stylesheet_outdir} (hint: set :mkdirs option))
|
164
|
+
end
|
165
|
+
end
|
166
|
+
::File.write stylesheet_dest, stylesheet_data, mode: FILE_WRITE_MODE
|
167
|
+
end
|
161
168
|
end
|
169
|
+
syntax_hl.write_stylesheet doc, stylesoutdir if copy_syntax_hl_stylesheet
|
162
170
|
end
|
163
|
-
syntax_hl.write_stylesheet doc, stylesoutdir if copy_syntax_hl_stylesheet
|
164
171
|
end
|
172
|
+
doc
|
173
|
+
else
|
174
|
+
output
|
165
175
|
end
|
166
|
-
doc
|
167
|
-
else
|
168
|
-
output
|
169
176
|
end
|
170
|
-
end
|
171
177
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
178
|
+
# Public: Parse the contents of the AsciiDoc source file into an
|
179
|
+
# Asciidoctor::Document and convert it to the specified backend format.
|
180
|
+
#
|
181
|
+
# input - the String AsciiDoc source filename
|
182
|
+
# options - a String, Array or Hash of options to control processing (default: {})
|
183
|
+
# String and Array values are converted into a Hash.
|
184
|
+
# See Asciidoctor::Document#initialize for details about options.
|
185
|
+
#
|
186
|
+
# Returns the Document object if the converted String is written to a
|
187
|
+
# file, otherwise the converted String
|
188
|
+
def convert_file filename, options = {}
|
189
|
+
::File.open(filename, FILE_READ_MODE) {|file| convert file, options }
|
190
|
+
end
|
185
191
|
|
186
|
-
|
187
|
-
|
188
|
-
module_function :render
|
192
|
+
# Deprecated: Use {Asciidoctor.convert} instead.
|
193
|
+
alias render convert
|
189
194
|
|
190
|
-
|
191
|
-
|
192
|
-
|
195
|
+
# Deprecated: Use {Asciidoctor.convert_file} instead.
|
196
|
+
alias render_file convert_file
|
197
|
+
end
|
193
198
|
end
|
@@ -85,23 +85,24 @@ module Converter
|
|
85
85
|
# Public: Derive backend traits (basebackend, filetype, outfilesuffix, htmlsyntax) from the given backend.
|
86
86
|
#
|
87
87
|
# backend - the String backend from which to derive the traits
|
88
|
+
# basebackend - the String basebackend to use in favor of deriving one from the backend (optional, default: nil)
|
88
89
|
#
|
89
90
|
# Returns the backend traits for the given backend as a [Hash].
|
90
|
-
def self.derive_backend_traits backend
|
91
|
+
def self.derive_backend_traits backend, basebackend = nil
|
91
92
|
return {} unless backend
|
92
|
-
if (
|
93
|
-
|
93
|
+
if (outfilesuffix = DEFAULT_EXTENSIONS[(basebackend ||= backend.sub TrailingDigitsRx, '')])
|
94
|
+
filetype = outfilesuffix.slice 1, outfilesuffix.length
|
94
95
|
else
|
95
|
-
|
96
|
+
outfilesuffix = %(.#{filetype = basebackend})
|
96
97
|
end
|
97
|
-
|
98
|
-
{ basebackend:
|
99
|
-
{ basebackend:
|
98
|
+
filetype == 'html' ?
|
99
|
+
{ basebackend: basebackend, filetype: filetype, htmlsyntax: 'html', outfilesuffix: outfilesuffix } :
|
100
|
+
{ basebackend: basebackend, filetype: filetype, outfilesuffix: outfilesuffix }
|
100
101
|
end
|
101
102
|
|
102
103
|
module BackendTraits
|
103
104
|
def basebackend value = nil
|
104
|
-
value ? (backend_traits[:basebackend] = value) : backend_traits[:basebackend]
|
105
|
+
value ? ((backend_traits value)[:basebackend] = value) : backend_traits[:basebackend]
|
105
106
|
end
|
106
107
|
|
107
108
|
def filetype value = nil
|
@@ -128,15 +129,15 @@ module Converter
|
|
128
129
|
@backend_traits = value || {}
|
129
130
|
end
|
130
131
|
|
131
|
-
def backend_traits
|
132
|
-
@backend_traits ||= Converter.derive_backend_traits @backend
|
132
|
+
def backend_traits basebackend = nil
|
133
|
+
@backend_traits ||= Converter.derive_backend_traits @backend, basebackend
|
133
134
|
end
|
134
135
|
|
135
136
|
alias backend_info backend_traits
|
136
137
|
|
137
138
|
# Deprecated: Use {Converter.derive_backend_traits} instead.
|
138
|
-
def self.derive_backend_traits backend
|
139
|
-
Converter.derive_backend_traits backend
|
139
|
+
def self.derive_backend_traits backend, basebackend = nil
|
140
|
+
Converter.derive_backend_traits backend, basebackend
|
140
141
|
end
|
141
142
|
end
|
142
143
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Asciidoctor
|
3
3
|
# A built-in {Converter} implementation that generates DocBook 5 output. The output is inspired by the output produced
|
4
|
-
# by the docbook45 backend from AsciiDoc
|
4
|
+
# by the docbook45 backend from AsciiDoc.py, except it has been migrated to the DocBook 5 specification.
|
5
5
|
class Converter::DocBook5Converter < Converter::Base
|
6
6
|
register_for 'docbook5'
|
7
7
|
|
@@ -41,7 +41,8 @@ class Converter::DocBook5Converter < Converter::Base
|
|
41
41
|
if (root_tag_name = node.doctype) == 'manpage'
|
42
42
|
root_tag_name = 'refentry'
|
43
43
|
end
|
44
|
-
|
44
|
+
root_tag_idx = result.size
|
45
|
+
id = node.id
|
45
46
|
result << (document_info_tag node) unless node.noheader
|
46
47
|
unless (docinfo_content = node.docinfo :header).empty?
|
47
48
|
result << docinfo_content
|
@@ -50,6 +51,9 @@ class Converter::DocBook5Converter < Converter::Base
|
|
50
51
|
unless (docinfo_content = node.docinfo :footer).empty?
|
51
52
|
result << docinfo_content
|
52
53
|
end
|
54
|
+
id, node.id = node.id, nil unless id
|
55
|
+
# defer adding root tag in case document ID is auto-generated on demand
|
56
|
+
result.insert root_tag_idx, %(<#{root_tag_name} xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0"#{lang_attribute}#{common_attributes id}>)
|
53
57
|
result << %(</#{root_tag_name}>)
|
54
58
|
result.join LF
|
55
59
|
end
|
@@ -371,9 +375,7 @@ class Converter::DocBook5Converter < Converter::Base
|
|
371
375
|
has_body = false
|
372
376
|
result = []
|
373
377
|
pgwide_attribute = (node.option? 'pgwide') ? ' pgwide="1"' : ''
|
374
|
-
if (frame = node.attr 'frame', 'all', 'table-frame') == 'ends'
|
375
|
-
frame = 'topbot'
|
376
|
-
end
|
378
|
+
frame = 'topbot' if (frame = node.attr 'frame', 'all', 'table-frame') == 'ends'
|
377
379
|
grid = node.attr 'grid', nil, 'table-grid'
|
378
380
|
result << %(<#{tag_name = node.title? ? 'table' : 'informaltable'}#{common_attributes node.id, node.role, node.reftext}#{pgwide_attribute} frame="#{frame}" rowsep="#{['none', 'cols'].include?(grid) ? 0 : 1}" colsep="#{['none', 'rows'].include?(grid) ? 0 : 1}"#{(node.attr? 'orientation', 'landscape', 'table-orientation') ? ' orient="land"' : ''}>)
|
379
381
|
if (node.option? 'unbreakable')
|
@@ -401,12 +403,10 @@ class Converter::DocBook5Converter < Converter::Base
|
|
401
403
|
rows.each do |row|
|
402
404
|
result << '<row>'
|
403
405
|
row.each do |cell|
|
404
|
-
halign_attribute = (cell.attr? 'halign') ? %( align="#{cell.attr 'halign'}") : ''
|
405
|
-
valign_attribute = (cell.attr? 'valign') ? %( valign="#{cell.attr 'valign'}") : ''
|
406
406
|
colspan_attribute = cell.colspan ? %( namest="col_#{colnum = cell.column.attr 'colnumber'}" nameend="col_#{colnum + cell.colspan - 1}") : ''
|
407
407
|
rowspan_attribute = cell.rowspan ? %( morerows="#{cell.rowspan - 1}") : ''
|
408
408
|
# NOTE <entry> may not have whitespace (e.g., line breaks) as a direct descendant according to DocBook rules
|
409
|
-
entry_start = %(<entry#{
|
409
|
+
entry_start = %(<entry align="#{cell.attr 'halign'}" valign="#{cell.attr 'valign'}"#{colspan_attribute}#{rowspan_attribute}>)
|
410
410
|
if tsec == :head
|
411
411
|
cell_content = cell.text
|
412
412
|
else
|
@@ -478,16 +478,22 @@ class Converter::DocBook5Converter < Converter::Base
|
|
478
478
|
%(<anchor#{common_attributes((id = node.id), nil, node.reftext || %([#{id}]))}/>)
|
479
479
|
when :xref
|
480
480
|
if (path = node.attributes['path'])
|
481
|
-
# QUESTION should we use refid as fallback text instead? (like the html5 backend?)
|
482
481
|
%(<link xl:href="#{node.target}">#{node.text || path}</link>)
|
483
482
|
else
|
484
|
-
linkend = node.attributes['
|
483
|
+
if (linkend = node.attributes['refid']).nil_or_empty?
|
484
|
+
root_doc = get_root_document node
|
485
|
+
# Q: should we warn instead of generating a document ID on demand?
|
486
|
+
linkend = (root_doc.id ||= generate_document_id root_doc)
|
487
|
+
end
|
488
|
+
# NOTE the xref tag in DocBook does not support explicit link text, so the link tag must be used instead
|
489
|
+
# The section at http://www.sagehill.net/docbookxsl/CrossRefs.html#IdrefLinks gives an explanation for this choice
|
490
|
+
# "link - a cross reference where you supply the text of the reference as the content of the link element."
|
485
491
|
(text = node.text) ? %(<link linkend="#{linkend}">#{text}</link>) : %(<xref linkend="#{linkend}"/>)
|
486
492
|
end
|
487
493
|
when :link
|
488
494
|
%(<link xl:href="#{node.target}">#{node.text}</link>)
|
489
495
|
when :bibref
|
490
|
-
%(<anchor#{common_attributes node.id, nil, "[#{node.reftext || node.id}]"}/>#{text})
|
496
|
+
%(<anchor#{common_attributes node.id, nil, (text = "[#{node.reftext || node.id}]")}/>#{text})
|
491
497
|
else
|
492
498
|
logger.warn %(unknown anchor type: #{node.type.inspect})
|
493
499
|
nil
|
@@ -517,7 +523,7 @@ class Converter::DocBook5Converter < Converter::Base
|
|
517
523
|
def convert_inline_image node
|
518
524
|
width_attribute = (node.attr? 'width') ? %( contentwidth="#{node.attr 'width'}") : ''
|
519
525
|
depth_attribute = (node.attr? 'height') ? %( contentdepth="#{node.attr 'height'}") : ''
|
520
|
-
%(<inlinemediaobject>
|
526
|
+
%(<inlinemediaobject#{common_attributes nil, node.role}>
|
521
527
|
<imageobject>
|
522
528
|
<imagedata fileref="#{node.type == 'icon' ? (node.icon_uri node.target) : (node.image_uri node.target)}"#{width_attribute}#{depth_attribute}/>
|
523
529
|
</imageobject>
|
@@ -714,6 +720,17 @@ class Converter::DocBook5Converter < Converter::Base
|
|
714
720
|
result.join LF
|
715
721
|
end
|
716
722
|
|
723
|
+
def get_root_document node
|
724
|
+
while (node = node.document).nested?
|
725
|
+
node = node.parent_document
|
726
|
+
end
|
727
|
+
node
|
728
|
+
end
|
729
|
+
|
730
|
+
def generate_document_id doc
|
731
|
+
%(__#{doc.doctype}-root__)
|
732
|
+
end
|
733
|
+
|
717
734
|
# FIXME this should be handled through a template mechanism
|
718
735
|
def enclose_content node
|
719
736
|
node.content_model == :compound ? node.content : %(<simpara>#{node.content}</simpara>)
|