asciidoctor 1.5.6.2 → 1.5.7

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 (112) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +330 -143
  3. data/README-fr.adoc +441 -0
  4. data/README-jp.adoc +418 -0
  5. data/README-zh_CN.adoc +430 -0
  6. data/README.adoc +454 -0
  7. data/Rakefile +57 -0
  8. data/asciidoctor.gemspec +7 -1
  9. data/data/locale/attributes-ar.adoc +22 -0
  10. data/data/locale/attributes-bg.adoc +22 -0
  11. data/data/locale/attributes-ca.adoc +22 -0
  12. data/data/locale/attributes-cs.adoc +22 -0
  13. data/data/locale/attributes-da.adoc +22 -0
  14. data/data/locale/attributes-de.adoc +22 -0
  15. data/data/locale/attributes-en.adoc +23 -0
  16. data/data/locale/attributes-es.adoc +22 -0
  17. data/data/locale/attributes-fa.adoc +22 -0
  18. data/data/locale/attributes-fi.adoc +22 -0
  19. data/data/locale/attributes-fr.adoc +22 -0
  20. data/data/locale/attributes-hu.adoc +22 -0
  21. data/data/locale/attributes-id.adoc +22 -0
  22. data/data/locale/attributes-it.adoc +22 -0
  23. data/data/locale/attributes-ja.adoc +22 -0
  24. data/data/locale/attributes-kr.adoc +22 -0
  25. data/data/locale/attributes-nb.adoc +22 -0
  26. data/data/locale/attributes-nl.adoc +22 -0
  27. data/data/locale/attributes-nn.adoc +22 -0
  28. data/data/locale/attributes-pl.adoc +22 -0
  29. data/data/locale/attributes-pt.adoc +22 -0
  30. data/data/locale/attributes-pt_BR.adoc +22 -0
  31. data/data/locale/attributes-ro.adoc +22 -0
  32. data/data/locale/attributes-ru.adoc +22 -0
  33. data/data/locale/attributes-sr.adoc +22 -0
  34. data/data/locale/attributes-sr_Latn.adoc +22 -0
  35. data/data/locale/attributes-tr.adoc +22 -0
  36. data/data/locale/attributes-uk.adoc +22 -0
  37. data/data/locale/attributes-zh_CN.adoc +22 -0
  38. data/data/locale/attributes-zh_TW.adoc +22 -0
  39. data/data/locale/attributes.adoc +8 -649
  40. data/data/stylesheets/asciidoctor-default.css +77 -72
  41. data/features/xref.feature +366 -7
  42. data/lib/asciidoctor.rb +107 -93
  43. data/lib/asciidoctor/abstract_block.rb +247 -239
  44. data/lib/asciidoctor/abstract_node.rb +56 -58
  45. data/lib/asciidoctor/block.rb +3 -3
  46. data/lib/asciidoctor/callouts.rb +1 -1
  47. data/lib/asciidoctor/cli/invoker.rb +36 -9
  48. data/lib/asciidoctor/cli/options.rb +63 -25
  49. data/lib/asciidoctor/converter.rb +23 -13
  50. data/lib/asciidoctor/converter/base.rb +4 -0
  51. data/lib/asciidoctor/converter/docbook45.rb +16 -9
  52. data/lib/asciidoctor/converter/docbook5.rb +115 -97
  53. data/lib/asciidoctor/converter/factory.rb +29 -31
  54. data/lib/asciidoctor/converter/html5.rb +229 -192
  55. data/lib/asciidoctor/converter/manpage.rb +72 -50
  56. data/lib/asciidoctor/converter/template.rb +12 -12
  57. data/lib/asciidoctor/core_ext.rb +5 -1
  58. data/lib/asciidoctor/core_ext/1.8.7/base64/strict_encode64.rb +6 -0
  59. data/lib/asciidoctor/document.rb +168 -77
  60. data/lib/asciidoctor/extensions.rb +79 -47
  61. data/lib/asciidoctor/helpers.rb +33 -11
  62. data/lib/asciidoctor/inline.rb +3 -2
  63. data/lib/asciidoctor/list.rb +2 -1
  64. data/lib/asciidoctor/logging.rb +122 -0
  65. data/lib/asciidoctor/parser.rb +406 -382
  66. data/lib/asciidoctor/path_resolver.rb +169 -162
  67. data/lib/asciidoctor/reader.rb +166 -121
  68. data/lib/asciidoctor/section.rb +45 -28
  69. data/lib/asciidoctor/stylesheets.rb +13 -5
  70. data/lib/asciidoctor/substitutors.rb +328 -254
  71. data/lib/asciidoctor/table.rb +105 -48
  72. data/lib/asciidoctor/timings.rb +34 -6
  73. data/lib/asciidoctor/version.rb +1 -1
  74. data/man/asciidoctor.1 +41 -23
  75. data/man/asciidoctor.adoc +14 -8
  76. data/test/api_test.rb +1004 -0
  77. data/test/attributes_test.rb +241 -50
  78. data/test/blocks_test.rb +549 -124
  79. data/test/converter_test.rb +170 -78
  80. data/test/document_test.rb +208 -767
  81. data/test/extensions_test.rb +188 -53
  82. data/test/fixtures/custom-backends/slim/html5/block_paragraph.html.slim +1 -1
  83. data/test/fixtures/custom-backends/slim/html5/block_sidebar.html.slim +1 -1
  84. data/test/fixtures/file-with-missing-include.adoc +1 -0
  85. data/test/fixtures/include-file.jsx +8 -0
  86. data/test/fixtures/lists.adoc +96 -0
  87. data/test/fixtures/other-chapters.adoc +11 -0
  88. data/test/fixtures/outer-include.adoc +5 -0
  89. data/test/fixtures/sample.asciidoc +5 -1
  90. data/test/fixtures/subdir/index.adoc +3 -0
  91. data/test/fixtures/subdir/inner-include.adoc +3 -0
  92. data/test/fixtures/subdir/middle-include.adoc +5 -0
  93. data/test/fixtures/tagged-class-enclosed.rb +0 -1
  94. data/test/fixtures/unclosed-tag.adoc +3 -0
  95. data/test/fixtures/unexpected-end-tag.adoc +4 -0
  96. data/test/invoker_test.rb +101 -40
  97. data/test/links_test.rb +266 -72
  98. data/test/lists_test.rb +243 -45
  99. data/test/logger_test.rb +211 -0
  100. data/test/manpage_test.rb +124 -6
  101. data/test/options_test.rb +46 -1
  102. data/test/paragraphs_test.rb +23 -10
  103. data/test/parser_test.rb +30 -1
  104. data/test/paths_test.rb +115 -33
  105. data/test/preamble_test.rb +1 -1
  106. data/test/reader_test.rb +337 -81
  107. data/test/sections_test.rb +656 -72
  108. data/test/substitutions_test.rb +182 -57
  109. data/test/tables_test.rb +324 -57
  110. data/test/test_helper.rb +77 -32
  111. data/test/text_test.rb +7 -7
  112. metadata +67 -3
