asciidoctor 1.5.8 → 2.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +11 -0
- data/CHANGELOG.adoc +628 -45
- data/LICENSE +2 -1
- data/README-de.adoc +28 -38
- data/README-fr.adoc +30 -43
- data/README-jp.adoc +255 -201
- data/README-zh_CN.adoc +40 -44
- data/README.adoc +170 -143
- data/asciidoctor.gemspec +22 -34
- data/bin/asciidoctor +5 -4
- 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 +6 -5
- 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 +8 -7
- 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-th.adoc +23 -0
- data/data/locale/attributes-tr.adoc +4 -3
- data/data/locale/attributes-uk.adoc +6 -5
- data/data/locale/attributes-vi.adoc +23 -0
- data/data/locale/attributes-zh_CN.adoc +4 -3
- data/data/locale/attributes-zh_TW.adoc +4 -3
- data/data/reference/syntax.adoc +296 -0
- data/data/stylesheets/asciidoctor-default.css +120 -114
- data/data/stylesheets/coderay-asciidoctor.css +15 -17
- data/lib/asciidoctor/abstract_block.rb +146 -140
- data/lib/asciidoctor/abstract_node.rb +152 -170
- data/lib/asciidoctor/attribute_list.rb +77 -89
- data/lib/asciidoctor/block.rb +29 -28
- data/lib/asciidoctor/callouts.rb +4 -2
- data/lib/asciidoctor/cli/invoker.rb +20 -24
- data/lib/asciidoctor/cli/options.rb +107 -96
- data/lib/asciidoctor/cli.rb +3 -2
- data/lib/asciidoctor/convert.rb +199 -0
- data/lib/asciidoctor/converter/composite.rb +40 -48
- data/lib/asciidoctor/converter/docbook5.rb +627 -644
- data/lib/asciidoctor/converter/html5.rb +1053 -951
- data/lib/asciidoctor/converter/manpage.rb +581 -532
- data/lib/asciidoctor/converter/template.rb +232 -271
- data/lib/asciidoctor/converter.rb +370 -185
- data/lib/asciidoctor/core_ext/float/truncate.rb +20 -0
- data/lib/asciidoctor/core_ext/hash/merge.rb +8 -0
- data/lib/asciidoctor/core_ext/match_data/names.rb +7 -0
- data/lib/asciidoctor/core_ext/nil_or_empty.rb +1 -0
- data/lib/asciidoctor/core_ext/regexp/is_match.rb +4 -2
- data/lib/asciidoctor/core_ext.rb +8 -17
- data/lib/asciidoctor/document.rb +503 -461
- data/lib/asciidoctor/extensions.rb +127 -174
- data/lib/asciidoctor/helpers.rb +184 -107
- data/lib/asciidoctor/inline.rb +9 -12
- data/lib/asciidoctor/list.rb +11 -29
- data/lib/asciidoctor/load.rb +119 -0
- data/lib/asciidoctor/logging.rb +22 -17
- data/lib/asciidoctor/parser.rb +673 -719
- data/lib/asciidoctor/path_resolver.rb +48 -33
- data/lib/asciidoctor/reader.rb +383 -338
- data/lib/asciidoctor/rouge_ext.rb +39 -0
- data/lib/asciidoctor/rx.rb +723 -0
- data/lib/asciidoctor/section.rb +17 -16
- data/lib/asciidoctor/stylesheets.rb +19 -37
- data/lib/asciidoctor/substitutors.rb +926 -1022
- data/lib/asciidoctor/syntax_highlighter/coderay.rb +88 -0
- data/lib/asciidoctor/syntax_highlighter/highlightjs.rb +34 -0
- data/lib/asciidoctor/syntax_highlighter/html_pipeline.rb +10 -0
- data/lib/asciidoctor/syntax_highlighter/prettify.rb +30 -0
- data/lib/asciidoctor/syntax_highlighter/pygments.rb +157 -0
- data/lib/asciidoctor/syntax_highlighter/rouge.rb +143 -0
- data/lib/asciidoctor/syntax_highlighter.rb +253 -0
- data/lib/asciidoctor/table.rb +152 -114
- data/lib/asciidoctor/timings.rb +7 -5
- data/lib/asciidoctor/version.rb +2 -1
- data/lib/asciidoctor/writer.rb +30 -0
- data/lib/asciidoctor.rb +266 -1340
- data/man/asciidoctor.1 +49 -47
- data/man/asciidoctor.adoc +54 -45
- metadata +50 -245
- data/CONTRIBUTING.adoc +0 -185
- data/Gemfile +0 -60
- data/Rakefile +0 -129
- data/bin/asciidoctor-safe +0 -15
- data/features/open_block.feature +0 -92
- data/features/pass_block.feature +0 -66
- data/features/step_definitions.rb +0 -49
- data/features/text_formatting.feature +0 -57
- data/features/xref.feature +0 -1039
- data/lib/asciidoctor/converter/base.rb +0 -59
- data/lib/asciidoctor/converter/docbook45.rb +0 -93
- data/lib/asciidoctor/converter/factory.rb +0 -226
- data/lib/asciidoctor/core_ext/1.8.7/base64/strict_encode64.rb +0 -6
- data/lib/asciidoctor/core_ext/1.8.7/concurrent/hash.rb +0 -5
- data/lib/asciidoctor/core_ext/1.8.7/hash/key.rb +0 -4
- data/lib/asciidoctor/core_ext/1.8.7/io/binread.rb +0 -6
- data/lib/asciidoctor/core_ext/1.8.7/io/write.rb +0 -5
- data/lib/asciidoctor/core_ext/1.8.7/string/chr.rb +0 -6
- data/lib/asciidoctor/core_ext/1.8.7/string/limit_bytesize.rb +0 -29
- data/lib/asciidoctor/core_ext/1.8.7/symbol/empty.rb +0 -6
- data/lib/asciidoctor/core_ext/1.8.7/symbol/length.rb +0 -6
- data/lib/asciidoctor/core_ext/string/limit_bytesize.rb +0 -10
- data/test/api_test.rb +0 -1240
- data/test/attribute_list_test.rb +0 -242
- data/test/attributes_test.rb +0 -1623
- data/test/blocks_test.rb +0 -3870
- data/test/converter_test.rb +0 -470
- data/test/document_test.rb +0 -1853
- data/test/extensions_test.rb +0 -1560
- data/test/fixtures/asciidoc_index.txt +0 -521
- data/test/fixtures/basic-docinfo-footer.html +0 -6
- data/test/fixtures/basic-docinfo-footer.xml +0 -8
- data/test/fixtures/basic-docinfo.html +0 -1
- data/test/fixtures/basic-docinfo.xml +0 -4
- data/test/fixtures/basic.asciidoc +0 -5
- data/test/fixtures/chapter-a.adoc +0 -3
- data/test/fixtures/child-include.adoc +0 -5
- data/test/fixtures/circle.svg +0 -9
- data/test/fixtures/custom-backends/erb/html5/block_paragraph.html.erb +0 -6
- data/test/fixtures/custom-backends/haml/docbook45/block_paragraph.xml.haml +0 -6
- data/test/fixtures/custom-backends/haml/html5/block_paragraph.html.haml +0 -3
- data/test/fixtures/custom-backends/haml/html5/block_sidebar.html.haml +0 -5
- data/test/fixtures/custom-backends/haml/html5-tweaks/block_paragraph.html.haml +0 -1
- data/test/fixtures/custom-backends/slim/docbook45/block_paragraph.xml.slim +0 -6
- data/test/fixtures/custom-backends/slim/html5/block_paragraph.html.slim +0 -3
- data/test/fixtures/custom-backends/slim/html5/block_sidebar.html.slim +0 -5
- data/test/fixtures/custom-docinfodir/basic-docinfo.html +0 -1
- data/test/fixtures/custom-docinfodir/docinfo.html +0 -1
- data/test/fixtures/docinfo-footer.html +0 -1
- data/test/fixtures/docinfo-footer.xml +0 -9
- data/test/fixtures/docinfo.html +0 -1
- data/test/fixtures/docinfo.xml +0 -3
- data/test/fixtures/doctime-localtime.adoc +0 -2
- data/test/fixtures/dot.gif +0 -0
- data/test/fixtures/encoding.asciidoc +0 -13
- data/test/fixtures/file-with-missing-include.adoc +0 -1
- data/test/fixtures/grandchild-include.adoc +0 -3
- data/test/fixtures/hello-asciidoctor.pdf +0 -69
- data/test/fixtures/include-file.asciidoc +0 -24
- data/test/fixtures/include-file.jsx +0 -8
- data/test/fixtures/include-file.ml +0 -3
- data/test/fixtures/include-file.xml +0 -5
- data/test/fixtures/lists.adoc +0 -96
- data/test/fixtures/master.adoc +0 -5
- data/test/fixtures/mismatched-end-tag.adoc +0 -7
- data/test/fixtures/other-chapters.adoc +0 -11
- data/test/fixtures/outer-include.adoc +0 -5
- data/test/fixtures/parent-include-restricted.adoc +0 -5
- data/test/fixtures/parent-include.adoc +0 -5
- data/test/fixtures/sample.asciidoc +0 -30
- data/test/fixtures/section-a.adoc +0 -4
- data/test/fixtures/stylesheets/custom.css +0 -3
- data/test/fixtures/subdir/index.adoc +0 -3
- data/test/fixtures/subdir/inner-include.adoc +0 -3
- data/test/fixtures/subdir/middle-include.adoc +0 -5
- data/test/fixtures/subs-docinfo.html +0 -2
- data/test/fixtures/subs.adoc +0 -6
- data/test/fixtures/tagged-class-enclosed.rb +0 -25
- data/test/fixtures/tagged-class.rb +0 -23
- data/test/fixtures/tip.gif +0 -0
- data/test/fixtures/unclosed-tag.adoc +0 -3
- data/test/fixtures/unexpected-end-tag.adoc +0 -4
- data/test/invoker_test.rb +0 -745
- data/test/links_test.rb +0 -855
- data/test/lists_test.rb +0 -5151
- data/test/logger_test.rb +0 -211
- data/test/manpage_test.rb +0 -660
- data/test/options_test.rb +0 -262
- data/test/paragraphs_test.rb +0 -562
- data/test/parser_test.rb +0 -742
- data/test/paths_test.rb +0 -395
- data/test/preamble_test.rb +0 -173
- data/test/reader_test.rb +0 -2161
- data/test/sections_test.rb +0 -3575
- data/test/substitutions_test.rb +0 -2066
- data/test/tables_test.rb +0 -2036
- data/test/test_helper.rb +0 -447
- data/test/text_test.rb +0 -309
@@ -1,7 +1,6 @@
|
|
1
|
-
#
|
2
|
-
require 'asciidoctor'
|
1
|
+
# frozen_string_literal: true
|
2
|
+
(require 'asciidoctor' unless defined? Asciidoctor.load) unless RUBY_ENGINE == 'opal'
|
3
3
|
|
4
|
-
# encoding: UTF-8
|
5
4
|
module Asciidoctor
|
6
5
|
# Extensions provide a way to participate in the parsing and converting
|
7
6
|
# phases of the AsciiDoc processor or extend the AsciiDoc syntax.
|
@@ -57,27 +56,23 @@ module Extensions
|
|
57
56
|
config[key] = default_value
|
58
57
|
end
|
59
58
|
|
60
|
-
#
|
59
|
+
# Mixes the DSL class for this processor into this processor class or instance.
|
61
60
|
#
|
62
|
-
# This method automatically detects whether to use the include or extend keyword
|
63
|
-
# based on what is appropriate.
|
61
|
+
# This method automatically detects whether to use the include or extend keyword to mix in the module.
|
64
62
|
#
|
65
63
|
# NOTE Inspiration for this DSL design comes from https://corcoran.io/2013/09/04/simple-pattern-ruby-dsl/
|
66
64
|
#
|
67
|
-
# Returns
|
68
|
-
def
|
69
|
-
if
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
#extend const_get :DSL if constants(false).grep :DSL
|
76
|
-
extend const_get :DSL if constants.grep :DSL
|
65
|
+
# Returns self
|
66
|
+
def enable_dsl
|
67
|
+
if const_defined? :DSL
|
68
|
+
if singleton_class?
|
69
|
+
include const_get :DSL
|
70
|
+
else
|
71
|
+
extend const_get :DSL
|
72
|
+
end
|
77
73
|
end
|
78
74
|
end
|
79
|
-
alias
|
80
|
-
alias include_dsl use_dsl
|
75
|
+
alias use_dsl enable_dsl
|
81
76
|
end
|
82
77
|
|
83
78
|
# Public: Get the configuration Hash for this processor instance.
|
@@ -92,7 +87,7 @@ module Extensions
|
|
92
87
|
end
|
93
88
|
|
94
89
|
def process *args
|
95
|
-
raise ::NotImplementedError, %(
|
90
|
+
raise ::NotImplementedError, %(#{Processor} subclass #{self.class} must implement the ##{__method__} method)
|
96
91
|
end
|
97
92
|
|
98
93
|
# QUESTION should attributes be an option instead of a parameter?
|
@@ -139,16 +134,18 @@ module Extensions
|
|
139
134
|
if opts.fetch :numbered, (style == 'appendix')
|
140
135
|
sect.numbered = true
|
141
136
|
elsif !(opts.key? :numbered) && (doc.attr? 'sectnums', 'all')
|
142
|
-
sect.numbered = book && level == 1 ? :chapter : true
|
137
|
+
sect.numbered = (book && level == 1 ? :chapter : true)
|
143
138
|
end
|
144
139
|
elsif level > 0
|
145
140
|
if opts.fetch :numbered, (doc.attr? 'sectnums')
|
146
141
|
sect.numbered = sect.special ? parent.numbered && true : true
|
147
142
|
end
|
148
|
-
|
149
|
-
sect.numbered = true
|
143
|
+
elsif opts.fetch :numbered, (book && (doc.attr? 'partnums'))
|
144
|
+
sect.numbered = true
|
150
145
|
end
|
151
|
-
|
146
|
+
if (id = attrs['id']) == false
|
147
|
+
attrs.delete 'id'
|
148
|
+
else
|
152
149
|
sect.id = attrs['id'] = id || ((doc.attr? 'sectids') ? (Section.generate_id sect.title, doc) : nil)
|
153
150
|
end
|
154
151
|
sect.update_attributes attrs
|
@@ -156,7 +153,7 @@ module Extensions
|
|
156
153
|
end
|
157
154
|
|
158
155
|
def create_block parent, context, source, attrs, opts = {}
|
159
|
-
Block.new parent, context, { :
|
156
|
+
Block.new parent, context, { source: source, attributes: attrs }.merge(opts)
|
160
157
|
end
|
161
158
|
|
162
159
|
# Public: Creates a list node and links it to the specified parent.
|
@@ -200,13 +197,13 @@ module Extensions
|
|
200
197
|
block = create_block parent, :image, nil, attrs, opts
|
201
198
|
if title
|
202
199
|
block.title = title
|
203
|
-
block.assign_caption(
|
200
|
+
block.assign_caption (attrs.delete 'caption'), 'figure'
|
204
201
|
end
|
205
202
|
block
|
206
203
|
end
|
207
204
|
|
208
205
|
def create_inline parent, context, text, opts = {}
|
209
|
-
Inline.new parent, context, text, opts
|
206
|
+
Inline.new parent, context, text, context == :quoted ? ({ type: :unquoted }.merge opts) : opts
|
210
207
|
end
|
211
208
|
|
212
209
|
# Public: Parses blocks in the content and attaches the block to the parent.
|
@@ -216,12 +213,25 @@ module Extensions
|
|
216
213
|
# QUESTION is parse_content the right method name? should we wrap in open block automatically?
|
217
214
|
def parse_content parent, content, attributes = nil
|
218
215
|
reader = Reader === content ? content : (Reader.new content)
|
219
|
-
|
220
|
-
reader.has_more_lines?
|
221
|
-
end
|
216
|
+
Parser.parse_blocks reader, parent, attributes
|
222
217
|
parent
|
223
218
|
end
|
224
219
|
|
220
|
+
# Public: Parses the attrlist String into a Hash of attributes
|
221
|
+
#
|
222
|
+
# block - the current AbstractBlock or the parent AbstractBlock if there is no current block (used for applying subs)
|
223
|
+
# attrlist - the list of attributes as a String
|
224
|
+
# opts - an optional Hash of options to control processing:
|
225
|
+
# :positional_attributes - an Array of attribute names to map positional arguments to (optional, default: false)
|
226
|
+
# :sub_attributes - enables attribute substitution on the attrlist argument (optional, default: false)
|
227
|
+
#
|
228
|
+
# Returns a Hash of parsed attributes
|
229
|
+
def parse_attributes block, attrlist, opts = {}
|
230
|
+
return {} if attrlist ? attrlist.empty? : true
|
231
|
+
attrlist = block.sub_attributes attrlist if opts[:sub_attributes] && (attrlist.include? ATTR_REF_HEAD)
|
232
|
+
(AttributeList.new attrlist).parse opts[:positional_attributes] || []
|
233
|
+
end
|
234
|
+
|
225
235
|
# TODO fill out remaining methods
|
226
236
|
[
|
227
237
|
[:create_paragraph, :create_block, :paragraph],
|
@@ -230,7 +240,8 @@ module Extensions
|
|
230
240
|
[:create_pass_block, :create_block, :pass],
|
231
241
|
[:create_listing_block, :create_block, :listing],
|
232
242
|
[:create_literal_block, :create_block, :literal],
|
233
|
-
[:create_anchor, :create_inline, :anchor]
|
243
|
+
[:create_anchor, :create_inline, :anchor],
|
244
|
+
[:create_inline_pass, :create_inline, :quoted],
|
234
245
|
].each do |method_name, delegate_method_name, context|
|
235
246
|
define_method method_name do |*args|
|
236
247
|
args.unshift args.shift, context
|
@@ -250,20 +261,20 @@ module Extensions
|
|
250
261
|
def process *args, &block
|
251
262
|
if block_given?
|
252
263
|
raise ::ArgumentError, %(wrong number of arguments (given #{args.size}, expected 0)) unless args.empty?
|
264
|
+
unless block.binding && self == block.binding.receiver
|
265
|
+
# NOTE remap self in process method to processor instance
|
266
|
+
context = self
|
267
|
+
block.define_singleton_method(:call) {|*m_args| context.instance_exec(*m_args, &block) }
|
268
|
+
end
|
253
269
|
@process_block = block
|
254
270
|
# TODO enable if we want to support passing proc or lambda as argument instead of block
|
255
271
|
#elsif ::Proc === args[0]
|
256
|
-
#
|
257
|
-
#
|
258
|
-
# @process_block = block
|
272
|
+
# raise ::ArgumentError, %(wrong number of arguments (given #{args.size - 1}, expected 0)) unless args.size == 1
|
273
|
+
# @process_block = args.shift
|
259
274
|
elsif defined? @process_block
|
260
|
-
# NOTE Proc automatically expands a single array argument
|
261
|
-
# ...but lambda doesn't (and we want to accept lambdas too)
|
262
|
-
# TODO need a test for this!
|
263
275
|
@process_block.call(*args)
|
264
276
|
else
|
265
|
-
#
|
266
|
-
raise ::NotImplementedError
|
277
|
+
raise ::NotImplementedError, %(#{self.class} ##{__method__} method called before being registered)
|
267
278
|
end
|
268
279
|
end
|
269
280
|
|
@@ -291,75 +302,73 @@ module Extensions
|
|
291
302
|
option :name, value
|
292
303
|
end
|
293
304
|
end
|
294
|
-
# NOTE match_name may get deprecated
|
295
|
-
alias match_name named
|
296
305
|
|
297
306
|
def content_model value
|
298
307
|
option :content_model, value
|
299
308
|
end
|
300
309
|
alias parse_content_as content_model
|
301
|
-
alias parses_content_as content_model
|
302
|
-
#alias parse_as content_model
|
303
|
-
#alias parsed_as content_model
|
304
310
|
|
305
|
-
def
|
306
|
-
option :
|
311
|
+
def positional_attributes *value
|
312
|
+
option :positional_attrs, value.flatten
|
307
313
|
end
|
308
|
-
alias
|
309
|
-
alias
|
314
|
+
alias name_positional_attributes positional_attributes
|
315
|
+
# NOTE positional_attrs alias is deprecated
|
316
|
+
alias positional_attrs positional_attributes
|
310
317
|
|
311
|
-
def
|
318
|
+
def default_attributes value
|
312
319
|
option :default_attrs, value
|
313
320
|
end
|
321
|
+
# NOTE default_attrs alias is deprecated
|
322
|
+
alias default_attrs default_attributes
|
314
323
|
|
315
|
-
def
|
324
|
+
def resolve_attributes *args
|
316
325
|
# NOTE assume true as default value; rewrap single-argument string or symbol
|
317
326
|
if (args = args.fetch 0, true).respond_to? :to_sym
|
318
327
|
args = [args]
|
319
328
|
end unless args.size > 1
|
320
329
|
case args
|
321
330
|
when true
|
322
|
-
option :
|
331
|
+
option :positional_attrs, []
|
323
332
|
option :default_attrs, {}
|
324
333
|
when ::Array
|
325
334
|
names, defaults = [], {}
|
326
335
|
args.each do |arg|
|
327
336
|
if (arg = arg.to_s).include? '='
|
328
|
-
name, value = arg.
|
337
|
+
name, _, value = arg.partition '='
|
329
338
|
if name.include? ':'
|
330
|
-
idx, name = name.
|
339
|
+
idx, _, name = name.partition ':'
|
331
340
|
idx = idx == '@' ? names.size : idx.to_i
|
332
341
|
names[idx] = name
|
333
342
|
end
|
334
343
|
defaults[name] = value
|
335
344
|
elsif arg.include? ':'
|
336
|
-
idx, name = arg.
|
345
|
+
idx, _, name = arg.partition ':'
|
337
346
|
idx = idx == '@' ? names.size : idx.to_i
|
338
347
|
names[idx] = name
|
339
348
|
else
|
340
349
|
names << arg
|
341
350
|
end
|
342
351
|
end
|
343
|
-
option :
|
352
|
+
option :positional_attrs, names.compact
|
344
353
|
option :default_attrs, defaults
|
345
354
|
when ::Hash
|
346
355
|
names, defaults = [], {}
|
347
356
|
args.each do |key, val|
|
348
357
|
if (name = key.to_s).include? ':'
|
349
|
-
idx, name = name.
|
358
|
+
idx, _, name = name.partition ':'
|
350
359
|
idx = idx == '@' ? names.size : idx.to_i
|
351
360
|
names[idx] = name
|
352
361
|
end
|
353
362
|
defaults[name] = val if val
|
354
363
|
end
|
355
|
-
option :
|
364
|
+
option :positional_attrs, names.compact
|
356
365
|
option :default_attrs, defaults
|
357
366
|
else
|
358
367
|
raise ::ArgumentError, %(unsupported attributes specification for macro: #{args.inspect})
|
359
368
|
end
|
360
369
|
end
|
361
|
-
# NOTE
|
362
|
-
alias resolve_attributes
|
370
|
+
# NOTE resolves_attributes alias is deprecated
|
371
|
+
alias resolves_attributes resolve_attributes
|
363
372
|
end
|
364
373
|
|
365
374
|
# Public: Preprocessors are run after the source text is split into lines and
|
@@ -377,7 +386,7 @@ module Extensions
|
|
377
386
|
# Preprocessor implementations must extend the Preprocessor class.
|
378
387
|
class Preprocessor < Processor
|
379
388
|
def process document, reader
|
380
|
-
raise ::NotImplementedError, %(
|
389
|
+
raise ::NotImplementedError, %(#{Preprocessor} subclass #{self.class} must implement the ##{__method__} method)
|
381
390
|
end
|
382
391
|
end
|
383
392
|
Preprocessor::DSL = DocumentProcessorDsl
|
@@ -394,7 +403,7 @@ module Extensions
|
|
394
403
|
# QUESTION should the tree processor get invoked after parse header too?
|
395
404
|
class TreeProcessor < Processor
|
396
405
|
def process document
|
397
|
-
raise ::NotImplementedError, %(
|
406
|
+
raise ::NotImplementedError, %(#{TreeProcessor} subclass #{self.class} must implement the ##{__method__} method)
|
398
407
|
end
|
399
408
|
end
|
400
409
|
TreeProcessor::DSL = DocumentProcessorDsl
|
@@ -416,10 +425,10 @@ module Extensions
|
|
416
425
|
# TIP: Postprocessors can also be used to relocate assets needed by the published
|
417
426
|
# document.
|
418
427
|
#
|
419
|
-
# Postprocessor implementations must Postprocessor.
|
428
|
+
# Postprocessor implementations must extend Postprocessor.
|
420
429
|
class Postprocessor < Processor
|
421
430
|
def process document, output
|
422
|
-
raise ::NotImplementedError, %(
|
431
|
+
raise ::NotImplementedError, %(#{Postprocessor} subclass #{self.class} must implement the ##{__method__} method)
|
423
432
|
end
|
424
433
|
end
|
425
434
|
Postprocessor::DSL = DocumentProcessorDsl
|
@@ -437,7 +446,7 @@ module Extensions
|
|
437
446
|
# TODO add file extension or regexp as shortcut for handles? method
|
438
447
|
class IncludeProcessor < Processor
|
439
448
|
def process document, reader, target, attributes
|
440
|
-
raise ::NotImplementedError, %(
|
449
|
+
raise ::NotImplementedError, %(#{IncludeProcessor} subclass #{self.class} must implement the ##{__method__} method)
|
441
450
|
end
|
442
451
|
|
443
452
|
def handles? target
|
@@ -475,15 +484,13 @@ module Extensions
|
|
475
484
|
# If a location is not specified, the DocinfoProcessor is assumed
|
476
485
|
# to add content to the header.
|
477
486
|
class DocinfoProcessor < Processor
|
478
|
-
attr_accessor :location
|
479
|
-
|
480
487
|
def initialize config = {}
|
481
488
|
super config
|
482
489
|
@config[:location] ||= :head
|
483
490
|
end
|
484
491
|
|
485
492
|
def process document
|
486
|
-
raise ::NotImplementedError, %(
|
493
|
+
raise ::NotImplementedError, %(#{DocinfoProcessor} subclass #{self.class} must implement the ##{__method__} method)
|
487
494
|
end
|
488
495
|
end
|
489
496
|
|
@@ -504,6 +511,10 @@ module Extensions
|
|
504
511
|
# registered to handle this name and, if found, invokes its {Processor#process}
|
505
512
|
# method to build a corresponding node in the document tree.
|
506
513
|
#
|
514
|
+
# If the process method returns an instance of Block, the content model of that
|
515
|
+
# Block is :compound, and the Block contains at least one line, the parser will
|
516
|
+
# parse those lines into blocks an assigned them to the returned block.
|
517
|
+
#
|
507
518
|
# AsciiDoc example:
|
508
519
|
#
|
509
520
|
# [shout]
|
@@ -514,7 +525,7 @@ module Extensions
|
|
514
525
|
# * :named - The name of the block (required: true)
|
515
526
|
# * :contexts - The blocks contexts on which this style can be used (default: [:paragraph, :open]
|
516
527
|
# * :content_model - The structure of the content supported in this block (default: :compound)
|
517
|
-
# * :
|
528
|
+
# * :positional_attrs - A list of attribute names used to map positional attributes (default: nil)
|
518
529
|
# * :default_attrs - A hash of attribute names and values used to seed the attributes hash (default: nil)
|
519
530
|
# * ...
|
520
531
|
#
|
@@ -539,7 +550,7 @@ module Extensions
|
|
539
550
|
end
|
540
551
|
|
541
552
|
def process parent, reader, attributes
|
542
|
-
raise ::NotImplementedError, %(
|
553
|
+
raise ::NotImplementedError, %(#{BlockProcessor} subclass #{self.class} must implement the ##{__method__} method)
|
543
554
|
end
|
544
555
|
end
|
545
556
|
|
@@ -551,7 +562,7 @@ module Extensions
|
|
551
562
|
end
|
552
563
|
alias on_contexts contexts
|
553
564
|
alias on_context contexts
|
554
|
-
alias
|
565
|
+
alias bind_to contexts
|
555
566
|
end
|
556
567
|
BlockProcessor::DSL = BlockProcessorDsl
|
557
568
|
|
@@ -565,28 +576,32 @@ module Extensions
|
|
565
576
|
end
|
566
577
|
|
567
578
|
def process parent, target, attributes
|
568
|
-
raise ::NotImplementedError, %(
|
579
|
+
raise ::NotImplementedError, %(#{MacroProcessor} subclass #{self.class} must implement the ##{__method__} method)
|
569
580
|
end
|
570
581
|
end
|
571
582
|
|
572
583
|
module MacroProcessorDsl
|
573
584
|
include SyntaxProcessorDsl
|
574
585
|
|
575
|
-
def
|
586
|
+
def resolve_attributes *args
|
576
587
|
if args.size == 1 && !args[0]
|
577
588
|
option :content_model, :text
|
578
|
-
|
589
|
+
else
|
590
|
+
super
|
591
|
+
option :content_model, :attributes
|
579
592
|
end
|
580
|
-
super
|
581
|
-
option :content_model, :attributes
|
582
593
|
end
|
583
|
-
# NOTE
|
584
|
-
alias resolve_attributes
|
594
|
+
# NOTE resolves_attributes alias is deprecated
|
595
|
+
alias resolves_attributes resolve_attributes
|
585
596
|
end
|
586
597
|
|
587
598
|
# Public: BlockMacroProcessors are used to handle block macros that have a
|
588
599
|
# custom name.
|
589
600
|
#
|
601
|
+
# If the process method returns an instance of Block, the content model of that
|
602
|
+
# Block is :compound, and the Block contains at least one line, the parser will
|
603
|
+
# parse those lines into blocks an assigned them to the returned block.
|
604
|
+
#
|
590
605
|
# BlockMacroProcessor implementations must extend BlockMacroProcessor.
|
591
606
|
class BlockMacroProcessor < MacroProcessor
|
592
607
|
def name
|
@@ -603,7 +618,7 @@ module Extensions
|
|
603
618
|
#--
|
604
619
|
# TODO break this out into different pattern types
|
605
620
|
# for example, FullInlineMacro, ShortInlineMacro (no target) and other patterns
|
606
|
-
# FIXME for inline
|
621
|
+
# FIXME for inline macro, we need to have some way to specify the text as a passthrough
|
607
622
|
class InlineMacroProcessor < MacroProcessor
|
608
623
|
@@rx_cache = {}
|
609
624
|
|
@@ -615,23 +630,23 @@ module Extensions
|
|
615
630
|
|
616
631
|
def resolve_regexp name, format
|
617
632
|
raise ::ArgumentError, %(invalid name for inline macro: #{name}) unless MacroNameRx.match? name
|
618
|
-
@@rx_cache[[name, format]] ||= /\\?#{name}:#{format == :short ? '(){0}' : '(\S+?)'}\[(
|
633
|
+
@@rx_cache[[name, format]] ||= /\\?#{name}:#{format == :short ? '(){0}' : '(\S+?)'}\[(|#{CC_ANY}*?[^\\])\]/
|
619
634
|
end
|
620
635
|
end
|
621
636
|
|
622
637
|
module InlineMacroProcessorDsl
|
623
638
|
include MacroProcessorDsl
|
624
639
|
|
625
|
-
def
|
640
|
+
def format value
|
626
641
|
option :format, value
|
627
642
|
end
|
628
|
-
alias
|
643
|
+
alias match_format format
|
644
|
+
# NOTE using_format alias is deprecated
|
645
|
+
alias using_format format
|
629
646
|
|
630
|
-
def
|
647
|
+
def match value
|
631
648
|
option :regexp, value
|
632
649
|
end
|
633
|
-
alias match matches
|
634
|
-
alias matching matches
|
635
650
|
end
|
636
651
|
InlineMacroProcessor::DSL = InlineMacroProcessorDsl
|
637
652
|
|
@@ -659,7 +674,7 @@ module Extensions
|
|
659
674
|
|
660
675
|
# Public: A specialization of the Extension proxy that additionally stores a
|
661
676
|
# reference to the {Processor#process} method. By storing this reference, its
|
662
|
-
# possible to
|
677
|
+
# possible to accommodate both concrete extension implementations and Procs.
|
663
678
|
class ProcessorExtension < Extension
|
664
679
|
attr_reader :process_method
|
665
680
|
|
@@ -947,7 +962,7 @@ module Extensions
|
|
947
962
|
end
|
948
963
|
|
949
964
|
# Public: Registers an {DocinfoProcessor} with the extension registry to
|
950
|
-
# add
|
965
|
+
# add additional docinfo to the document.
|
951
966
|
#
|
952
967
|
# The DocinfoProcessor may be one of four types:
|
953
968
|
#
|
@@ -965,7 +980,7 @@ module Extensions
|
|
965
980
|
# docinfo_processor MetaRobotsDocinfoProcessor
|
966
981
|
#
|
967
982
|
# # as an instance of a DocinfoProcessor subclass with an explicit location
|
968
|
-
# docinfo_processor JQueryDocinfoProcessor.new, :
|
983
|
+
# docinfo_processor JQueryDocinfoProcessor.new, location: :footer
|
969
984
|
#
|
970
985
|
# # as a name of a DocinfoProcessor subclass
|
971
986
|
# docinfo_processor 'MetaRobotsDocinfoProcessor'
|
@@ -1014,8 +1029,6 @@ module Extensions
|
|
1014
1029
|
else
|
1015
1030
|
@docinfo_processor_extensions
|
1016
1031
|
end
|
1017
|
-
else
|
1018
|
-
nil
|
1019
1032
|
end
|
1020
1033
|
end
|
1021
1034
|
|
@@ -1194,7 +1207,7 @@ module Extensions
|
|
1194
1207
|
# name - the String or Symbol (coersed to a Symbol) macro name
|
1195
1208
|
#
|
1196
1209
|
# Returns the [Extension] object stored in the registry that proxies the
|
1197
|
-
#
|
1210
|
+
# corresponding BlockMacroProcessor or nil if a match is not found.
|
1198
1211
|
def find_block_macro_extension name
|
1199
1212
|
@block_macro_extensions[name.to_sym]
|
1200
1213
|
end
|
@@ -1281,7 +1294,7 @@ module Extensions
|
|
1281
1294
|
# name - the String or Symbol (coersed to a Symbol) macro name
|
1282
1295
|
#
|
1283
1296
|
# Returns the [Extension] object stored in the registry that proxies the
|
1284
|
-
#
|
1297
|
+
# corresponding InlineMacroProcessor or nil if a match is not found.
|
1285
1298
|
def find_inline_macro_extension name
|
1286
1299
|
@inline_macro_extensions[name.to_sym]
|
1287
1300
|
end
|
@@ -1319,41 +1332,38 @@ module Extensions
|
|
1319
1332
|
def add_document_processor kind, args, &block
|
1320
1333
|
kind_name = kind.to_s.tr '_', ' '
|
1321
1334
|
kind_class_symbol = kind_name.split.map {|it| it.capitalize }.join.to_sym
|
1322
|
-
kind_class = Extensions.const_get kind_class_symbol
|
1323
|
-
kind_java_class = (defined? ::AsciidoctorJ) ? (::AsciidoctorJ::Extensions.const_get kind_class_symbol) : nil
|
1335
|
+
kind_class = Extensions.const_get kind_class_symbol, false
|
1336
|
+
kind_java_class = (defined? ::AsciidoctorJ) ? (::AsciidoctorJ::Extensions.const_get kind_class_symbol, false) : nil
|
1324
1337
|
kind_store = instance_variable_get(%(@#{kind}_extensions).to_sym) || instance_variable_set(%(@#{kind}_extensions).to_sym, [])
|
1325
1338
|
# style 1: specified as block
|
1326
|
-
|
1339
|
+
if block_given?
|
1327
1340
|
config = resolve_args args, 1
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
# NOTE kind_class.contants(false) doesn't exist in Ruby 1.8.7
|
1335
|
-
processor.extend kind_class.const_get :DSL if kind_class.constants.grep :DSL
|
1336
|
-
processor.instance_exec(&block)
|
1337
|
-
processor.freeze
|
1341
|
+
(processor = kind_class.new config).singleton_class.enable_dsl
|
1342
|
+
if block.arity == 0
|
1343
|
+
processor.instance_exec(&block)
|
1344
|
+
else
|
1345
|
+
yield processor
|
1346
|
+
end
|
1338
1347
|
unless processor.process_block_given?
|
1339
1348
|
raise ::ArgumentError, %(No block specified to process #{kind_name} extension at #{block.source_location})
|
1340
1349
|
end
|
1341
|
-
|
1350
|
+
processor.freeze
|
1351
|
+
extension = ProcessorExtension.new kind, processor
|
1342
1352
|
else
|
1343
1353
|
processor, config = resolve_args args, 2
|
1344
1354
|
# style 2: specified as Class or String class name
|
1345
|
-
if (processor_class =
|
1355
|
+
if (processor_class = Helpers.resolve_class processor)
|
1346
1356
|
unless processor_class < kind_class || (kind_java_class && processor_class < kind_java_class)
|
1347
1357
|
raise ::ArgumentError, %(Invalid type for #{kind_name} extension: #{processor})
|
1348
1358
|
end
|
1349
1359
|
processor_instance = processor_class.new config
|
1350
1360
|
processor_instance.freeze
|
1351
|
-
ProcessorExtension.new kind, processor_instance
|
1361
|
+
extension = ProcessorExtension.new kind, processor_instance
|
1352
1362
|
# style 3: specified as instance
|
1353
1363
|
elsif kind_class === processor || (kind_java_class && kind_java_class === processor)
|
1354
1364
|
processor.update_config config
|
1355
1365
|
processor.freeze
|
1356
|
-
ProcessorExtension.new kind, processor
|
1366
|
+
extension = ProcessorExtension.new kind, processor
|
1357
1367
|
else
|
1358
1368
|
raise ::ArgumentError, %(Invalid arguments specified for registering #{kind_name} extension: #{args})
|
1359
1369
|
end
|
@@ -1365,24 +1375,18 @@ module Extensions
|
|
1365
1375
|
|
1366
1376
|
def add_syntax_processor kind, args, &block
|
1367
1377
|
kind_name = kind.to_s.tr '_', ' '
|
1368
|
-
kind_class_symbol = (kind_name.split.map {|it| it.capitalize }
|
1369
|
-
kind_class = Extensions.const_get kind_class_symbol
|
1370
|
-
kind_java_class = (defined? ::AsciidoctorJ) ? (::AsciidoctorJ::Extensions.const_get kind_class_symbol) : nil
|
1378
|
+
kind_class_symbol = (kind_name.split.map {|it| it.capitalize } << 'Processor').join.to_sym
|
1379
|
+
kind_class = Extensions.const_get kind_class_symbol, false
|
1380
|
+
kind_java_class = (defined? ::AsciidoctorJ) ? (::AsciidoctorJ::Extensions.const_get kind_class_symbol, false) : nil
|
1371
1381
|
kind_store = instance_variable_get(%(@#{kind}_extensions).to_sym) || instance_variable_set(%(@#{kind}_extensions).to_sym, {})
|
1372
1382
|
# style 1: specified as block
|
1373
1383
|
if block_given?
|
1374
1384
|
name, config = resolve_args args, 2
|
1375
|
-
processor = kind_class.new as_symbol
|
1376
|
-
|
1377
|
-
#class << processor
|
1378
|
-
# include_dsl
|
1379
|
-
#end
|
1380
|
-
# NOTE kind_class.contants(false) doesn't exist in Ruby 1.8.7
|
1381
|
-
processor.extend kind_class.const_get :DSL if kind_class.constants.grep :DSL
|
1382
|
-
if block.arity == 1
|
1383
|
-
yield processor
|
1384
|
-
else
|
1385
|
+
(processor = kind_class.new (as_symbol name), config).singleton_class.enable_dsl
|
1386
|
+
if block.arity == 0
|
1385
1387
|
processor.instance_exec(&block)
|
1388
|
+
else
|
1389
|
+
yield processor
|
1386
1390
|
end
|
1387
1391
|
unless (name = as_symbol processor.name)
|
1388
1392
|
raise ::ArgumentError, %(No name specified for #{kind_name} extension at #{block.source_location})
|
@@ -1395,7 +1399,7 @@ module Extensions
|
|
1395
1399
|
else
|
1396
1400
|
processor, name, config = resolve_args args, 3
|
1397
1401
|
# style 2: specified as Class or String class name
|
1398
|
-
if (processor_class =
|
1402
|
+
if (processor_class = Helpers.resolve_class processor)
|
1399
1403
|
unless processor_class < kind_class || (kind_java_class && processor_class < kind_java_class)
|
1400
1404
|
raise ::ArgumentError, %(Class specified for #{kind_name} extension does not inherit from #{kind_class}: #{processor})
|
1401
1405
|
end
|
@@ -1453,13 +1457,11 @@ module Extensions
|
|
1453
1457
|
|
1454
1458
|
def create name = nil, &block
|
1455
1459
|
if block_given?
|
1456
|
-
Registry.new
|
1460
|
+
Registry.new (name || generate_name) => block
|
1457
1461
|
else
|
1458
1462
|
Registry.new
|
1459
1463
|
end
|
1460
1464
|
end
|
1461
|
-
# Deprecated: Use create instead of build_registry
|
1462
|
-
alias build_registry create
|
1463
1465
|
|
1464
1466
|
# Public: Registers an extension Group that subsequently registers a
|
1465
1467
|
# collection of extensions.
|
@@ -1501,7 +1503,7 @@ module Extensions
|
|
1501
1503
|
resolved_group = block
|
1502
1504
|
elsif (group = args.pop)
|
1503
1505
|
# QUESTION should we instantiate the group class here or defer until activation??
|
1504
|
-
resolved_group = (resolve_class group) || group
|
1506
|
+
resolved_group = (Helpers.resolve_class group) || group
|
1505
1507
|
else
|
1506
1508
|
raise ::ArgumentError, %(Extension group to register not specified)
|
1507
1509
|
end
|
@@ -1529,55 +1531,6 @@ module Extensions
|
|
1529
1531
|
names.each {|group| @groups.delete group.to_sym }
|
1530
1532
|
nil
|
1531
1533
|
end
|
1532
|
-
|
1533
|
-
# Internal: Resolve the specified object as a Class
|
1534
|
-
#
|
1535
|
-
# object - The object to resolve as a Class
|
1536
|
-
#
|
1537
|
-
# Returns a Class if the specified object is a Class (but not a Module) or
|
1538
|
-
# a String that resolves to a Class; otherwise, nil
|
1539
|
-
def resolve_class object
|
1540
|
-
case object
|
1541
|
-
when ::Class
|
1542
|
-
object
|
1543
|
-
when ::String
|
1544
|
-
class_for_name object
|
1545
|
-
end
|
1546
|
-
end
|
1547
|
-
|
1548
|
-
# Public: Resolves the Class object for the qualified name.
|
1549
|
-
#
|
1550
|
-
# Returns Class
|
1551
|
-
if ::RUBY_MIN_VERSION_2
|
1552
|
-
def class_for_name qualified_name
|
1553
|
-
resolved = ::Object.const_get qualified_name, false
|
1554
|
-
raise unless ::Class === resolved
|
1555
|
-
resolved
|
1556
|
-
rescue
|
1557
|
-
raise ::NameError, %(Could not resolve class for name: #{qualified_name})
|
1558
|
-
end
|
1559
|
-
elsif ::RUBY_MIN_VERSION_1_9
|
1560
|
-
def class_for_name qualified_name
|
1561
|
-
resolved = (qualified_name.split '::').reduce ::Object do |current, name|
|
1562
|
-
name.empty? ? current : (current.const_get name, false)
|
1563
|
-
end
|
1564
|
-
raise unless ::Class === resolved
|
1565
|
-
resolved
|
1566
|
-
rescue
|
1567
|
-
raise ::NameError, %(Could not resolve class for name: #{qualified_name})
|
1568
|
-
end
|
1569
|
-
else
|
1570
|
-
def class_for_name qualified_name
|
1571
|
-
resolved = (qualified_name.split '::').reduce ::Object do |current, name|
|
1572
|
-
# NOTE on Ruby 1.8, const_defined? only checks for constant in current scope
|
1573
|
-
name.empty? ? current : ((current.const_defined? name) ? (current.const_get name) : raise)
|
1574
|
-
end
|
1575
|
-
raise unless ::Class === resolved
|
1576
|
-
resolved
|
1577
|
-
rescue
|
1578
|
-
raise ::NameError, %(Could not resolve class for name: #{qualified_name})
|
1579
|
-
end
|
1580
|
-
end
|
1581
1534
|
end
|
1582
1535
|
end
|
1583
1536
|
end
|