asciidoctor 0.1.4 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of asciidoctor might be problematic. Click here for more details.

Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +209 -25
  3. data/{LICENSE → LICENSE.adoc} +4 -3
  4. data/README.adoc +392 -395
  5. data/Rakefile +94 -137
  6. data/benchmark/benchmark.rb +127 -0
  7. data/benchmark/sample-data/mdbasics.adoc +334 -0
  8. data/bin/asciidoctor +5 -8
  9. data/bin/asciidoctor-safe +4 -8
  10. data/compat/asciidoc.conf +78 -11
  11. data/compat/font-awesome-3-compat.css +397 -0
  12. data/data/stylesheets/asciidoctor-default.css +399 -0
  13. data/data/stylesheets/coderay-asciidoctor.css +89 -0
  14. data/features/open_block.feature +92 -0
  15. data/features/pass_block.feature +66 -0
  16. data/features/step_definitions.rb +42 -0
  17. data/features/text_formatting.feature +55 -0
  18. data/features/xref.feature +116 -0
  19. data/lib/asciidoctor.rb +1155 -605
  20. data/lib/asciidoctor/abstract_block.rb +157 -71
  21. data/lib/asciidoctor/abstract_node.rb +150 -93
  22. data/lib/asciidoctor/attribute_list.rb +85 -90
  23. data/lib/asciidoctor/block.rb +51 -24
  24. data/lib/asciidoctor/callouts.rb +4 -7
  25. data/lib/asciidoctor/cli.rb +3 -0
  26. data/lib/asciidoctor/cli/invoker.rb +86 -76
  27. data/lib/asciidoctor/cli/options.rb +111 -61
  28. data/lib/asciidoctor/converter.rb +232 -0
  29. data/lib/asciidoctor/converter/base.rb +58 -0
  30. data/lib/asciidoctor/converter/composite.rb +66 -0
  31. data/lib/asciidoctor/converter/docbook45.rb +94 -0
  32. data/lib/asciidoctor/converter/docbook5.rb +684 -0
  33. data/lib/asciidoctor/converter/factory.rb +225 -0
  34. data/lib/asciidoctor/converter/html5.rb +1081 -0
  35. data/lib/asciidoctor/converter/template.rb +296 -0
  36. data/lib/asciidoctor/core_ext.rb +7 -0
  37. data/lib/asciidoctor/core_ext/object/nil_or_empty.rb +23 -0
  38. data/lib/asciidoctor/core_ext/string/chr.rb +6 -0
  39. data/lib/asciidoctor/core_ext/symbol/length.rb +6 -0
  40. data/lib/asciidoctor/document.rb +590 -304
  41. data/lib/asciidoctor/extensions.rb +1100 -308
  42. data/lib/asciidoctor/helpers.rb +109 -46
  43. data/lib/asciidoctor/inline.rb +16 -9
  44. data/lib/asciidoctor/list.rb +23 -15
  45. data/lib/asciidoctor/opal_ext.rb +4 -0
  46. data/lib/asciidoctor/opal_ext/comparable.rb +38 -0
  47. data/lib/asciidoctor/opal_ext/dir.rb +13 -0
  48. data/lib/asciidoctor/opal_ext/error.rb +2 -0
  49. data/lib/asciidoctor/opal_ext/file.rb +125 -0
  50. data/lib/asciidoctor/{lexer.rb → parser.rb} +646 -455
  51. data/lib/asciidoctor/path_resolver.rb +141 -77
  52. data/lib/asciidoctor/reader.rb +257 -187
  53. data/lib/asciidoctor/section.rb +12 -16
  54. data/lib/asciidoctor/stylesheets.rb +91 -0
  55. data/lib/asciidoctor/substitutors.rb +1548 -0
  56. data/lib/asciidoctor/table.rb +73 -57
  57. data/lib/asciidoctor/timings.rb +39 -0
  58. data/lib/asciidoctor/version.rb +1 -1
  59. data/man/asciidoctor.1 +22 -14
  60. data/man/asciidoctor.adoc +18 -10
  61. data/test/attributes_test.rb +314 -14
  62. data/test/blocks_test.rb +763 -118
  63. data/test/converter_test.rb +352 -0
  64. data/test/document_test.rb +518 -199
  65. data/test/extensions_test.rb +273 -103
  66. data/test/fixtures/asciidoc_index.txt +27 -13
  67. data/test/fixtures/basic-docinfo.xml +1 -1
  68. data/test/fixtures/chapter-a.adoc +3 -0
  69. data/test/fixtures/custom-backends/erb/html5/block_paragraph.html.erb +6 -0
  70. data/test/fixtures/docinfo.xml +1 -1
  71. data/test/fixtures/include-file.asciidoc +2 -0
  72. data/test/fixtures/master.adoc +5 -0
  73. data/test/invoker_test.rb +173 -61
  74. data/test/links_test.rb +97 -21
  75. data/test/lists_test.rb +181 -22
  76. data/test/options_test.rb +86 -2
  77. data/test/paragraphs_test.rb +47 -5
  78. data/test/{lexer_test.rb → parser_test.rb} +128 -57
  79. data/test/paths_test.rb +36 -1
  80. data/test/preamble_test.rb +25 -17
  81. data/test/reader_test.rb +404 -249
  82. data/test/sections_test.rb +623 -58
  83. data/test/substitutions_test.rb +609 -132
  84. data/test/tables_test.rb +198 -24
  85. data/test/test_helper.rb +101 -31
  86. data/test/text_test.rb +88 -31
  87. metadata +160 -64
  88. data/Gemfile +0 -12
  89. data/Guardfile +0 -18
  90. data/asciidoctor.gemspec +0 -143
  91. data/lib/asciidoctor/backends/_stylesheets.rb +0 -466
  92. data/lib/asciidoctor/backends/base_template.rb +0 -114
  93. data/lib/asciidoctor/backends/docbook45.rb +0 -774
  94. data/lib/asciidoctor/backends/docbook5.rb +0 -103
  95. data/lib/asciidoctor/backends/html5.rb +0 -1214
  96. data/lib/asciidoctor/renderer.rb +0 -259
  97. data/lib/asciidoctor/substituters.rb +0 -1083
  98. data/test/fixtures/asciidoc.txt +0 -105
  99. data/test/fixtures/ascshort.txt +0 -32
  100. data/test/fixtures/list_elements.asciidoc +0 -10
  101. data/test/renderer_test.rb +0 -162