@@ -11,7 +11,7 @@ context 'Links' do
11
11
  end
12
12
 
13
13
  test 'qualified url with role inline with text' do
14
- assert_xpath "//a[@href='http://asciidoc.org'][@class='bare project'][text() = 'http://asciidoc.org']", render_string("The AsciiDoc project is located at http://asciidoc.org[,role=project].", :attributes => {'linkattrs' => ''})
14
+ assert_xpath "//a[@href='http://asciidoc.org'][@class='bare project'][text() = 'http://asciidoc.org']", render_string("The AsciiDoc project is located at http://asciidoc.org[role=project].")
15
15
  end
16
16
 
17
17
  test 'qualified http url inline with hide-uri-scheme set' do
@@ -43,7 +43,7 @@ context 'Links' do
43
43
  end
44
44
 
45
45
  test 'qualified url with role using link macro' do
46
- assert_xpath "//a[@href='http://asciidoc.org'][@class='bare project'][text() = 'http://asciidoc.org']", render_string("We're parsing link:http://asciidoc.org[,role=project] markup", :attributes => {'linkattrs' => ''})
46
+ assert_xpath "//a[@href='http://asciidoc.org'][@class='bare project'][text() = 'http://asciidoc.org']", render_string("We're parsing link:http://asciidoc.org[role=project] markup")
47
47
  end
48
48
 
49
49
  test 'qualified url using macro syntax with multi-line label inline with text' do
@@ -82,37 +82,57 @@ context 'Links' do
82
82
  end
83
83
 
84
84
  test 'qualified url with trailing round bracket' do
85
- assert_xpath '//a[@href="http://asciidoctor.org"][text()="http://asciidoctor.org"]', render_string('Asciidoctor is a Ruby-based AsciiDoc processor (see http://asciidoctor.org)'), 1
85
+ assert_xpath '//a[@href="https://asciidoctor.org"][text()="https://asciidoctor.org"]', render_string('Asciidoctor is a Ruby-based AsciiDoc processor (see https://asciidoctor.org)'), 1
86
86
  end
87
87
 
88
88
  test 'qualified url with trailing semi-colon' do
89
- assert_xpath '//a[@href="http://asciidoctor.org"][text()="http://asciidoctor.org"]', render_string('http://asciidoctor.org; where text gets parsed'), 1
89
+ assert_xpath '//a[@href="https://asciidoctor.org"][text()="https://asciidoctor.org"]', render_string('https://asciidoctor.org; where text gets parsed'), 1
90
90
  end
91
91
 
92
92
  test 'qualified url with trailing colon' do
93
- assert_xpath '//a[@href="http://asciidoctor.org"][text()="http://asciidoctor.org"]', render_string('http://asciidoctor.org: where text gets parsed'), 1
93
+ assert_xpath '//a[@href="https://asciidoctor.org"][text()="https://asciidoctor.org"]', render_string('https://asciidoctor.org: where text gets parsed'), 1
94
94
  end
95
95
 
96
96
  test 'qualified url in round brackets with trailing colon' do
97
- assert_xpath '//a[@href="http://asciidoctor.org"][text()="http://asciidoctor.org"]', render_string('(http://asciidoctor.org): where text gets parsed'), 1
97
+ assert_xpath '//a[@href="https://asciidoctor.org"][text()="https://asciidoctor.org"]', render_string('(https://asciidoctor.org): where text gets parsed'), 1
98
98
  end
99
99
 
100
100
  test 'qualified url with trailing round bracket followed by colon' do
