asciidoctor 1.5.8 → 2.0.0.rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +162 -17
  3. data/LICENSE +1 -1
  4. data/README-de.adoc +12 -13
  5. data/README-fr.adoc +11 -12
  6. data/README-jp.adoc +11 -12
  7. data/README-zh_CN.adoc +12 -13
  8. data/README.adoc +6 -7
  9. data/asciidoctor.gemspec +19 -24
  10. data/bin/asciidoctor +5 -4
  11. data/data/reference/syntax.adoc +283 -0
  12. data/data/stylesheets/asciidoctor-default.css +56 -52
  13. data/data/stylesheets/coderay-asciidoctor.css +7 -9
  14. data/lib/asciidoctor.rb +171 -232
  15. data/lib/asciidoctor/abstract_block.rb +96 -105
  16. data/lib/asciidoctor/abstract_node.rb +118 -139
  17. data/lib/asciidoctor/attribute_list.rb +10 -14
  18. data/lib/asciidoctor/block.rb +20 -19
  19. data/lib/asciidoctor/callouts.rb +4 -2
  20. data/lib/asciidoctor/cli.rb +3 -2
  21. data/lib/asciidoctor/cli/invoker.rb +14 -21
  22. data/lib/asciidoctor/cli/options.rb +64 -54
  23. data/lib/asciidoctor/converter.rb +357 -185
  24. data/lib/asciidoctor/converter/composite.rb +40 -48
  25. data/lib/asciidoctor/converter/docbook5.rb +604 -640
  26. data/lib/asciidoctor/converter/html5.rb +949 -963
  27. data/lib/asciidoctor/converter/manpage.rb +569 -548
  28. data/lib/asciidoctor/converter/template.rb +231 -272
  29. data/lib/asciidoctor/core_ext.rb +5 -18
  30. data/lib/asciidoctor/core_ext/float/truncate.rb +19 -0
  31. data/lib/asciidoctor/core_ext/match_data/names.rb +7 -0
  32. data/lib/asciidoctor/core_ext/nil_or_empty.rb +1 -0
  33. data/lib/asciidoctor/core_ext/regexp/is_match.rb +4 -2
  34. data/lib/asciidoctor/document.rb +399 -377
  35. data/lib/asciidoctor/extensions.rb +72 -140
  36. data/lib/asciidoctor/helpers.rb +122 -83
  37. data/lib/asciidoctor/inline.rb +5 -1
  38. data/lib/asciidoctor/list.rb +13 -11
  39. data/lib/asciidoctor/logging.rb +17 -16
  40. data/lib/asciidoctor/parser.rb +390 -423
  41. data/lib/asciidoctor/path_resolver.rb +10 -5
  42. data/lib/asciidoctor/reader.rb +286 -263
  43. data/lib/asciidoctor/rouge_ext.rb +39 -0
  44. data/lib/asciidoctor/section.rb +9 -8
  45. data/lib/asciidoctor/stylesheets.rb +19 -37
  46. data/lib/asciidoctor/substitutors.rb +364 -509
  47. data/lib/asciidoctor/syntax_highlighter.rb +238 -0
  48. data/lib/asciidoctor/syntax_highlighter/coderay.rb +87 -0
  49. data/lib/asciidoctor/syntax_highlighter/highlightjs.rb +26 -0
  50. data/lib/asciidoctor/syntax_highlighter/html_pipeline.rb +10 -0
  51. data/lib/asciidoctor/syntax_highlighter/prettify.rb +27 -0
  52. data/lib/asciidoctor/syntax_highlighter/pygments.rb +149 -0
  53. data/lib/asciidoctor/syntax_highlighter/rouge.rb +129 -0
  54. data/lib/asciidoctor/table.rb +73 -66
  55. data/lib/asciidoctor/timings.rb +4 -2
  56. data/lib/asciidoctor/version.rb +2 -1
  57. data/lib/asciidoctor/writer.rb +30 -0
  58. data/man/asciidoctor.1 +19 -15
  59. data/man/asciidoctor.adoc +14 -12
  60. metadata +69 -216
  61. data/CONTRIBUTING.adoc +0 -185
  62. data/Gemfile +0 -60
  63. data/Rakefile +0 -129
  64. data/bin/asciidoctor-safe +0 -15
  65. data/features/open_block.feature +0 -92
  66. data/features/pass_block.feature +0 -66
  67. data/features/step_definitions.rb +0 -49
  68. data/features/text_formatting.feature +0 -57
  69. data/features/xref.feature +0 -1039
  70. data/lib/asciidoctor/converter/base.rb +0 -59
  71. data/lib/asciidoctor/converter/docbook45.rb +0 -93
  72. data/lib/asciidoctor/converter/factory.rb +0 -226
  73. data/lib/asciidoctor/core_ext/1.8.7/base64/strict_encode64.rb +0 -6
  74. data/lib/asciidoctor/core_ext/1.8.7/concurrent/hash.rb +0 -5
  75. data/lib/asciidoctor/core_ext/1.8.7/hash/key.rb +0 -4
  76. data/lib/asciidoctor/core_ext/1.8.7/io/binread.rb +0 -6
  77. data/lib/asciidoctor/core_ext/1.8.7/io/write.rb +0 -5
  78. data/lib/asciidoctor/core_ext/1.8.7/string/chr.rb +0 -6
  79. data/lib/asciidoctor/core_ext/1.8.7/string/limit_bytesize.rb +0 -29
  80. data/lib/asciidoctor/core_ext/1.8.7/symbol/empty.rb +0 -6
  81. data/lib/asciidoctor/core_ext/1.8.7/symbol/length.rb +0 -6
  82. data/lib/asciidoctor/core_ext/string/limit_bytesize.rb +0 -10
  83. data/test/api_test.rb +0 -1240
  84. data/test/attribute_list_test.rb +0 -242
  85. data/test/attributes_test.rb +0 -1623
  86. data/test/blocks_test.rb +0 -3870
  87. data/test/converter_test.rb +0 -470
  88. data/test/document_test.rb +0 -1853
  89. data/test/extensions_test.rb +0 -1560
  90. data/test/fixtures/asciidoc_index.txt +0 -521
  91. data/test/fixtures/basic-docinfo-footer.html +0 -6
  92. data/test/fixtures/basic-docinfo-footer.xml +0 -8
  93. data/test/fixtures/basic-docinfo.html +0 -1
  94. data/test/fixtures/basic-docinfo.xml +0 -4
  95. data/test/fixtures/basic.asciidoc +0 -5
  96. data/test/fixtures/chapter-a.adoc +0 -3
  97. data/test/fixtures/child-include.adoc +0 -5
  98. data/test/fixtures/circle.svg +0 -9
  99. data/test/fixtures/custom-backends/erb/html5/block_paragraph.html.erb +0 -6
  100. data/test/fixtures/custom-backends/haml/docbook45/block_paragraph.xml.haml +0 -6
  101. data/test/fixtures/custom-backends/haml/html5-tweaks/block_paragraph.html.haml +0 -1
  102. data/test/fixtures/custom-backends/haml/html5/block_paragraph.html.haml +0 -3
  103. data/test/fixtures/custom-backends/haml/html5/block_sidebar.html.haml +0 -5
  104. data/test/fixtures/custom-backends/slim/docbook45/block_paragraph.xml.slim +0 -6
  105. data/test/fixtures/custom-backends/slim/html5/block_paragraph.html.slim +0 -3
  106. data/test/fixtures/custom-backends/slim/html5/block_sidebar.html.slim +0 -5
  107. data/test/fixtures/custom-docinfodir/basic-docinfo.html +0 -1
  108. data/test/fixtures/custom-docinfodir/docinfo.html +0 -1
  109. data/test/fixtures/docinfo-footer.html +0 -1
  110. data/test/fixtures/docinfo-footer.xml +0 -9
  111. data/test/fixtures/docinfo.html +0 -1
  112. data/test/fixtures/docinfo.xml +0 -3
  113. data/test/fixtures/doctime-localtime.adoc +0 -2
  114. data/test/fixtures/dot.gif +0 -0
  115. data/test/fixtures/encoding.asciidoc +0 -13
  116. data/test/fixtures/file-with-missing-include.adoc +0 -1
  117. data/test/fixtures/grandchild-include.adoc +0 -3
  118. data/test/fixtures/hello-asciidoctor.pdf +0 -69
  119. data/test/fixtures/include-file.asciidoc +0 -24
  120. data/test/fixtures/include-file.jsx +0 -8
  121. data/test/fixtures/include-file.ml +0 -3
  122. data/test/fixtures/include-file.xml +0 -5
  123. data/test/fixtures/lists.adoc +0 -96
  124. data/test/fixtures/master.adoc +0 -5
  125. data/test/fixtures/mismatched-end-tag.adoc +0 -7
  126. data/test/fixtures/other-chapters.adoc +0 -11
  127. data/test/fixtures/outer-include.adoc +0 -5
  128. data/test/fixtures/parent-include-restricted.adoc +0 -5
  129. data/test/fixtures/parent-include.adoc +0 -5
  130. data/test/fixtures/sample.asciidoc +0 -30
  131. data/test/fixtures/section-a.adoc +0 -4
  132. data/test/fixtures/stylesheets/custom.css +0 -3
  133. data/test/fixtures/subdir/index.adoc +0 -3
  134. data/test/fixtures/subdir/inner-include.adoc +0 -3
  135. data/test/fixtures/subdir/middle-include.adoc +0 -5
  136. data/test/fixtures/subs-docinfo.html +0 -2
  137. data/test/fixtures/subs.adoc +0 -6
  138. data/test/fixtures/tagged-class-enclosed.rb +0 -25
  139. data/test/fixtures/tagged-class.rb +0 -23
  140. data/test/fixtures/tip.gif +0 -0
  141. data/test/fixtures/unclosed-tag.adoc +0 -3
  142. data/test/fixtures/unexpected-end-tag.adoc +0 -4
  143. data/test/invoker_test.rb +0 -745
  144. data/test/links_test.rb +0 -855
  145. data/test/lists_test.rb +0 -5151
  146. data/test/logger_test.rb +0 -211
  147. data/test/manpage_test.rb +0 -660
  148. data/test/options_test.rb +0 -262
  149. data/test/paragraphs_test.rb +0 -562
  150. data/test/parser_test.rb +0 -742
  151. data/test/paths_test.rb +0 -395
  152. data/test/preamble_test.rb +0 -173
  153. data/test/reader_test.rb +0 -2161
  154. data/test/sections_test.rb +0 -3575
  155. data/test/substitutions_test.rb +0 -2066
  156. data/test/tables_test.rb +0 -2036
  157. data/test/test_helper.rb +0 -447
  158. data/test/text_test.rb +0 -309