@@ -1,7 +1,14 @@
1
- require 'test_helper'
1
+ # encoding: UTF-8
2
+ unless defined? ASCIIDOCTOR_PROJECT_DIR
3
+ $: << File.dirname(__FILE__); $:.uniq!
4
+ require 'test_helper'
5
+ end
2
6
  require 'asciidoctor/extensions'
3
7
 
4
8
  class SamplePreprocessor < Asciidoctor::Extensions::Preprocessor
9
+ def process doc, reader
10
+ nil
11
+ end
5
12
  end
6
13
 
7
14
  class SampleIncludeProcessor < Asciidoctor::Extensions::IncludeProcessor
@@ -23,12 +30,14 @@ class SampleInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
23
30
  end
24
31
 
25
32
  class ScrubHeaderPreprocessor < Asciidoctor::Extensions::Preprocessor
26
- def process reader, lines
33
+ def process doc, reader
34
+ lines = reader.lines
35
+ skipped = []
27
36
  while !lines.empty? && !lines.first.start_with?('=')
28
- lines.shift
37
+ skipped << lines.shift
29
38
  reader.advance
30
39
  end
31
- #lines
40
+ doc.set_attr 'skipped', (skipped * "\n")
32
41
  reader
33
42
  end
34
43
  end
@@ -38,7 +47,7 @@ class BoilerplateTextIncludeProcessor < Asciidoctor::Extensions::IncludeProcesso
38
47
  target.end_with? '.txt'
39
48
  end
40
49
 
41
- def process reader, target, attributes
50
+ def process document, reader, target, attributes
42
51
  case target
43
52
  when 'lorem-ipsum.txt'
44
53
  content = ["Lorem ipsum dolor sit amet...\n"]
@@ -50,84 +59,109 @@ class BoilerplateTextIncludeProcessor < Asciidoctor::Extensions::IncludeProcesso
50
59
  end
51
60
 
52
61
  class ReplaceAuthorTreeprocessor < Asciidoctor::Extensions::Treeprocessor