101
- result = render_embedded_string '(from http://asciidoctor.org): where text gets parsed'
102
- assert_xpath '//a[@href="http://asciidoctor.org"][text()="http://asciidoctor.org"]', result, 1
103
- assert_xpath '//a[@href="http://asciidoctor.org"][text()="http://asciidoctor.org"]/preceding-sibling::text()[.="(from "]', result, 1
104
- assert_xpath '//a[@href="http://asciidoctor.org"][text()="http://asciidoctor.org"]/following-sibling::text()[.="): where text gets parsed"]', result, 1
101
+ result = render_embedded_string '(from https://asciidoctor.org): where text gets parsed'
102
+ assert_xpath '//a[@href="https://asciidoctor.org"][text()="https://asciidoctor.org"]', result, 1
103
+ assert_xpath '//a[@href="https://asciidoctor.org"][text()="https://asciidoctor.org"]/preceding-sibling::text()[.="(from "]', result, 1
104
+ assert_xpath '//a[@href="https://asciidoctor.org"][text()="https://asciidoctor.org"]/following-sibling::text()[.="): where text gets parsed"]', result, 1
105
105
  end
106
106
 
107
107
  test 'qualified url in round brackets with trailing semi-colon' do
108
- assert_xpath '//a[@href="http://asciidoctor.org"][text()="http://asciidoctor.org"]', render_string('(http://asciidoctor.org); where text gets parsed'), 1
108
+ assert_xpath '//a[@href="https://asciidoctor.org"][text()="https://asciidoctor.org"]', render_string('(https://asciidoctor.org); where text gets parsed'), 1
109
109
  end
110
110
 
111
111
  test 'qualified url with trailing round bracket followed by semi-colon' do