@@ -1,395 +0,0 @@
1
- # encoding: UTF-8
2
- unless defined? ASCIIDOCTOR_PROJECT_DIR
3
- $: << File.dirname(__FILE__); $:.uniq!
4
- require 'test_helper'
5
- end
6
-
7
- context 'Path Resolver' do
8
- context 'Web Paths' do
9
- def setup
10
- @resolver = Asciidoctor::PathResolver.new
11
- end
12
-
13
- test 'target with absolute path' do
14
- assert_equal '/images', @resolver.web_path('/images')
15
- assert_equal '/images', @resolver.web_path('/images', '')
16
- assert_equal '/images', @resolver.web_path('/images', nil)
17
- end
18
-
19
- test 'target with relative path' do
20
- assert_equal 'images', @resolver.web_path('images')
21
- assert_equal 'images', @resolver.web_path('images', '')
22
- assert_equal 'images', @resolver.web_path('images', nil)
23
- end
24
-
25
- test 'target with hidden relative path' do
26
- assert_equal '.images', @resolver.web_path('.images')
27
- assert_equal '.images', @resolver.web_path('.images', '')
28
- assert_equal '.images', @resolver.web_path('.images', nil)
29
- end
30
-
31
- test 'target with path relative to current directory' do
32
- assert_equal './images', @resolver.web_path('./images')
33
- assert_equal './images', @resolver.web_path('./images', '')
34
- assert_equal './images', @resolver.web_path('./images', nil)
35
- end
36
-
37
- test 'target with absolute path ignores start path' do
38
- assert_equal '/images', @resolver.web_path('/images', 'foo')
39
- assert_equal '/images', @resolver.web_path('/images', '/foo')
40
- assert_equal '/images', @resolver.web_path('/images', './foo')
41
- end
42
-
43
- test 'target with relative path appended to start path' do
44
- assert_equal 'assets/images', @resolver.web_path('images', 'assets')
45
- assert_equal '/assets/images', @resolver.web_path('images', '/assets')
46
- #assert_equal '/assets/images/tiger.png', @resolver.web_path('tiger.png', '/assets//images')
47
- assert_equal './assets/images', @resolver.web_path('images', './assets')
48
- assert_equal '/theme.css', @resolver.web_path('theme.css', '/')
49
- assert_equal '/css/theme.css', @resolver.web_path('theme.css', '/css/')
50
- end
51
-
52
- test 'target with path relative to current directory appended to start path' do
53
- assert_equal 'assets/images', @resolver.web_path('./images', 'assets')
54
- assert_equal '/assets/images', @resolver.web_path('./images', '/assets')
55
- assert_equal './assets/images', @resolver.web_path('./images', './assets')
56
- end
57
-
58
- test 'target with relative path appended to url start path' do
59
- assert_equal 'http://www.example.com/assets/images', @resolver.web_path('images', 'http://www.example.com/assets')
60
- end
61
-
62
- # enable if we want to allow web_path to detect and preserve a target URI
63
- #test 'target with file url appended to relative path' do
64
- # assert_equal 'file:///home/username/styles/asciidoctor.css', @resolver.web_path('file:///home/username/styles/asciidoctor.css', '.')
65
- #end
66
-
67
- # enable if we want to allow web_path to detect and preserve a target URI
68
- #test 'target with http url appended to relative path' do
69
- # assert_equal 'http://example.com/asciidoctor.css', @resolver.web_path('http://example.com/asciidoctor.css', '.')
70
- #end
71
-
72
- test 'normalize target' do
73
- assert_equal '../images', @resolver.web_path('../images/../images')
74
- end
75
-
76
- test 'append target to start path and normalize' do
77
- assert_equal '../images', @resolver.web_path('../images/../images', '../images')
78
- assert_equal '../../images', @resolver.web_path('../images', '..')
79
- end
80
-
81
- test 'normalize parent directory that follows root' do
82
- assert_equal '/tiger.png', @resolver.web_path('/../tiger.png')
83
- assert_equal '/tiger.png', @resolver.web_path('/../../tiger.png')
84
- end
85
-
86
- test 'uses start when target is empty' do
87
- assert_equal 'assets/images', @resolver.web_path('', 'assets/images')
88
- assert_equal 'assets/images', @resolver.web_path(nil, 'assets/images')
89
- end
90
-
91
- test 'posixifies windows paths' do
92
- @resolver.file_separator = '\\'
93
- assert_equal '/images', @resolver.web_path('\\images')
94
- assert_equal '../images', @resolver.web_path('..\\images')
95
- assert_equal '/images', @resolver.web_path('\\..\\images')
96
- assert_equal 'assets/images', @resolver.web_path('assets\\images')
97
- assert_equal '../assets/images', @resolver.web_path('assets\\images', '..\\images\\..')
98
- end
99
-
100
- test 'URL encode spaces in path' do
101
- assert_equal 'assets%20and%20stuff/lots%20of%20images', @resolver.web_path('lots of images', 'assets and stuff')
102
- end
103
- end
104
-
105
- context 'System Paths' do
106
- JAIL = '/home/doctor/docs'
107
- default_logger = Asciidoctor::LoggerManager.logger
108
-
109
- def setup
110
- @resolver = Asciidoctor::PathResolver.new
111
- @logger = (Asciidoctor::LoggerManager.logger = Asciidoctor::MemoryLogger.new)
112
- end
113
-
114
- teardown do
115
- Asciidoctor::LoggerManager.logger = default_logger
116
- end
117
-
118
- test 'raises security error if jail is not an absolute path' do
119
- begin
120
- @resolver.system_path('images/tiger.png', '/etc', 'foo')
121
- flunk 'Expecting SecurityError to be raised'
122
- rescue SecurityError
123
- end
124
- end
125
-
126
- #test 'raises security error if jail is not a canoncial path' do
127
- # begin
128
- # @resolver.system_path('images/tiger.png', '/etc', %(#{JAIL}/../foo))
129
- # flunk 'Expecting SecurityError to be raised'
130
- # rescue SecurityError
131
- # end
132
- #end
133
-
134
- test 'prevents access to paths outside of jail' do
135
- result = @resolver.system_path '../../../../../css', %(#{JAIL}/assets/stylesheets), JAIL
136
- assert_equal %(#{JAIL}/css), result
137
- assert_message @logger, :WARN, 'path has illegal reference to ancestor of jail; recovering automatically'
138
-
139
- @logger.clear
140
- result = @resolver.system_path '/../../../../../css', %(#{JAIL}/assets/stylesheets), JAIL
141
- assert_equal %(#{JAIL}/css), result
142
- assert_message @logger, :WARN, 'path is outside of jail; recovering automatically'
143
-
144
- @logger.clear
145
- result = @resolver.system_path '../../../css', '../../..', JAIL
146
- assert_equal %(#{JAIL}/css), result
147
- assert_message @logger, :WARN, 'path has illegal reference to ancestor of jail; recovering automatically'
148
- end
149
-
150
- test 'throws exception for illegal path access if recover is false' do
151
- begin
152
- @resolver.system_path('../../../../../css', "#{JAIL}/assets/stylesheets", JAIL, :recover => false)
153
- flunk 'Expecting SecurityError to be raised'
154
- rescue SecurityError
155
- end
156
- end
157
-
158
- test 'resolves start path if target is empty' do
159
- assert_equal "#{JAIL}/assets/stylesheets", @resolver.system_path('', "#{JAIL}/assets/stylesheets", JAIL)
160
- assert_equal "#{JAIL}/assets/stylesheets", @resolver.system_path(nil, "#{JAIL}/assets/stylesheets", JAIL)
161
- end
162
-
163
- test 'expands parent references in start path if target is empty' do
164
- assert_equal "#{JAIL}/stylesheets", @resolver.system_path('', "#{JAIL}/assets/../stylesheets", JAIL)
165
- end
166
-
167
- test 'expands parent references in start path if target is not empty' do
168
- assert_equal "#{JAIL}/stylesheets/site.css", @resolver.system_path('site.css', "#{JAIL}/assets/../stylesheets", JAIL)
169
- end
170
-
171
- test 'resolves start path if target is dot' do
172
- assert_equal "#{JAIL}/assets/stylesheets", @resolver.system_path('.', "#{JAIL}/assets/stylesheets", JAIL)
173
- assert_equal "#{JAIL}/assets/stylesheets", @resolver.system_path('./', "#{JAIL}/assets/stylesheets", JAIL)
174
- end
175
-
176
- test 'treats absolute target outside of jail as relative when jail is specified' do
177
- result = @resolver.system_path '/', "#{JAIL}/assets/stylesheets", JAIL
178
- assert_equal JAIL, result
179
- assert_message @logger, :WARN, 'path is outside of jail; recovering automatically'
180
-
181
- @logger.clear
182
- result = @resolver.system_path '/foo', "#{JAIL}/assets/stylesheets", JAIL
183
- assert_equal "#{JAIL}/foo", result
184
- assert_message @logger, :WARN, 'path is outside of jail; recovering automatically'
185
-
186
- @logger.clear
187
- result = @resolver.system_path '/../foo', "#{JAIL}/assets/stylesheets", JAIL
188
- assert_equal "#{JAIL}/foo", result
189
- assert_message @logger, :WARN, 'path is outside of jail; recovering automatically'
190
-
191
- @logger.clear
192
- @resolver.file_separator = '\\'
193
- result = @resolver.system_path 'baz.adoc', 'C:/foo', 'C:/bar'
194
- assert_equal 'C:/bar/baz.adoc', result
195
- assert_message @logger, :WARN, 'path is outside of jail; recovering automatically'
196
- end
197
-
198
- test 'allows use of absolute target or start if resolved path is sub-path of jail' do
199
- assert_equal "#{JAIL}/my/path", @resolver.system_path("#{JAIL}/my/path", '', JAIL)
200
- assert_equal "#{JAIL}/my/path", @resolver.system_path("#{JAIL}/my/path", nil, JAIL)
201
- assert_equal "#{JAIL}/my/path", @resolver.system_path('', "#{JAIL}/my/path", JAIL)
202
- assert_equal "#{JAIL}/my/path", @resolver.system_path(nil, "#{JAIL}/my/path", JAIL)
203
- assert_equal "#{JAIL}/my/path", @resolver.system_path('path', "#{JAIL}/my", JAIL)
204
- assert_equal '/foo/bar/baz.adoc', @resolver.system_path('/foo/bar/baz.adoc', nil, '/')
205
- assert_equal '/foo/bar/baz.adoc', @resolver.system_path('baz.adoc', '/foo/bar', '/')
206
- assert_equal '/foo/bar/baz.adoc', @resolver.system_path('baz.adoc', 'foo/bar', '/')
207
- end
208
-
209
- test 'uses jail path if start path is empty' do
210
- assert_equal "#{JAIL}/images/tiger.png", @resolver.system_path('images/tiger.png', '', JAIL)
211
- assert_equal "#{JAIL}/images/tiger.png", @resolver.system_path('images/tiger.png', nil, JAIL)
212
- end
213
-
214
- test 'warns if start is not contained within jail' do
215
- result = @resolver.system_path 'images/tiger.png', '/etc', JAIL
216
- assert_equal %(#{JAIL}/images/tiger.png), result
217
- assert_message @logger, :WARN, 'path is outside of jail; recovering automatically'
218
-
219
- @logger.clear
220
- result = @resolver.system_path '.', '/etc', JAIL
221
- assert_equal JAIL, result
222
- assert_message @logger, :WARN, 'path is outside of jail; recovering automatically'
223
-
224
- @logger.clear
225
- @resolver.file_separator = '\\'
226
- result = @resolver.system_path '.', 'C:/foo', 'C:/bar'
227
- assert_equal 'C:/bar', result
228
- assert_message @logger, :WARN, 'path is outside of jail; recovering automatically'
229
- end
230
-
231
- test 'allows start path to be parent of jail if resolved target is inside jail' do
232
- assert_equal "#{JAIL}/foo/path", @resolver.system_path('foo/path', JAIL, "#{JAIL}/foo")
233
- @resolver.file_separator = '\\'
234
- assert_equal "C:/dev/project/README.adoc", @resolver.system_path('project/README.adoc', 'C:/dev', 'C:/dev/project')
235
- end
236
-
237
- test 'relocates target to jail if resolved value fails outside of jail' do
238
- result = @resolver.system_path 'bar/baz.adoc', JAIL, "#{JAIL}/foo"
239
- assert_equal %(#{JAIL}/foo/bar/baz.adoc), result
240
- assert_message @logger, :WARN, 'path is outside of jail; recovering automatically'
241
-
242
- @logger.clear
243
- @resolver.file_separator = '\\'
244
- result = @resolver.system_path 'bar/baz.adoc', 'D:/', 'C:/foo'
245
- assert_equal 'C:/foo/bar/baz.adoc', result
246
- assert_message @logger, :WARN, '~outside of jail root'
247
- end
248
-
249
- test 'raises security error if start is not contained within jail and recover is disabled' do
250
- begin
251
- @resolver.system_path('images/tiger.png', '/etc', JAIL, :recover => false)
252
- flunk 'Expecting SecurityError to be raised'
253
- rescue SecurityError
254
- end
255
-
256
- begin
257
- @resolver.system_path('.', '/etc', JAIL, :recover => false)
258
- flunk 'Expecting SecurityError to be raised'
259
- rescue SecurityError
260
- end
261
- end
262
-
263
- test 'expands parent references in absolute path if jail is not specified' do
264
- assert_equal '/etc/stylesheet.css', @resolver.system_path('/usr/share/../../etc/stylesheet.css')
265
- end
266
-
267
- test 'resolves absolute directory if jail is not specified' do
268
- assert_equal '/usr/share/stylesheet.css', @resolver.system_path('/usr/share/stylesheet.css', '/home/dallen/docs/assets/stylesheets')
269
- end
270
-
271
- test 'resolves ancestor directory of start if jail is not specified' do
272
- assert_equal '/usr/share/stylesheet.css', @resolver.system_path('../../../../../usr/share/stylesheet.css', '/home/dallen/docs/assets/stylesheets')
273
- end
274
-
275
- test 'resolves absolute path if start is absolute and target is relative' do
276
- assert_equal '/usr/share/assets/stylesheet.css', @resolver.system_path('assets/stylesheet.css', '/usr/share')
277
- end
278
-
279
- test 'File.dirname preserves UNC path root on Windows' do
280
- assert_equal File.dirname('\\\\server\\docs\\file.html'), '\\\\server\\docs'
281
- end if windows?
282
-
283
- test 'File.dirname preserves posix-style UNC path root on Windows' do
284
- assert_equal File.dirname('//server/docs/file.html'), '//server/docs'
285
- end if windows?
286
-
287
- test 'resolves UNC path if start is absolute and target is relative' do
288
- assert_equal '//QA/c$/users/asciidoctor/assets/stylesheet.css', @resolver.system_path('assets/stylesheet.css', '//QA/c$/users/asciidoctor')
289
- end
290
-
291
- test 'resolves UNC path if target is UNC path' do
292
- @resolver.file_separator = '\\'
293
- assert_equal '//server/docs/output.html', @resolver.system_path('\\\\server\\docs\\output.html')
294
- end
295
-
296
- test 'resolves UNC path if target is posix-style UNC path' do
297
- assert_equal '//server/docs/output.html', @resolver.system_path('//server/docs/output.html')
298
- end
299
-
300
- test 'resolves relative target relative to current directory if start is empty' do
301
- pwd = File.expand_path(Dir.pwd)
302
- assert_equal "#{pwd}/images/tiger.png", @resolver.system_path('images/tiger.png', '')
303
- assert_equal "#{pwd}/images/tiger.png", @resolver.system_path('images/tiger.png', nil)
304
- assert_equal "#{pwd}/images/tiger.png", @resolver.system_path('images/tiger.png')
305
- end
306
-
307
- test 'resolves relative hidden target relative to current directory if start is empty' do
308
- pwd = File.expand_path(Dir.pwd)
309
- assert_equal "#{pwd}/.images/tiger.png", @resolver.system_path('.images/tiger.png', '')
310
- assert_equal "#{pwd}/.images/tiger.png", @resolver.system_path('.images/tiger.png', nil)
311
- end
312
-
313
- test 'resolves and normalizes start when target is empty' do
314
- pwd = File.expand_path Dir.pwd
315
- assert_equal '/home/doctor/docs', (@resolver.system_path '', '/home/doctor/docs')
316
- assert_equal '/home/doctor/docs', (@resolver.system_path '', '/home/doctor/./docs')
317
- assert_equal '/home/doctor/docs', (@resolver.system_path nil, '/home/doctor/docs')
318
- assert_equal '/home/doctor/docs', (@resolver.system_path nil, '/home/doctor/./docs')
319
- assert_equal %(#{pwd}/assets/images), (@resolver.system_path nil, 'assets/images')
320
- @resolver.system_path '', '../assets/images', JAIL
321
- assert_message @logger, :WARN, 'path has illegal reference to ancestor of jail; recovering automatically'
322
- end
323
-
324
- test 'posixifies windows paths' do
325
- @resolver.file_separator = '\\'
326
- assert_equal "#{JAIL}/assets/css", @resolver.system_path('..\\css', 'assets\\stylesheets', JAIL)
327
- end
328
-
329
- test 'resolves windows paths when file separator is backlash' do
330
- @resolver.file_separator = '\\'
331
-
332
- assert_equal 'C:/data/docs', (@resolver.system_path '..', 'C:\\data\\docs\\assets', 'C:\\data\\docs')
333
-
334
- result = @resolver.system_path '..\\..', 'C:\\data\\docs\\assets', 'C:\\data\\docs'
335
- assert_equal 'C:/data/docs', result
336
- assert_message @logger, :WARN, 'path has illegal reference to ancestor of jail; recovering automatically'
337
-
338
- @logger.clear
339
- result = @resolver.system_path '..\\..\\css', 'C:\\data\\docs\\assets', 'C:\\data\\docs'
340
- assert_equal 'C:/data/docs/css', result
341
- assert_message @logger, :WARN, 'path has illegal reference to ancestor of jail; recovering automatically'
342
- end
343
-
344
- test 'should calculate relative path' do
345
- filename = @resolver.system_path('part1/chapter1/section1.adoc', nil, JAIL)
346
- assert_equal "#{JAIL}/part1/chapter1/section1.adoc", filename
347
- assert_equal 'part1/chapter1/section1.adoc', @resolver.relative_path(filename, JAIL)
348
- end
349
-
350
- test 'should resolve relative path to filename outside of base directory' do
351
- filename = '/home/shared/partials'
352
- base_dir = '/home/user/docs'
353
- result = @resolver.relative_path filename, base_dir
354
- assert_equal '../../shared/partials', result
355
- end
356
-
357
- test 'should resolve relative path relative to base dir in unsafe mode' do
358
- base_dir = fixture_path 'base'
359
- doc = empty_document :base_dir => base_dir, :safe => Asciidoctor::SafeMode::UNSAFE
360
- expected = ::File.join base_dir, 'images', 'tiger.png'
361
- actual = doc.normalize_system_path 'tiger.png', 'images'
362
- assert_equal expected, actual
363
- end
364
-
365
- test 'should resolve absolute path as absolute in unsafe mode' do
366
- base_dir = fixture_path 'base'
367
- doc = empty_document :base_dir => base_dir, :safe => Asciidoctor::SafeMode::UNSAFE
368
- actual = doc.normalize_system_path 'tiger.png', '/etc/images'
369
- assert_equal '/etc/images/tiger.png', actual
370
- end
371
- end
372
-
373
- context 'Helpers' do
374
- test 'rootname should return file name without extension' do
375
- assert_equal 'master', Asciidoctor::Helpers.rootname('master.adoc')
376
- assert_equal 'docs/master', Asciidoctor::Helpers.rootname('docs/master.adoc')
377
- end
378
-
379
- test 'rootname should file name if it has no extension' do
380
- assert_equal 'master', Asciidoctor::Helpers.rootname('master')
381
- assert_equal 'docs/master', Asciidoctor::Helpers.rootname('docs/master')
382
- end
383
-
384
- test 'UriSniffRx should detect URIs' do
385
- assert Asciidoctor::UriSniffRx =~ 'http://example.com'
386
- assert Asciidoctor::UriSniffRx =~ 'https://example.com'
387
- assert Asciidoctor::UriSniffRx =~ 'data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs='
388
- end
389
-
390
- test 'UriSniffRx should not detect an absolute Windows path as a URI' do
391
- assert Asciidoctor::UriSniffRx !~ 'c:/sample.adoc'
392
- assert Asciidoctor::UriSniffRx !~ 'c:\\sample.adoc'
393
- end
394
- end
395
- end
@@ -1,173 +0,0 @@
1
- # encoding: UTF-8
2
- unless defined? ASCIIDOCTOR_PROJECT_DIR
3
- $: << File.dirname(__FILE__); $:.uniq!
4
- require 'test_helper'
5
- end
6
-
7
- context 'Preamble' do
8
-
9
- test 'title and single paragraph preamble before section' do
10
- input = <<-EOS
11
- = Title
12
-
13
- Preamble paragraph 1.
14
-
15
- == First Section
16
-
17
- Section paragraph 1.
18
- EOS
19
- result = convert_string(input)
20
- assert_xpath '//p', result, 2
21
- assert_xpath '//*[@id="preamble"]', result, 1
22
- assert_xpath '//*[@id="preamble"]//p', result, 1
23
- assert_xpath '//*[@id="preamble"]/following-sibling::*//h2[@id="_first_section"]', result, 1
24
- assert_xpath '//*[@id="preamble"]/following-sibling::*//p', result, 1
25
- end
26
-
27
- test 'title of preface is blank by default in DocBook output' do
28
- input = <<-EOS
29
- = Document Title
30
- :doctype: book
31
-
32
- Preface content.
33
-
34
- == First Section
35
-
36
- Section content.
37
- EOS
38
- result = convert_string input, :backend => :docbook
39
- assert_xpath '//preface/title', result, 1
40
- title_node = xmlnodes_at_xpath '//preface/title', result, 1
41
- assert_equal '', title_node.text
42
- end
43
-
44
- test 'preface-title attribute is assigned as title of preface in DocBook output' do
45
- input = <<-EOS
46
- = Document Title
47
- :doctype: book
48
- :preface-title: Preface
49
-
50
- Preface content.
51
-
52
- == First Section
53
-
54
- Section content.
55
- EOS
56
- result = convert_string input, :backend => :docbook
57
- assert_xpath '//preface/title[text()="Preface"]', result, 1
58
- end
59
-
60
- test 'title and multi-paragraph preamble before section' do
61
- input = <<-EOS
62
- = Title
63
-
64
- Preamble paragraph 1.
65
-
66
- Preamble paragraph 2.
67
-
68
- == First Section
69
-
70
- Section paragraph 1.
71
- EOS
72
- result = convert_string(input)
73
- assert_xpath '//p', result, 3
74
- assert_xpath '//*[@id="preamble"]', result, 1
75
- assert_xpath '//*[@id="preamble"]//p', result, 2
76
- assert_xpath '//*[@id="preamble"]/following-sibling::*//h2[@id="_first_section"]', result, 1
77
- assert_xpath '//*[@id="preamble"]/following-sibling::*//p', result, 1
78
- end
79
-
80
- test 'should not wrap content in preamble if document has title but no sections' do
81
- input = <<-EOS
82
- = Title
83
-
84
- paragraph
85
- EOS
86
- result = convert_string(input)
87
- assert_xpath '//p', result, 1
88
- assert_xpath '//*[@id="content"]/*[@class="paragraph"]/p', result, 1
89
- assert_xpath '//*[@id="content"]/*[@class="paragraph"]/following-sibling::*', result, 0
90
- end
91
-
92
- test 'title and section without preamble' do
93
- input = <<-EOS
94
- = Title
95
-
96
- == First Section
97
-
98
- Section paragraph 1.
99
- EOS
100
- result = convert_string(input)
101
- assert_xpath '//p', result, 1
102
- assert_xpath '//*[@id="preamble"]', result, 0
103
- assert_xpath '//h2[@id="_first_section"]', result, 1
104
- end
105
-
106
- test 'no title with preamble and section' do
107
- input = <<-EOS
108
- Preamble paragraph 1.
109
-
110
- == First Section
111
-
112
- Section paragraph 1.
113
- EOS
114
- result = convert_string(input)
115
- assert_xpath '//p', result, 2
116
- assert_xpath '//*[@id="preamble"]', result, 0
117
- assert_xpath '//h2[@id="_first_section"]/preceding::p', result, 1
118
- end
119
-
120
- test 'preamble in book doctype' do
121
- input = <<-EOS
122
- = Book
123
- :doctype: book
124
-
125
- Back then...
126
-
127
- = Chapter One
128
-
129
- [partintro]
130
- It was a dark and stormy night...
131
-
132
- == Scene One
133
-
134
- Someone's gonna get axed.
135
-
136
- = Chapter Two
137
-
138
- [partintro]
139
- They couldn't believe their eyes when...
140
-
141
- == Scene One
142
-
143
- The axe came swinging.
144
- EOS
145
-
146
- d = document_from_string(input)
147
- assert_equal 'book', d.doctype
148
- output = d.convert
149
- assert_xpath '//h1', output, 3
150
- assert_xpath %{//*[@id="preamble"]//p[text() = "Back then#{decode_char 8230}#{decode_char 8203}"]}, output, 1
151
- end
152
-
153
- test 'should output table of contents in preamble if toc-placement attribute value is preamble' do
154
- input = <<-EOS
155
- = Article
156
- :toc:
157
- :toc-placement: preamble
158
-
159
- Once upon a time...
160
-
161
- == Section One
162
-
163
- It was a dark and stormy night...
164
-
165
- == Section Two
166
-
167
- They couldn't believe their eyes when...
168
- EOS
169
-
170
- output = convert_string input
171
- assert_xpath '//*[@id="preamble"]/*[@id="toc"]', output, 1
172
- end
173
- end