53
- def process
54
- @document.attributes['firstname'] = 'Ghost'
55
- @document.attributes['author'] = 'Ghost Writer'
62
+ def process document
63
+ document.attributes['firstname'] = 'Ghost'
64
+ document.attributes['author'] = 'Ghost Writer'
65
+ document
66
+ end
67
+ end
68
+
69
+ class ReplaceTreeTreeprocessor < Asciidoctor::Extensions::Treeprocessor
70
+ def process document
71
+ if document.doctitle == 'Original Document'
72
+ Asciidoctor.load %(== Replacement Document\nReplacement Author\n\ncontent)
73
+ else
74
+ document
75
+ end
56
76
  end
57
77
  end
58
78
 
59
79
  class StripAttributesPostprocessor < Asciidoctor::Extensions::Postprocessor
60
- def process output
80
+ def process document, output
61
81
  output.gsub(/<(\w+).*?>/m, "<\\1>")
62
82
  end
63
83
  end
64
84
 
65
- class UppercaseBlock < Asciidoctor::Extensions::BlockProcessor
85
+ class UppercaseBlock < Asciidoctor::Extensions::BlockProcessor; use_dsl
86
+ match_name :yell
87
+ on_contexts :paragraph
88
+ parse_content_as :simple
66
89
  def process parent, reader, attributes
67
- Asciidoctor::Block.new parent, :paragraph, :source => reader.lines.map {|line| line.upcase }
90
+ create_paragraph parent, reader.lines.map(&:upcase), attributes
68
91
  end
69
92
  end
70
93
 
71
94
  class SnippetMacro < Asciidoctor::Extensions::BlockMacroProcessor
72
95
  def process parent, target, attributes
73
- Asciidoctor::Block.new parent, :pass, :content_model => :raw, :source => %(<script src="http://example.com/#{target}.js"></script>)
96
+ create_pass_block parent, %(<script src="http://example.com/#{target}.js"></script>), {}, :content_model => :raw
74
97
  end
75
98
  end
76
99
 
77
- class TemperatureMacro < Asciidoctor::Extensions::InlineMacroProcessor
100
+ class TemperatureMacro < Asciidoctor::Extensions::InlineMacroProcessor; use_dsl
101
+ named :degrees
102
+ name_attributes 'units'
78
103
  def process parent, target, attributes
79
- temperature_unit = @document.attr('temperature-unit', 'C')
104
+ units = attributes['units'] || (parent.document.attr 'temperature-unit', 'C')
80
105
  c = target.to_f