112
- result = render_embedded_string '(from http://asciidoctor.org); where text gets parsed'
113
- assert_xpath '//a[@href="http://asciidoctor.org"][text()="http://asciidoctor.org"]', result, 1
114
- assert_xpath '//a[@href="http://asciidoctor.org"][text()="http://asciidoctor.org"]/preceding-sibling::text()[.="(from "]', result, 1
115
- assert_xpath '//a[@href="http://asciidoctor.org"][text()="http://asciidoctor.org"]/following-sibling::text()[.="); where text gets parsed"]', result, 1
112
+ result = render_embedded_string '(from https://asciidoctor.org); where text gets parsed'
113
+ assert_xpath '//a[@href="https://asciidoctor.org"][text()="https://asciidoctor.org"]', result, 1
114
+ assert_xpath '//a[@href="https://asciidoctor.org"][text()="https://asciidoctor.org"]/preceding-sibling::text()[.="(from "]', result, 1
115
+ assert_xpath '//a[@href="https://asciidoctor.org"][text()="https://asciidoctor.org"]/following-sibling::text()[.="); where text gets parsed"]', result, 1
116
+ end
117
+
118
+ test 'URI scheme with trailing characters should not be converted to a link' do
119
+ input_sources = %w(
120
+ (https://)
121
+ http://;
122
+ file://:
123
+ <ftp://>
124
+ )
125
+ expected_outputs = %w(
126
+ (https://)
127
+ http://;
128
+ file://:
129
+ &lt;ftp://&gt;
130
+ )
131
+ input_sources.each_with_index do |input_source, i|
132
+ expected_output = expected_outputs[i]
133
+ actual = block_from_string input_source
134
+ assert_equal expected_output, actual.content
135
+ end
116
136
  end
117
137
 
118
138
  test 'qualified url containing round brackets' do
@@ -176,26 +196,35 @@ context 'Links' do
176
196
  assert_xpath '//a[@href="https://github.com/asciidoctor"]', render_string('Asciidoctor GitHub organization: <**https://github.com/asciidoctor**>'), 1
177
197
  end
178
198
 
179
- test 'link with quoted text should not be separated into attributes when linkattrs is set' do
180
- assert_xpath '//a[@href="http://search.example.com"][text()="Google, Yahoo, Bing = Search Engines"]', render_embedded_string('http://search.example.com["Google, Yahoo, Bing = Search Engines"]', :attributes => {'linkattrs' => ''}), 1
199
+ test 'link with quoted text should not be separated into attributes when text contains an equal sign' do
200
+ assert_xpath '//a[@href="http://search.example.com"][text()="Google, Yahoo, Bing = Search Engines"]', render_embedded_string('http://search.example.com["Google, Yahoo, Bing = Search Engines"]'), 1
201
+ end
202
+
203
+ test 'link with quoted text but no equal sign should carry quotes over to output' do
204
+ assert_xpath %(//a[@href="http://search.example.com"][text()='"Google, Yahoo, Bing"']), render_embedded_string('http://search.example.com["Google, Yahoo, Bing"]'), 1
181
205
  end
182
206
 
183
- test 'link with comma in text but no equal sign should not be separated into attributes when linkattrs is set' do
184
- assert_xpath '//a[@href="http://search.example.com"][text()="Google, Yahoo, Bing"]', render_embedded_string('http://search.example.com[Google, Yahoo, Bing]', :attributes => {'linkattrs' => ''}), 1
207
+ test 'link with comma in text but no equal sign should not be separated into attributes' do
208
+ assert_xpath '//a[@href="http://search.example.com"][text()="Google, Yahoo, Bing"]', render_embedded_string('http://search.example.com[Google, Yahoo, Bing]'), 1
185
209
  end
186
210
 
187
- test 'role and window attributes on link are processed when linkattrs is set' do
188
- assert_xpath '//a[@href="http://google.com"][@class="external"][@target="_blank"]', render_embedded_string('http://google.com[Google, role="external", window="_blank"]', :attributes => {'linkattrs' => ''}), 1
211
+ test 'role and window attributes on link are processed' do
212
+ assert_xpath '//a[@href="http://google.com"][@class="external"][@target="_blank"]', render_embedded_string('http://google.com[Google, role=external, window="_blank"]'), 1
213
+ end
214
+
215
+ test 'link macro with attributes but no text should use URL as text' do
216
+ url = 'https://fonts.googleapis.com/css?family=Roboto:400,400italic,'
217
+ assert_xpath %(//a[@href="#{url}"][text()="#{url}"]), render_embedded_string(%(link:#{url}[family=Roboto,weight=400])), 1
189
218
  end
190
219
 
191
- test 'link macro with attributes but no text should use URL as text when linkattrs is set' do
220
+ test 'link macro with attributes but blank text should use URL as text' do
192
221
  url = 'https://fonts.googleapis.com/css?family=Roboto:400,400italic,'
193
- assert_xpath %(//a[@href="#{url}"][text()="#{url}"]), render_embedded_string(%(link:#{url}[family=Roboto,weight=400]), :attributes => {'linkattrs' => ''}), 1
222
+ assert_xpath %(//a[@href="#{url}"][text()="#{url}"]), render_embedded_string(%(link:#{url}[,family=Roboto,weight=400])), 1
194
223
  end
195
224
 
196
- test 'link macro with comma but no explicit attributes in text should not parse text when linkattrs is set' do
225
+ test 'link macro with comma but no explicit attributes in text should not parse text' do
197
226
  url = 'https://fonts.googleapis.com/css?family=Roboto:400,400italic,'
198
- assert_xpath %(//a[@href="#{url}"][text()="Roboto,400"]), render_embedded_string(%(link:#{url}[Roboto,400]), :attributes => {'linkattrs' => ''}), 1
227
+ assert_xpath %(//a[@href="#{url}"][text()="Roboto,400"]), render_embedded_string(%(link:#{url}[Roboto,400])), 1
199
228
  end
200
229
 
201
230
  test 'link text that ends in ^ should set link window to _blank' do
@@ -207,21 +236,25 @@ context 'Links' do
207
236
  end
208
237
 
209
238
  test 'rel=noopener should be added to a link that targets a named window when the noopener option is set' do
210
- assert_xpath '//a[@href="http://google.com"][@target="name"][@rel="noopener"]', render_embedded_string('http://google.com[Google,window=name,opts=noopener]', :attributes => {'linkattrs' => ''}), 1
239
+ assert_xpath '//a[@href="http://google.com"][@target="name"][@rel="noopener"]', render_embedded_string('http://google.com[Google,window=name,opts=noopener]'), 1
211
240
  end
212
241
 
213
242
  test 'rel=noopener should not be added to a link if it does not target a window' do
214
- result = render_embedded_string 'http://google.com[Google,opts=noopener]', :attributes => {'linkattrs' => ''}
243
+ result = render_embedded_string 'http://google.com[Google,opts=noopener]'
215
244
  assert_xpath '//a[@href="http://google.com"]', result, 1
216
245
  assert_xpath '//a[@href="http://google.com"][@rel="noopener"]', result, 0
217
246
  end
218
247
 
219
- test 'id attribute on link are processed when linkattrs is set' do
220
- assert_xpath '//a[@href="http://google.com"][@id="link-1"]', render_embedded_string('http://google.com[Google, id="link-1"]', :attributes => {'linkattrs' => ''}), 1
248
+ test 'rel=nofollow should be added to a link when the nofollow option is set' do
249
+ assert_xpath '//a[@href="http://google.com"][@target="name"][@rel="nofollow noopener"]', render_embedded_string('http://google.com[Google,window=name,opts="nofollow,noopener"]'), 1
221
250
  end
222
251
 
223
- test 'title attribute on link are processed when linkattrs is set' do
224
- assert_xpath '//a[@href="http://google.com"][@title="title-1"]', render_embedded_string('http://google.com[Google, title="title-1"]', :attributes => {'linkattrs' => ''}), 1
252
+ test 'id attribute on link is processed' do
253
+ assert_xpath '//a[@href="http://google.com"][@id="link-1"]', render_embedded_string('http://google.com[Google, id="link-1"]'), 1
254
+ end
255
+
256
+ test 'title attribute on link is processed' do
257
+ assert_xpath '//a[@href="http://google.com"][@title="title-1"]', render_embedded_string('http://google.com[Google, title="title-1"]'), 1
225
258
  end
226
259
 
227
260
  test 'inline irc link' do
@@ -236,9 +269,9 @@ context 'Links' do
236
269
  variations = %w([[tigers]] anchor:tigers[])
237
270
  variations.each do |anchor|
238
271
  doc = document_from_string %(Here you can read about tigers.#{anchor})
239
- output = doc.render
272
+ output = doc.convert
240
273
  assert_equal '[tigers]', doc.catalog[:ids]['tigers']
241
- assert doc.catalog[:refs]['tigers'].is_a? Asciidoctor::Inline
274
+ assert_kind_of Asciidoctor::Inline, doc.catalog[:refs]['tigers']
242
275
  assert_nil doc.catalog[:refs]['tigers'].text
243
276
  assert_xpath '//a[@id = "tigers"]', output, 1
244
277
  assert_xpath '//a[@id = "tigers"]/child::text()', output, 0
@@ -249,7 +282,7 @@ context 'Links' do
249
282
  variations = %w([[tigers]] anchor:tigers[])
250
283
  variations.each do |anchor|
251
284
  doc = document_from_string %(Here you can read about tigers.\\#{anchor})
252
- output = doc.render
285
+ output = doc.convert
253
286
  refute doc.catalog[:ids].key?('tigers')
254
287
  refute doc.catalog[:refs].key?('tigers')
255
288
  assert_xpath '//a[@id = "tigers"]', output, 0
@@ -272,9 +305,9 @@ context 'Links' do
272
305
  test 'inline ref with reftext' do
273
306
  %w([[tigers,Tigers]] anchor:tigers[Tigers]).each do |anchor|
274
307
  doc = document_from_string %(Here you can read about tigers.#{anchor})
275
- output = doc.render
308
+ output = doc.convert
276
309
  assert_equal 'Tigers', doc.catalog[:ids]['tigers']
277
- assert doc.catalog[:refs]['tigers'].is_a? Asciidoctor::Inline
310
+ assert_kind_of Asciidoctor::Inline, doc.catalog[:refs]['tigers']
278
311
  assert_equal 'Tigers', doc.catalog[:refs]['tigers'].text
279
312
  assert_xpath '//a[@id = "tigers"]', output, 1
280
313
  assert_xpath '//a[@id = "tigers"]/child::text()', output, 0
@@ -290,8 +323,8 @@ context 'Links' do
290
323
  test 'should substitute attribute references in reftext when registering inline ref' do
291
324
  %w([[tigers,{label-tigers}]] anchor:tigers[{label-tigers}]).each do |anchor|
292
325
  doc = document_from_string %(Here you can read about tigers.#{anchor}), :attributes => { 'label-tigers' => 'Tigers' }
293
- doc.render
294
- assert doc.catalog[:refs]['tigers'].is_a? Asciidoctor::Inline
326
+ doc.convert
327
+ assert_kind_of Asciidoctor::Inline, doc.catalog[:refs]['tigers']
295
328
  assert_equal 'Tigers', doc.catalog[:refs]['tigers'].text
296
329
  assert_equal 'Tigers', doc.catalog[:ids]['tigers']
297
330
  end
@@ -301,7 +334,7 @@ context 'Links' do
301
334
  %w([[tigers,<Tigers>]] anchor:tigers[<Tigers>]).each do |anchor|
302
335
  doc = document_from_string %(Here you can read about tigers.#{anchor}), :backend => :docbook45
303
336
  output = doc.convert :header_footer => false
304
- assert doc.catalog[:refs]['tigers'].is_a? Asciidoctor::Inline
337
+ assert_kind_of Asciidoctor::Inline, doc.catalog[:refs]['tigers']
305
338
  assert_equal '<Tigers>', doc.catalog[:refs]['tigers'].text
306
339
  assert_equal '<Tigers>', doc.references[:ids]['tigers']
307
340
  assert_includes output, '<anchor id="tigers" xreflabel="&lt;Tigers&gt;"/>'
@@ -349,13 +382,13 @@ anchor:foo[b[a\]r]text'
349
382
  test 'xref using angled bracket syntax' do
350
383
  doc = document_from_string '<<tigers>>'
351
384
  doc.register :refs, ['tigers', (Asciidoctor::Inline.new doc, :anchor, '[tigers]', :type => :ref, :target => 'tigers'), '[tigers]']
352
- assert_xpath '//a[@href="#tigers"][text() = "[tigers]"]', doc.render, 1
385
+ assert_xpath '//a[@href="#tigers"][text() = "[tigers]"]', doc.convert, 1
353
386
  end
354
387
 
355
388
  test 'xref using angled bracket syntax with explicit hash' do
356
389
  doc = document_from_string '<<#tigers>>'
357
390
  doc.register :refs, ['tigers', (Asciidoctor::Inline.new doc, :anchor, 'Tigers', :type => :ref, :target => 'tigers'), 'Tigers']
358
- assert_xpath '//a[@href="#tigers"][text() = "Tigers"]', doc.render, 1
391
+ assert_xpath '//a[@href="#tigers"][text() = "Tigers"]', doc.convert, 1
359
392
  end
360
393
 
361
394
  test 'xref using angled bracket syntax with label' do
@@ -378,14 +411,26 @@ anchor:foo[b[a\]r]text'
378
411
  assert_xpath %q(//a[@href="#tigers"][text() = '"About Tigers"']), render_string(input), 1
379
412
  end
380
413
 
414
+ test 'should not interpret path sans extension in xref with angled bracket syntax in compat mode' do
415
+ using_memory_logger do |logger|
416
+ doc = document_from_string '<<tigers#>>', :header_footer => false, :attributes => { 'compat-mode' => '' }
417
+ assert_xpath '//a[@href="#tigers#"][text() = "[tigers#]"]', doc.convert, 1
418
+ end
419
+ end
420
+
381
421
  test 'xref using angled bracket syntax with path sans extension' do
382
422
  doc = document_from_string '<<tigers#>>', :header_footer => false
383
- assert_xpath '//a[@href="tigers.html"][text() = "tigers.html"]', doc.render, 1
423
+ assert_xpath '//a[@href="tigers.html"][text() = "tigers.html"]', doc.convert, 1
384
424
  end
385
425
 
386
- test 'inter-document xref should not truncate after period if path has no extension' do
387
- result = render_embedded_string '<<using-.net-web-services#,Using .NET web services>>'
388
- assert_xpath '//a[@href="using-.net-web-services.html"][text() = "Using .NET web services"]', result, 1
426
+ test 'inter-document xref should not add suffix to path with a non-AsciiDoc extension' do
427
+ {
428
+ 'using-.net-web-services' => 'Using .NET web services',
429
+ '../file.pdf' => 'Download the .pdf file'
430
+ }.each do |path, text|
431
+ result = render_embedded_string %(<<#{path}#,#{text}>>)
432
+ assert_xpath %(//a[@href="#{path}"][text() = "#{text}"]), result, 1
433
+ end
389
434
  end
390
435
 
391
436
  test 'inter-document xref should only remove the file extension part if the path contains a period elsewhere' do
@@ -395,52 +440,94 @@ anchor:foo[b[a\]r]text'
395
440
 
396
441
  test 'xref using angled bracket syntax with path sans extension using docbook backend' do
397
442
  doc = document_from_string '<<tigers#>>', :header_footer => false, :backend => 'docbook'
398
- assert_match '<link xl:href="tigers.xml">tigers.xml</link>', doc.render, 1
443
+ assert_match '<link xl:href="tigers.xml">tigers.xml</link>', doc.convert, 1
399
444
  doc = document_from_string '<<tigers#>>', :header_footer => false, :backend => 'docbook45'
400
- assert_match '<ulink url="tigers.xml">tigers.xml</ulink>', doc.render, 1
445
+ assert_match '<ulink url="tigers.xml">tigers.xml</ulink>', doc.convert, 1
401
446
  end
402
447
 
403
448
  test 'xref using angled bracket syntax with ancestor path sans extension' do
404
449
  doc = document_from_string '<<../tigers#,tigers>>', :header_footer => false
405
- assert_xpath '//a[@href="../tigers.html"][text() = "tigers"]', doc.render, 1
450
+ assert_xpath '//a[@href="../tigers.html"][text() = "tigers"]', doc.convert, 1
406
451
  end
407
452
 
408
453
  test 'xref using angled bracket syntax with absolute path sans extension' do
409
454
  doc = document_from_string '<</path/to/tigers#,tigers>>', :header_footer => false
410
- assert_xpath '//a[@href="/path/to/tigers.html"][text() = "tigers"]', doc.render, 1
455
+ assert_xpath '//a[@href="/path/to/tigers.html"][text() = "tigers"]', doc.convert, 1
411
456
  end
412
457
 
413
458
  test 'xref using angled bracket syntax with path and extension' do
459
+ using_memory_logger do |logger|
460
+ doc = document_from_string '<<tigers.adoc>>', :header_footer => false
461
+ assert_xpath '//a[@href="#tigers.adoc"][text() = "[tigers.adoc]"]', doc.convert, 1
462
+ end
463
+ end
464
+
465
+ test 'xref using angled bracket syntax with path and extension with hash' do
414
466
  doc = document_from_string '<<tigers.adoc#>>', :header_footer => false
415
- assert_xpath '//a[@href="tigers.html"][text() = "tigers.html"]', doc.render, 1
467
+ assert_xpath '//a[@href="tigers.html"][text() = "tigers.html"]', doc.convert, 1
468
+ end
469
+
470
+ test 'xref using angled bracket syntax with path and extension with fragment' do
471
+ doc = document_from_string '<<tigers.adoc#id>>', :header_footer => false
472
+ assert_xpath '//a[@href="tigers.html#id"][text() = "tigers.html"]', doc.convert, 1
473
+ end
474
+
475
+ test 'xref using macro syntax with path and extension in compat mode' do
476
+ using_memory_logger do |logger|
477
+ doc = document_from_string 'xref:tigers.adoc[]', :header_footer => false, :attributes => { 'compat-mode' => '' }
478
+ assert_xpath '//a[@href="#tigers.adoc"][text() = "[tigers.adoc]"]', doc.convert, 1
479
+ end
480
+ end
481
+
482
+ test 'xref using macro syntax with path and extension' do
483
+ doc = document_from_string 'xref:tigers.adoc[]', :header_footer => false
484
+ assert_xpath '//a[@href="tigers.html"][text() = "tigers.html"]', doc.convert, 1
416
485
  end
417
486
 
418
487
  test 'xref using angled bracket syntax with path and fragment' do
419
488
  doc = document_from_string '<<tigers#about>>', :header_footer => false
420
- assert_xpath '//a[@href="tigers.html#about"][text() = "tigers.html"]', doc.render, 1
489
+ assert_xpath '//a[@href="tigers.html#about"][text() = "tigers.html"]', doc.convert, 1
421
490
  end
422
491
 
423
492
  test 'xref using angled bracket syntax with path, fragment and text' do
424
493
  doc = document_from_string '<<tigers#about,About Tigers>>', :header_footer => false
425
- assert_xpath '//a[@href="tigers.html#about"][text() = "About Tigers"]', doc.render, 1
494
+ assert_xpath '//a[@href="tigers.html#about"][text() = "About Tigers"]', doc.convert, 1
426
495
  end
427
496
 
428
497
  test 'xref using angled bracket syntax with path and custom relfilesuffix and outfilesuffix' do
429
498
  attributes = {'relfileprefix' => '../', 'outfilesuffix' => '/'}
430
499
  doc = document_from_string '<<tigers#about,About Tigers>>', :header_footer => false, :attributes => attributes
431
- assert_xpath '//a[@href="../tigers/#about"][text() = "About Tigers"]', doc.render, 1
500
+ assert_xpath '//a[@href="../tigers/#about"][text() = "About Tigers"]', doc.convert, 1
501
+ end
502
+
503
+ test 'xref using angled bracket syntax with path and custom relfilesuffix' do
504
+ attributes = { 'relfilesuffix' => '/' }
505
+ doc = document_from_string '<<tigers#about,About Tigers>>', :header_footer => false, :attributes => attributes
506
+ assert_xpath '//a[@href="tigers/#about"][text() = "About Tigers"]', doc.convert, 1
432
507
  end
433
508
 
434
509
  test 'xref using angled bracket syntax with path which has been included in this document' do
435
- doc = document_from_string '<<tigers#about,About Tigers>>', :header_footer => false
436
- doc.catalog[:includes] << 'tigers'
437
- assert_xpath '//a[@href="#about"][text() = "About Tigers"]', doc.render, 1
510
+ using_memory_logger do |logger|
511
+ in_verbose_mode do
512
+ doc = document_from_string '<<tigers#about,About Tigers>>', :header_footer => false
513
+ doc.catalog[:includes]['tigers'] = true
514
+ output = doc.convert
515
+ assert_xpath '//a[@href="#about"][text() = "About Tigers"]', output, 1
516
+ assert_message logger, :WARN, 'invalid reference: about'
517
+ end
518
+ end
438
519
  end
439
520
 
440
521
  test 'xref using angled bracket syntax with nested path which has been included in this document' do
441
- doc = document_from_string '<<part1/tigers#about,About Tigers>>', :header_footer => false
442
- doc.catalog[:includes] << 'part1/tigers'
443
- assert_xpath '//a[@href="#about"][text() = "About Tigers"]', doc.render, 1
522
+ using_memory_logger do |logger|
523
+ in_verbose_mode do
524
+ doc = document_from_string '<<part1/tigers#about,About Tigers>>', :header_footer => false
525
+ doc.catalog[:includes]['part1/tigers'] = true
526
+ output = doc.convert
527
+ assert_xpath '//a[@href="#about"][text() = "About Tigers"]', output, 1
528
+ assert_message logger, :WARN, 'invalid reference: about'
529
+ end
530
+ end
444
531
  end
445
532
 
446
533
  test 'xref using angled bracket syntax inline with text' do
@@ -496,7 +583,7 @@ A summary of the first lesson.
496
583
  test 'xref using macro syntax' do
497
584
  doc = document_from_string 'xref:tigers[]'
498
585
  doc.register :refs, ['tigers', (Asciidoctor::Inline.new doc, :anchor, '[tigers]', :type => :ref, :target => 'tigers'), '[tigers]']
499
- assert_xpath '//a[@href="#tigers"][text() = "[tigers]"]', doc.render, 1
586
+ assert_xpath '//a[@href="#tigers"][text() = "[tigers]"]', doc.convert, 1
500
587
  end
501
588
 
502
589
  test 'multiple xref macros with implicit text in single line' do
@@ -517,7 +604,7 @@ This document has two sections, xref:sect-a[] and xref:sect-b[].
517
604
  test 'xref using macro syntax with explicit hash' do
518
605
  doc = document_from_string 'xref:#tigers[]'
519
606
  doc.register :refs, ['tigers', (Asciidoctor::Inline.new doc, :anchor, 'Tigers', :type => :ref, :target => 'tigers'), 'Tigers']
520
- assert_xpath '//a[@href="#tigers"][text() = "Tigers"]', doc.render, 1
607
+ assert_xpath '//a[@href="#tigers"][text() = "Tigers"]', doc.convert, 1
521
608
  end
522
609
 
523
610
  test 'xref using macro syntax with label' do
@@ -552,14 +639,24 @@ tigers]?
552
639
  assert_xpath %{//a[@href="#tigers"][normalize-space(text()) = "about tigers"]}, render_string(input), 1
553
640
  end
554
641
 
555
- test 'xref using macro syntax with text that contains an escaped closing bracket' do
642
+ test 'xref using macro syntax with text that ends with an escaped closing bracket' do
556
643
  input = <<-EOS
557
644
  xref:tigers[[tigers\\]]
558
645
 
559
646
  [#tigers]
560
647
  == Tigers
561
648
  EOS
562
- assert_xpath '//a[@href="#tigers"][text() = "[tigers]"]', render_string(input), 1
649
+ assert_xpath '//a[@href="#tigers"][text() = "[tigers]"]', render_embedded_string(input), 1
650
+ end
651
+
652
+ test 'xref using macro syntax with text that contains an escaped closing bracket' do
653
+ input = <<-EOS
654
+ xref:tigers[[tigers\\] are cats]
655
+
656
+ [#tigers]
657
+ == Tigers
658
+ EOS
659
+ assert_xpath '//a[@href="#tigers"][text() = "[tigers] are cats"]', render_embedded_string(input), 1
563
660
  end
564
661
 
565
662
  test 'unescapes square bracket in reftext used by xref' do
@@ -574,7 +671,7 @@ see <<foo>>'
574
671
  test 'xref using invalid macro syntax does not create link' do
575
672
  doc = document_from_string 'xref:tigers'
576
673
  doc.register :refs, ['tigers', (Asciidoctor::Inline.new doc, :anchor, 'Tigers', :type => :ref, :target => 'tigers'), 'Tigers']
577
- assert_xpath '//a', doc.render, 0
674
+ assert_xpath '//a', doc.convert, 0
578
675
  end
579
676
 
580
677
  test 'should warn and create link if verbose flag is set and reference is not found' do
@@ -586,14 +683,111 @@ see <<foo>>'
586
683
 
587
684
  See <<foobaz>>.
588
685
  EOS
589
- begin
590
- old_verbose, $VERBOSE = $VERBOSE, true
591
- output, warnings = redirect_streams {|_, err| [(render_embedded_string input), err.string] }
592
- assert_xpath '//a[@href="#foobaz"][text() = "[foobaz]"]', output, 1
593
- refute_empty warnings
594
- assert_includes warnings, 'asciidoctor: WARNING: invalid reference: foobaz'
595
- ensure
596
- $VERBOSE = old_verbose
686
+ using_memory_logger do |logger|
687
+ in_verbose_mode do
688
+ output = render_embedded_string input
689
+ assert_xpath '//a[@href="#foobaz"][text() = "[foobaz]"]', output, 1
690
+ assert_message logger, :WARN, 'invalid reference: foobaz'
691
+ end
692
+ end
693
+ end
694
+
695
+ test 'should warn and create link if verbose flag is set and reference using # notation is not found' do
696
+ input = <<-EOS
697
+ [#foobar]
698
+ == Foobar
699
+
700
+ == Section B
701
+
702
+ See <<#foobaz>>.
703
+ EOS
704
+ using_memory_logger do |logger|
705
+ in_verbose_mode do
706
+ output = render_embedded_string input
707
+ assert_xpath '//a[@href="#foobaz"][text() = "[foobaz]"]', output, 1
708
+ assert_message logger, :WARN, 'invalid reference: foobaz'
709
+ end
710
+ end
711
+ end
712
+
713
+ test 'should produce an internal anchor from an inter-document xref to file included into current file' do
714
+ input = <<-'EOS'
715
+ = Book Title
716
+ :doctype: book
717
+
718
+ [#ch1]
719
+ == Chapter 1
720
+
721
+ So it begins.
722
+
723
+ Read <<other-chapters.adoc#ch2>> to find out what happens next!
724
+
725
+ include::other-chapters.adoc[]
726
+ EOS
727
+
728
+ doc = document_from_string input, :safe => :safe, :base_dir => fixturedir
729
+ assert doc.catalog[:includes].key?('other-chapters')
730
+ assert doc.catalog[:includes]['other-chapters']
731
+ output = doc.convert
732
+ assert_xpath '//a[@href="#ch2"][text()="Chapter 2"]', output, 1
733
+ end
734
+
735
+ test 'should produce an internal anchor from an inter-document xref to file included entirely into current file using tags' do
736
+ input = <<-'EOS'
737
+ = Book Title
738
+ :doctype: book
739
+
740
+ [#ch1]
741
+ == Chapter 1
742
+
743
+ So it begins.
744
+
745
+ Read <<other-chapters.adoc#ch2>> to find out what happens next!
746
+
747
+ include::other-chapters.adoc[tags=**]
748
+ EOS
749
+
750
+ output = render_embedded_string input, :safe => :safe, :base_dir => fixturedir
751
+ assert_xpath '//a[@href="#ch2"][text()="Chapter 2"]', output, 1
752
+ end
753
+
754
+ test 'should not produce an internal anchor for inter-document xref to file partially included into current file' do
755
+ input = <<-'EOS'
756
+ = Book Title
757
+ :doctype: book
758
+
759
+ [#ch1]
760
+ == Chapter 1
761
+
762
+ So it begins.
763
+
764
+ Read <<other-chapters.adoc#ch2,the next chapter>> to find out what happens next!
765
+
766
+ include::other-chapters.adoc[tags=ch2]
767
+ EOS
768
+
769
+ doc = document_from_string input, :safe => :safe, :base_dir => fixturedir
770
+ assert doc.catalog[:includes].key?('other-chapters')
771
+ refute doc.catalog[:includes]['other-chapters']
772
+ output = doc.convert
773
+ assert_xpath '//a[@href="other-chapters.html#ch2"][text()="the next chapter"]', output, 1
774
+ end
775
+
776
+ test 'should warn and create link if debug mode is enabled, inter-document xref points to current doc, and reference not found' do
777
+ input = <<-EOS
778
+ [#foobar]
779
+ == Foobar
780
+
781
+ == Section B
782
+
783
+ See <<test.adoc#foobaz>>.
784
+ EOS
785
+ using_memory_logger do |logger|
786
+ in_verbose_mode do
787
+ output = render_embedded_string input, :attributes => { 'docname' => 'test' }
788
+ assert_xpath '//a[@href="#foobaz"][text() = "[foobaz]"]', output, 1
789
+ assert_message logger, :WARN, 'invalid reference: foobaz'
790
+ end
597
791
  end
598
792
  end
599
793