81
- if temperature_unit == 'C'
82
- text = %(#{c} &#176;C)
83
- elsif temperature_unit == 'F'
84
- f = c * 1.8 + 32
85
- text = %(#{f} &#176;F)
106
+ case units
107
+ when 'C'
108
+ %(#{c} &#176;C)
109
+ when 'F'
110
+ %(#{c * 1.8 + 32 } &#176;F)
86
111
  else
87
- text = target
112
+ c
88
113
  end
89
-
90
- text
91
114
  end
92
115
  end
93
116
 
94
- class SampleExtension < Asciidoctor::Extensions::Extension
95
- def self.activate(registry, document)
96
- document.attributes['activate-method-called'] = ''
117
+ class SampleExtensionGroup < Asciidoctor::Extensions::Group
118
+ def activate registry
119
+ registry.document.attributes['activate-method-called'] = ''
97
120
  registry.preprocessor SamplePreprocessor
98
121
  end
99
122
  end
100
123
 
101
124
  context 'Extensions' do
102
125
  context 'Register' do
103
- test 'should register extension class' do
126
+ test 'should register extension group class' do
104
127
  begin
105
- Asciidoctor::Extensions.register SampleExtension
106
- assert_not_nil Asciidoctor::Extensions.registered
107
- assert_equal 1, Asciidoctor::Extensions.registered.size
108
- assert_equal SampleExtension, Asciidoctor::Extensions.registered.first
128
+ Asciidoctor::Extensions.register :sample, SampleExtensionGroup
129
+ refute_nil Asciidoctor::Extensions.groups
130
+ assert_equal 1, Asciidoctor::Extensions.groups.size
131
+ assert_equal SampleExtensionGroup, Asciidoctor::Extensions.groups[:sample]
109
132
  ensure
110
133
  Asciidoctor::Extensions.unregister_all
111
134
  end
112
135
  end
113
136
 
114
- test 'should be able to self register extension class' do
137
+ test 'should self register extension group class' do
115
138
  begin
116
- SampleExtension.register
117
- assert_not_nil Asciidoctor::Extensions.registered
118
- assert_equal 1, Asciidoctor::Extensions.registered.size
119
- assert_equal SampleExtension, Asciidoctor::Extensions.registered.first
139
+ SampleExtensionGroup.register :sample
140
+ refute_nil Asciidoctor::Extensions.groups
141
+ assert_equal 1, Asciidoctor::Extensions.groups.size
142
+ assert_equal SampleExtensionGroup, Asciidoctor::Extensions.groups[:sample]
120
143
  ensure
121
144
  Asciidoctor::Extensions.unregister_all
122
145
  end
123
146
  end
124
147
 
125
- test 'should register extension class from string' do
148
+ test 'should register extension group from class name' do
126
149
  begin
127
- Asciidoctor::Extensions.register 'SampleExtension'
128
- assert_not_nil Asciidoctor::Extensions.registered
129
- assert_equal 1, Asciidoctor::Extensions.registered.size
130
- assert_equal SampleExtension, Asciidoctor::Extensions.registered.first
150
+ Asciidoctor::Extensions.register :sample, 'SampleExtensionGroup'
151
+ refute_nil Asciidoctor::Extensions.groups
152
+ assert_equal 1, Asciidoctor::Extensions.groups.size
153
+ assert_equal SampleExtensionGroup, Asciidoctor::Extensions.groups[:sample]
154
+ ensure
155
+ Asciidoctor::Extensions.unregister_all
156
+ end
157
+ end
158
+
159
+ test 'should register extension group from instance' do
160
+ begin
161
+ Asciidoctor::Extensions.register :sample, SampleExtensionGroup.new
162
+ refute_nil Asciidoctor::Extensions.groups
163
+ assert_equal 1, Asciidoctor::Extensions.groups.size
164
+ assert Asciidoctor::Extensions.groups[:sample].is_a? SampleExtensionGroup
131
165
  ensure
132
166
  Asciidoctor::Extensions.unregister_all
133
167
  end
@@ -135,11 +169,11 @@ context 'Extensions' do
135
169
 
136
170
  test 'should register extension block' do
137
171
  begin
138
- Asciidoctor::Extensions.register do |document|
172
+ Asciidoctor::Extensions.register(:sample) do
139
173
  end
140
- assert_not_nil Asciidoctor::Extensions.registered
141
- assert_equal 1, Asciidoctor::Extensions.registered.size
142
- assert Asciidoctor::Extensions.registered.first.is_a?(Proc)
174
+ refute_nil Asciidoctor::Extensions.groups
175
+ assert_equal 1, Asciidoctor::Extensions.groups.size
176
+ assert Asciidoctor::Extensions.groups[:sample].is_a? Proc
143
177
  ensure
144
178
  Asciidoctor::Extensions.unregister_all
145
179
  end
@@ -147,26 +181,26 @@ context 'Extensions' do
147
181
 
148
182
  test 'should get class for top-level class name' do
149
183
  clazz = Asciidoctor::Extensions.class_for_name('Asciidoctor')
150
- assert_not_nil clazz
184
+ refute_nil clazz
151
185
  assert_equal Asciidoctor, clazz
152
186
  end
153
187
 
154
188
  test 'should get class for class name in module' do
155
189
  clazz = Asciidoctor::Extensions.class_for_name('Asciidoctor::Extensions')
156
- assert_not_nil clazz
190
+ refute_nil clazz
157
191
  assert_equal Asciidoctor::Extensions, clazz
158
192
  end
159
193
 
160
194
  test 'should get class for class name resolved from root' do
161
195
  clazz = Asciidoctor::Extensions.class_for_name('::Asciidoctor::Extensions')
162
- assert_not_nil clazz
196
+ refute_nil clazz
163
197
  assert_equal Asciidoctor::Extensions, clazz
164
198
  end
165
199
 
166
200
  test 'should raise exception if cannot find class for name' do
167
201
  begin
168
- Asciidoctor::Extensions.class_for_name('InvalidModule::InvalidClass')
169
- flunk 'Expecting RuntimeError to be raised'
202
+ Asciidoctor::Extensions.class_for_name('InvalidModule::InvalidClass')
203
+ flunk 'Expecting RuntimeError to be raised'
170
204
  rescue RuntimeError => e
171
205
  assert_equal 'Could not resolve class for name: InvalidModule::InvalidClass', e.message
172
206
  end
@@ -174,23 +208,24 @@ context 'Extensions' do
174
208
 
175
209
  test 'should resolve class if class is given' do
176
210
  clazz = Asciidoctor::Extensions.resolve_class(Asciidoctor::Extensions)
177
- assert_not_nil clazz
211
+ refute_nil clazz
178
212
  assert_equal Asciidoctor::Extensions, clazz
179
213
  end
180
214
 
181
215
  test 'should resolve class if class from string' do
182
216
  clazz = Asciidoctor::Extensions.resolve_class('Asciidoctor::Extensions')
183
- assert_not_nil clazz
217
+ refute_nil clazz
184
218
  assert_equal Asciidoctor::Extensions, clazz
185
219
  end
186
220
  end
187
221
 
188
222
  context 'Activate' do
189
- test 'should call activate on extension class' do
223
+ test 'should call activate on extension group class' do
190
224
  begin
191
225
  doc = Asciidoctor::Document.new
192
- Asciidoctor::Extensions.register SampleExtension
193
- registry = Asciidoctor::Extensions::Registry.new doc
226
+ Asciidoctor::Extensions.register :sample, SampleExtensionGroup
227
+ registry = Asciidoctor::Extensions::Registry.new
228
+ registry.activate doc
194
229
  assert doc.attr? 'activate-method-called'
195
230
  assert registry.preprocessors?
196
231
  ensure
@@ -201,11 +236,12 @@ context 'Extensions' do
201
236
  test 'should invoke extension block' do
202
237
  begin
203
238
  doc = Asciidoctor::Document.new
204
- Asciidoctor::Extensions.register do |document|
205
- document.attributes['block-called'] = ''
239
+ Asciidoctor::Extensions.register do
240
+ @document.attributes['block-called'] = ''
206
241
  preprocessor SamplePreprocessor
207
242
  end
208
- registry = Asciidoctor::Extensions::Registry.new doc
243
+ registry = Asciidoctor::Extensions::Registry.new
244
+ registry.activate doc
209
245
  assert doc.attr? 'block-called'
210
246
  assert registry.preprocessors?
211
247
  ensure
@@ -215,7 +251,7 @@ context 'Extensions' do
215
251
 
216
252
  test 'should create registry in Document if extensions are loaded' do
217
253
  begin
218
- SampleExtension.register
254
+ SampleExtensionGroup.register
219
255
  doc = Asciidoctor::Document.new
220
256
  assert doc.extensions?
221
257
  assert doc.extensions.is_a? Asciidoctor::Extensions::Registry
@@ -230,79 +266,102 @@ context 'Extensions' do
230
266
  test 'should instantiate preprocessors' do
231
267
  registry = Asciidoctor::Extensions::Registry.new
232
268
  registry.preprocessor SamplePreprocessor
269
+ registry.activate Asciidoctor::Document.new
233
270
  assert registry.preprocessors?
234
- processors = registry.load_preprocessors Asciidoctor::Document.new
235
- assert_equal 1, processors.size
236
- assert processors.first.is_a? SamplePreprocessor
271
+ extensions = registry.preprocessors
272
+ assert_equal 1, extensions.size
273
+ assert extensions.first.is_a? Asciidoctor::Extensions::ProcessorExtension
274
+ assert extensions.first.instance.is_a? SamplePreprocessor
275
+ assert extensions.first.process_method.is_a? ::Method
237
276
  end
238
277
 
239
278
  test 'should instantiate include processors' do
240
279
  registry = Asciidoctor::Extensions::Registry.new
241
280
  registry.include_processor SampleIncludeProcessor
281
+ registry.activate Asciidoctor::Document.new
242
282
  assert registry.include_processors?
243
- processors = registry.load_include_processors Asciidoctor::Document.new
244
- assert_equal 1, processors.size
245
- assert processors.first.is_a? SampleIncludeProcessor
283
+ extensions = registry.include_processors
284
+ assert_equal 1, extensions.size
285
+ assert extensions.first.is_a? Asciidoctor::Extensions::ProcessorExtension
286
+ assert extensions.first.instance.is_a? SampleIncludeProcessor
287
+ assert extensions.first.process_method.is_a? ::Method
246
288
  end
247
289
 
248
290
  test 'should instantiate treeprocessors' do
249
291
  registry = Asciidoctor::Extensions::Registry.new
250
292
  registry.treeprocessor SampleTreeprocessor
293
+ registry.activate Asciidoctor::Document.new
251
294
  assert registry.treeprocessors?
252
- processors = registry.load_treeprocessors Asciidoctor::Document.new
253
- assert_equal 1, processors.size
254
- assert processors.first.is_a? SampleTreeprocessor
295
+ extensions = registry.treeprocessors
296
+ assert_equal 1, extensions.size
297
+ assert extensions.first.is_a? Asciidoctor::Extensions::ProcessorExtension
298
+ assert extensions.first.instance.is_a? SampleTreeprocessor
299
+ assert extensions.first.process_method.is_a? ::Method
255
300
  end
256
301
 
257
302
  test 'should instantiate postprocessors' do
258
303
  registry = Asciidoctor::Extensions::Registry.new
259
304
  registry.postprocessor SamplePostprocessor
305
+ registry.activate Asciidoctor::Document.new
260
306
  assert registry.postprocessors?
261
- processors = registry.load_postprocessors Asciidoctor::Document.new
262
- assert_equal 1, processors.size
263
- assert processors.first.is_a? SamplePostprocessor
307
+ extensions = registry.postprocessors
308
+ assert_equal 1, extensions.size
309
+ assert extensions.first.is_a? Asciidoctor::Extensions::ProcessorExtension
310
+ assert extensions.first.instance.is_a? SamplePostprocessor
311
+ assert extensions.first.process_method.is_a? ::Method
264
312
  end
265
313
 
266
314
  test 'should instantiate block processor' do
267
315
  registry = Asciidoctor::Extensions::Registry.new
268
- registry.block :sample, SampleBlock
316
+ registry.block SampleBlock, :sample
317
+ registry.activate Asciidoctor::Document.new
269
318
  assert registry.blocks?
270
- assert registry.processor_registered_for_block? :sample, :paragraph
271
- processor = registry.load_block_processor :sample, Asciidoctor::Document.new
272
- assert processor.is_a? SampleBlock
319
+ assert registry.registered_for_block? :sample, :paragraph
320
+ extension = registry.find_block_extension :sample
321
+ assert extension.is_a? Asciidoctor::Extensions::ProcessorExtension
322
+ assert extension.instance.is_a? SampleBlock
323
+ assert extension.process_method.is_a? ::Method
273
324
  end
274
325
 
275
326
  test 'should not match block processor for unsupported context' do
276
327
  registry = Asciidoctor::Extensions::Registry.new
277
- registry.block :sample, SampleBlock
278
- assert !(registry.processor_registered_for_block? :sample, :sidebar)
328
+ registry.block SampleBlock, :sample
329
+ registry.activate Asciidoctor::Document.new
330
+ assert !(registry.registered_for_block? :sample, :sidebar)
279
331
  end
280
332
 
281
333
  test 'should instantiate block macro processor' do
282
334
  registry = Asciidoctor::Extensions::Registry.new
283
- registry.block_macro 'sample', SampleBlockMacro
335
+ registry.block_macro SampleBlockMacro, 'sample'
336
+ registry.activate Asciidoctor::Document.new
284
337
  assert registry.block_macros?
285
- assert registry.processor_registered_for_block_macro? 'sample'
286
- processor = registry.load_block_macro_processor 'sample', Asciidoctor::Document.new
287
- assert processor.is_a? SampleBlockMacro
338
+ assert registry.registered_for_block_macro? 'sample'
339
+ extension = registry.find_block_macro_extension 'sample'
340
+ assert extension.is_a? Asciidoctor::Extensions::ProcessorExtension
341
+ assert extension.instance.is_a? SampleBlockMacro
342
+ assert extension.process_method.is_a? ::Method
288
343
  end
289
344
 
290
345
  test 'should instantiate inline macro processor' do
291
346
  registry = Asciidoctor::Extensions::Registry.new
292
- registry.inline_macro 'sample', SampleInlineMacro
347
+ registry.inline_macro SampleInlineMacro, 'sample'
348
+ registry.activate Asciidoctor::Document.new
293
349
  assert registry.inline_macros?
294
- assert registry.processor_registered_for_inline_macro? 'sample'
295
- processor = registry.load_inline_macro_processor 'sample', Asciidoctor::Document.new
296
- assert processor.is_a? SampleInlineMacro
350
+ assert registry.registered_for_inline_macro? 'sample'
351
+ extension = registry.find_inline_macro_extension 'sample'
352
+ assert extension.is_a? Asciidoctor::Extensions::ProcessorExtension
353
+ assert extension.instance.is_a? SampleInlineMacro
354
+ assert extension.process_method.is_a? ::Method
297
355
  end
298
356
 
299
357
  test 'should allow processors to be registered by a string name' do
300
358
  registry = Asciidoctor::Extensions::Registry.new
301
359
  registry.preprocessor 'SamplePreprocessor'
360
+ registry.activate Asciidoctor::Document.new
302
361
  assert registry.preprocessors?
303
- processors = registry.load_preprocessors Asciidoctor::Document.new
304
- assert_equal 1, processors.size
305
- assert processors.first.is_a? SamplePreprocessor
362
+ extensions = registry.preprocessors
363
+ assert_equal 1, extensions.size
364
+ assert extensions.first.is_a? Asciidoctor::Extensions::ProcessorExtension
306
365
  end
307
366
  end
308
367
 
@@ -317,11 +376,13 @@ sample content
317
376
  EOS
318
377
 
319
378
  begin
320
- Asciidoctor::Extensions.register do |document|
379
+ Asciidoctor::Extensions.register do
321
380
  preprocessor ScrubHeaderPreprocessor
322
381
  end
323
382
 
324
383
  doc = document_from_string input
384
+ assert doc.attr? 'skipped'
385
+ assert_equal 'junk line', (doc.attr 'skipped').strip
325
386
  assert doc.has_header?
326
387
  assert_equal 'Document Title', doc.doctitle
327
388
  ensure
@@ -339,7 +400,7 @@ after
339
400
  EOS
340
401
 
341
402
  begin
342
- Asciidoctor::Extensions.register do |document|
403
+ Asciidoctor::Extensions.register do
343
404
  include_processor BoilerplateTextIncludeProcessor
344
405
  end
345
406
 
@@ -352,6 +413,39 @@ after
352
413
  Asciidoctor::Extensions.unregister_all
353
414
  end
354
415
  end
416
+
417
+ test 'should call include processor to process include directive' do
418
+ input = <<-EOS
419
+ first line
420
+
421
+ include::include-file.asciidoc[]
422
+
423
+ last line
424
+ EOS
425
+
426
+ # Safe Mode is not required here
427
+ document = empty_document :base_dir => File.expand_path(File.dirname(__FILE__))
428
+ document.extensions.include_processor do
429
+ process do |doc, reader, target, attributes|
430
+ # demonstrate that push_include normalizes endlines
431
+ content = ["include target:: #{target}\n", "\n", "middle line\n"]
432
+ reader.push_include content, target, target, 1, attributes
433
+ end
434
+ end
435
+ reader = Asciidoctor::PreprocessorReader.new document, input
436
+ lines = []
437
+ lines << reader.read_line
438
+ lines << reader.read_line
439
+ lines << reader.read_line
440
+ assert_equal 'include target:: include-file.asciidoc', lines.last
441
+ assert_equal 'include-file.asciidoc: line 2', reader.line_info
442
+ while reader.has_more_lines?
443
+ lines << reader.read_line
444
+ end
445
+ source = lines * ::Asciidoctor::EOL
446
+ assert_match(/^include target:: include-file.asciidoc$/, source)
447
+ assert_match(/^middle line$/, source)
448
+ end
355
449
 
356
450
  test 'should invoke treeprocessors after parsing document' do
357
451
  input = <<-EOS
@@ -362,7 +456,7 @@ content
362
456
  EOS
363
457
 
364
458
  begin
365
- Asciidoctor::Extensions.register do |document|
459
+ Asciidoctor::Extensions.register do
366
460
  treeprocessor ReplaceAuthorTreeprocessor
367
461
  end
368
462
 
@@ -373,6 +467,26 @@ content
373
467
  end
374
468
  end
375
469
 
470
+ test 'should allow treeprocessor to replace tree' do
471
+ input = <<-EOS
472
+ = Original Document
473
+ Doc Writer
474
+
475
+ content
476
+ EOS
477
+
478
+ begin
479
+ Asciidoctor::Extensions.register do
480
+ treeprocessor ReplaceTreeTreeprocessor
481
+ end
482
+
483
+ doc = document_from_string input
484
+ assert_equal 'Replacement Document', doc.doctitle
485
+ ensure
486
+ Asciidoctor::Extensions.unregister_all
487
+ end
488
+ end
489
+
376
490
  test 'should invoke postprocessors after rendering document' do
377
491
  input = <<-EOS
378
492
  * one
@@ -381,12 +495,12 @@ content
381
495
  EOS
382
496
 
383
497
  begin
384
- Asciidoctor::Extensions.register do |document|
498
+ Asciidoctor::Extensions.register do
385
499
  postprocessor StripAttributesPostprocessor
386
500
  end
387
501
 
388
502
  output = render_string input
389
- assert_no_match(/<div class="ulist">/, output)
503
+ refute_match(/<div class="ulist">/, output)
390
504
  ensure
391
505
  Asciidoctor::Extensions.unregister_all
392
506
  end
@@ -399,8 +513,8 @@ Hi there!
399
513
  EOS
400
514
 
401
515
  begin
402
- Asciidoctor::Extensions.register do |document|
403
- block :yell, UppercaseBlock
516
+ Asciidoctor::Extensions.register do
517
+ block UppercaseBlock
404
518
  end
405
519
 
406
520
  output = render_embedded_string input
@@ -417,8 +531,8 @@ snippet::12345[]
417
531
  EOS
418
532
 
419
533
  begin
420
- Asciidoctor::Extensions.register do |document|
421
- block_macro :snippet, SnippetMacro
534
+ Asciidoctor::Extensions.register do
535
+ block_macro SnippetMacro, :snippet
422
536
  end
423
537
 
424
538
  output = render_embedded_string input
@@ -429,20 +543,76 @@ snippet::12345[]
429
543
  end
430
544
 
431
545
  test 'should invoke processor for custom inline macro' do
432
- input = <<-EOS
433
- Room temperature is degrees:25[].
434
- EOS
435
-
436
546
  begin
437
- Asciidoctor::Extensions.register do |document|
438
- inline_macro :degrees, TemperatureMacro
547
+ Asciidoctor::Extensions.register do
548
+ inline_macro TemperatureMacro, :degrees
439
549
  end
440
550
 
441
- output = render_embedded_string input, :attributes => {'temperature-unit' => 'F'}
551
+ output = render_embedded_string 'Room temperature is degrees:25[C].', :attributes => {'temperature-unit' => 'F'}
552
+ assert output.include?('Room temperature is 25.0 &#176;C.')
553
+
554
+ output = render_embedded_string 'Room temperature is degrees:25[].', :attributes => {'temperature-unit' => 'F'}
442
555
  assert output.include?('Room temperature is 77.0 &#176;F.')
443
556
  ensure
444
557
  Asciidoctor::Extensions.unregister_all
445
558
  end
446
559
  end
560
+
561
+ test 'should not carry over attributes if block processor returns nil' do
562
+ begin
563
+ Asciidoctor::Extensions.register do
564
+ block do
565
+ named :skip
566
+ on_context :paragraph
567
+ parse_content_as :raw
568
+ process do |parent, reader, attrs|
569
+ nil
570
+ end
571
+ end
572
+ end
573
+ input = <<-EOS
574
+ .unused title
575
+ [skip]
576
+ not rendered
577
+
578
+ --
579
+ rendered
580
+ --
581
+ EOS
582
+ doc = document_from_string input
583
+ assert_equal 1, doc.blocks.size
584
+ assert_nil doc.blocks[0].attributes['title']
585
+ ensure
586
+ Asciidoctor::Extensions.unregister_all
587
+ end
588
+ end
589
+
590
+ test 'should pass attributes by value to block processor' do
591
+ begin
592
+ Asciidoctor::Extensions.register do
593
+ block do
594
+ named :foo
595
+ on_context :paragraph
596
+ parse_content_as :raw
597
+ process do |parent, reader, attrs|
598
+ original_attrs = attrs.dup
599
+ attrs.delete('title')
600
+ create_paragraph parent, reader.read_lines, original_attrs.merge('id' => 'value')
601
+ end
602
+ end
603
+ end
604
+ input = <<-EOS
605
+ .title
606
+ [foo]
607
+ content
608
+ EOS
609
+ doc = document_from_string input
610
+ assert_equal 1, doc.blocks.size
611
+ assert_equal 'title', doc.blocks[0].attributes['title']
612
+ assert_equal 'value', doc.blocks[0].id
613
+ ensure
614
+ Asciidoctor::Extensions.unregister_all
615
+ end
616
+ end
447
617
  end
448
618
  end