asciidoctor 1.5.8 → 2.0.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +11 -0
  3. data/CHANGELOG.adoc +628 -45
  4. data/LICENSE +2 -1
  5. data/README-de.adoc +28 -38
  6. data/README-fr.adoc +30 -43
  7. data/README-jp.adoc +255 -201
  8. data/README-zh_CN.adoc +40 -44
  9. data/README.adoc +170 -143
  10. data/asciidoctor.gemspec +22 -34
  11. data/bin/asciidoctor +5 -4
  12. data/data/locale/attributes-ar.adoc +4 -3
  13. data/data/locale/attributes-be.adoc +23 -0
  14. data/data/locale/attributes-bg.adoc +4 -3
  15. data/data/locale/attributes-ca.adoc +6 -5
  16. data/data/locale/attributes-cs.adoc +4 -3
  17. data/data/locale/attributes-da.adoc +6 -5
  18. data/data/locale/attributes-de.adoc +6 -5
  19. data/data/locale/attributes-en.adoc +4 -4
  20. data/data/locale/attributes-es.adoc +6 -5
  21. data/data/locale/attributes-fa.adoc +4 -3
  22. data/data/locale/attributes-fi.adoc +4 -3
  23. data/data/locale/attributes-fr.adoc +8 -7
  24. data/data/locale/attributes-hu.adoc +4 -3
  25. data/data/locale/attributes-id.adoc +4 -3
  26. data/data/locale/attributes-it.adoc +6 -5
  27. data/data/locale/attributes-ja.adoc +4 -3
  28. data/data/locale/{attributes-kr.adoc → attributes-ko.adoc} +4 -3
  29. data/data/locale/attributes-nb.adoc +4 -3
  30. data/data/locale/attributes-nl.adoc +6 -5
  31. data/data/locale/attributes-nn.adoc +4 -3
  32. data/data/locale/attributes-pl.adoc +8 -7
  33. data/data/locale/attributes-pt.adoc +6 -5
  34. data/data/locale/attributes-pt_BR.adoc +6 -5
  35. data/data/locale/attributes-ro.adoc +4 -3
  36. data/data/locale/attributes-ru.adoc +6 -5
  37. data/data/locale/attributes-sr.adoc +4 -4
  38. data/data/locale/attributes-sr_Latn.adoc +4 -4
  39. data/data/locale/attributes-sv.adoc +4 -4
  40. data/data/locale/attributes-th.adoc +23 -0
  41. data/data/locale/attributes-tr.adoc +4 -3
  42. data/data/locale/attributes-uk.adoc +6 -5
  43. data/data/locale/attributes-vi.adoc +23 -0
  44. data/data/locale/attributes-zh_CN.adoc +4 -3
  45. data/data/locale/attributes-zh_TW.adoc +4 -3
  46. data/data/reference/syntax.adoc +296 -0
  47. data/data/stylesheets/asciidoctor-default.css +120 -114
  48. data/data/stylesheets/coderay-asciidoctor.css +15 -17
  49. data/lib/asciidoctor/abstract_block.rb +146 -140
  50. data/lib/asciidoctor/abstract_node.rb +152 -170
  51. data/lib/asciidoctor/attribute_list.rb +77 -89
  52. data/lib/asciidoctor/block.rb +29 -28
  53. data/lib/asciidoctor/callouts.rb +4 -2
  54. data/lib/asciidoctor/cli/invoker.rb +20 -24
  55. data/lib/asciidoctor/cli/options.rb +107 -96
  56. data/lib/asciidoctor/cli.rb +3 -2
  57. data/lib/asciidoctor/convert.rb +199 -0
  58. data/lib/asciidoctor/converter/composite.rb +40 -48
  59. data/lib/asciidoctor/converter/docbook5.rb +627 -644
  60. data/lib/asciidoctor/converter/html5.rb +1053 -951
  61. data/lib/asciidoctor/converter/manpage.rb +581 -532
  62. data/lib/asciidoctor/converter/template.rb +232 -271
  63. data/lib/asciidoctor/converter.rb +370 -185
  64. data/lib/asciidoctor/core_ext/float/truncate.rb +20 -0
  65. data/lib/asciidoctor/core_ext/hash/merge.rb +8 -0
  66. data/lib/asciidoctor/core_ext/match_data/names.rb +7 -0
  67. data/lib/asciidoctor/core_ext/nil_or_empty.rb +1 -0
  68. data/lib/asciidoctor/core_ext/regexp/is_match.rb +4 -2
  69. data/lib/asciidoctor/core_ext.rb +8 -17
  70. data/lib/asciidoctor/document.rb +503 -461
  71. data/lib/asciidoctor/extensions.rb +127 -174
  72. data/lib/asciidoctor/helpers.rb +184 -107
  73. data/lib/asciidoctor/inline.rb +9 -12
  74. data/lib/asciidoctor/list.rb +11 -29
  75. data/lib/asciidoctor/load.rb +119 -0
  76. data/lib/asciidoctor/logging.rb +22 -17
  77. data/lib/asciidoctor/parser.rb +673 -719
  78. data/lib/asciidoctor/path_resolver.rb +48 -33
  79. data/lib/asciidoctor/reader.rb +383 -338
  80. data/lib/asciidoctor/rouge_ext.rb +39 -0
  81. data/lib/asciidoctor/rx.rb +723 -0
  82. data/lib/asciidoctor/section.rb +17 -16
  83. data/lib/asciidoctor/stylesheets.rb +19 -37
  84. data/lib/asciidoctor/substitutors.rb +926 -1022
  85. data/lib/asciidoctor/syntax_highlighter/coderay.rb +88 -0
  86. data/lib/asciidoctor/syntax_highlighter/highlightjs.rb +34 -0
  87. data/lib/asciidoctor/syntax_highlighter/html_pipeline.rb +10 -0
  88. data/lib/asciidoctor/syntax_highlighter/prettify.rb +30 -0
  89. data/lib/asciidoctor/syntax_highlighter/pygments.rb +157 -0
  90. data/lib/asciidoctor/syntax_highlighter/rouge.rb +143 -0
  91. data/lib/asciidoctor/syntax_highlighter.rb +253 -0
  92. data/lib/asciidoctor/table.rb +152 -114
  93. data/lib/asciidoctor/timings.rb +7 -5
  94. data/lib/asciidoctor/version.rb +2 -1
  95. data/lib/asciidoctor/writer.rb +30 -0
  96. data/lib/asciidoctor.rb +266 -1340
  97. data/man/asciidoctor.1 +49 -47
  98. data/man/asciidoctor.adoc +54 -45
  99. metadata +50 -245
  100. data/CONTRIBUTING.adoc +0 -185
  101. data/Gemfile +0 -60
  102. data/Rakefile +0 -129
  103. data/bin/asciidoctor-safe +0 -15
  104. data/features/open_block.feature +0 -92
  105. data/features/pass_block.feature +0 -66
  106. data/features/step_definitions.rb +0 -49
  107. data/features/text_formatting.feature +0 -57
  108. data/features/xref.feature +0 -1039
  109. data/lib/asciidoctor/converter/base.rb +0 -59
  110. data/lib/asciidoctor/converter/docbook45.rb +0 -93
  111. data/lib/asciidoctor/converter/factory.rb +0 -226
  112. data/lib/asciidoctor/core_ext/1.8.7/base64/strict_encode64.rb +0 -6
  113. data/lib/asciidoctor/core_ext/1.8.7/concurrent/hash.rb +0 -5
  114. data/lib/asciidoctor/core_ext/1.8.7/hash/key.rb +0 -4
  115. data/lib/asciidoctor/core_ext/1.8.7/io/binread.rb +0 -6
  116. data/lib/asciidoctor/core_ext/1.8.7/io/write.rb +0 -5
  117. data/lib/asciidoctor/core_ext/1.8.7/string/chr.rb +0 -6
  118. data/lib/asciidoctor/core_ext/1.8.7/string/limit_bytesize.rb +0 -29
  119. data/lib/asciidoctor/core_ext/1.8.7/symbol/empty.rb +0 -6
  120. data/lib/asciidoctor/core_ext/1.8.7/symbol/length.rb +0 -6
  121. data/lib/asciidoctor/core_ext/string/limit_bytesize.rb +0 -10
  122. data/test/api_test.rb +0 -1240
  123. data/test/attribute_list_test.rb +0 -242
  124. data/test/attributes_test.rb +0 -1623
  125. data/test/blocks_test.rb +0 -3870
  126. data/test/converter_test.rb +0 -470
  127. data/test/document_test.rb +0 -1853
  128. data/test/extensions_test.rb +0 -1560
  129. data/test/fixtures/asciidoc_index.txt +0 -521
  130. data/test/fixtures/basic-docinfo-footer.html +0 -6
  131. data/test/fixtures/basic-docinfo-footer.xml +0 -8
  132. data/test/fixtures/basic-docinfo.html +0 -1
  133. data/test/fixtures/basic-docinfo.xml +0 -4
  134. data/test/fixtures/basic.asciidoc +0 -5
  135. data/test/fixtures/chapter-a.adoc +0 -3
  136. data/test/fixtures/child-include.adoc +0 -5
  137. data/test/fixtures/circle.svg +0 -9
  138. data/test/fixtures/custom-backends/erb/html5/block_paragraph.html.erb +0 -6
  139. data/test/fixtures/custom-backends/haml/docbook45/block_paragraph.xml.haml +0 -6
  140. data/test/fixtures/custom-backends/haml/html5/block_paragraph.html.haml +0 -3
  141. data/test/fixtures/custom-backends/haml/html5/block_sidebar.html.haml +0 -5
  142. data/test/fixtures/custom-backends/haml/html5-tweaks/block_paragraph.html.haml +0 -1
  143. data/test/fixtures/custom-backends/slim/docbook45/block_paragraph.xml.slim +0 -6
  144. data/test/fixtures/custom-backends/slim/html5/block_paragraph.html.slim +0 -3
  145. data/test/fixtures/custom-backends/slim/html5/block_sidebar.html.slim +0 -5
  146. data/test/fixtures/custom-docinfodir/basic-docinfo.html +0 -1
  147. data/test/fixtures/custom-docinfodir/docinfo.html +0 -1
  148. data/test/fixtures/docinfo-footer.html +0 -1
  149. data/test/fixtures/docinfo-footer.xml +0 -9
  150. data/test/fixtures/docinfo.html +0 -1
  151. data/test/fixtures/docinfo.xml +0 -3
  152. data/test/fixtures/doctime-localtime.adoc +0 -2
  153. data/test/fixtures/dot.gif +0 -0
  154. data/test/fixtures/encoding.asciidoc +0 -13
  155. data/test/fixtures/file-with-missing-include.adoc +0 -1
  156. data/test/fixtures/grandchild-include.adoc +0 -3
  157. data/test/fixtures/hello-asciidoctor.pdf +0 -69
  158. data/test/fixtures/include-file.asciidoc +0 -24
  159. data/test/fixtures/include-file.jsx +0 -8
  160. data/test/fixtures/include-file.ml +0 -3
  161. data/test/fixtures/include-file.xml +0 -5
  162. data/test/fixtures/lists.adoc +0 -96
  163. data/test/fixtures/master.adoc +0 -5
  164. data/test/fixtures/mismatched-end-tag.adoc +0 -7
  165. data/test/fixtures/other-chapters.adoc +0 -11
  166. data/test/fixtures/outer-include.adoc +0 -5
  167. data/test/fixtures/parent-include-restricted.adoc +0 -5
  168. data/test/fixtures/parent-include.adoc +0 -5
  169. data/test/fixtures/sample.asciidoc +0 -30
  170. data/test/fixtures/section-a.adoc +0 -4
  171. data/test/fixtures/stylesheets/custom.css +0 -3
  172. data/test/fixtures/subdir/index.adoc +0 -3
  173. data/test/fixtures/subdir/inner-include.adoc +0 -3
  174. data/test/fixtures/subdir/middle-include.adoc +0 -5
  175. data/test/fixtures/subs-docinfo.html +0 -2
  176. data/test/fixtures/subs.adoc +0 -6
  177. data/test/fixtures/tagged-class-enclosed.rb +0 -25
  178. data/test/fixtures/tagged-class.rb +0 -23
  179. data/test/fixtures/tip.gif +0 -0
  180. data/test/fixtures/unclosed-tag.adoc +0 -3
  181. data/test/fixtures/unexpected-end-tag.adoc +0 -4
  182. data/test/invoker_test.rb +0 -745
  183. data/test/links_test.rb +0 -855
  184. data/test/lists_test.rb +0 -5151
  185. data/test/logger_test.rb +0 -211
  186. data/test/manpage_test.rb +0 -660
  187. data/test/options_test.rb +0 -262
  188. data/test/paragraphs_test.rb +0 -562
  189. data/test/parser_test.rb +0 -742
  190. data/test/paths_test.rb +0 -395
  191. data/test/preamble_test.rb +0 -173
  192. data/test/reader_test.rb +0 -2161
  193. data/test/sections_test.rb +0 -3575
  194. data/test/substitutions_test.rb +0 -2066
  195. data/test/tables_test.rb +0 -2036
  196. data/test/test_helper.rb +0 -447
  197. data/test/text_test.rb +0 -309
data/test/invoker_test.rb DELETED
@@ -1,745 +0,0 @@
1
- # encoding: UTF-8
2
- unless defined? ASCIIDOCTOR_PROJECT_DIR
3
- $: << File.dirname(__FILE__); $:.uniq!
4
- require 'test_helper'
5
- end
6
- require 'asciidoctor/cli/options'
7
- require 'asciidoctor/cli/invoker'
8
-
9
- context 'Invoker' do
10
- test 'should parse source and convert to html5 article by default' do
11
- invoker = nil
12
- output = nil
13
- redirect_streams do |out, err|
14
- invoker = invoke_cli %w(-o -)
15
- output = out.string
16
- end
17
- refute_nil invoker
18
- doc = invoker.document
19
- refute_nil doc
20
- assert_equal 'Document Title', doc.doctitle
21
- assert_equal 'Doc Writer', doc.attr('author')
22
- assert_equal 'html5', doc.attr('backend')
23
- assert_equal '.html', doc.attr('outfilesuffix')
24
- assert_equal 'article', doc.attr('doctype')
25
- assert doc.blocks?
26
- assert_equal :preamble, doc.blocks.first.context
27
- refute_empty output
28
- assert_xpath '/html', output, 1
29
- assert_xpath '/html/head', output, 1
30
- assert_xpath '/html/body', output, 1
31
- assert_xpath '/html/head/title[text() = "Document Title"]', output, 1
32
- assert_xpath '/html/body[@class="article"]/*[@id="header"]/h1[text() = "Document Title"]', output, 1
33
- end
34
-
35
- test 'should set implicit doc info attributes' do
36
- sample_filepath = fixture_path 'sample.asciidoc'
37
- sample_filedir = fixturedir
38
- invoker = invoke_cli_to_buffer %w(-o /dev/null), sample_filepath
39
- doc = invoker.document
40
- assert_equal 'sample', doc.attr('docname')
41
- assert_equal sample_filepath, doc.attr('docfile')
42
- assert_equal sample_filedir, doc.attr('docdir')
43
- assert doc.attr?('docdate')
44
- assert doc.attr?('docyear')
45
- assert doc.attr?('doctime')
46
- assert doc.attr?('docdatetime')
47
- assert_empty invoker.read_output
48
- end
49
-
50
- test 'should allow docdate and doctime to be overridden' do
51
- sample_filepath = fixture_path 'sample.asciidoc'
52
- invoker = invoke_cli_to_buffer %w(-o /dev/null -a docdate=2015-01-01 -a doctime=10:00:00-0700), sample_filepath
53
- doc = invoker.document
54
- assert doc.attr?('docdate', '2015-01-01')
55
- assert doc.attr?('docyear', '2015')
56
- assert doc.attr?('doctime', '10:00:00-0700')
57
- assert doc.attr?('docdatetime', '2015-01-01 10:00:00-0700')
58
- end
59
-
60
- test 'should accept document from stdin and write to stdout' do
61
- invoker = invoke_cli_to_buffer(%w(-s), '-') { 'content' }
62
- doc = invoker.document
63
- refute doc.attr?('docname')
64
- refute doc.attr?('docfile')
65
- assert_equal Dir.pwd, doc.attr('docdir')
66
- assert_equal doc.attr('docdate'), doc.attr('localdate')
67
- assert_equal doc.attr('docyear'), doc.attr('localyear')
68
- assert_equal doc.attr('doctime'), doc.attr('localtime')
69
- assert_equal doc.attr('docdatetime'), doc.attr('localdatetime')
70
- refute doc.attr?('outfile')
71
- output = invoker.read_output
72
- refute_empty output
73
- assert_xpath '/*[@class="paragraph"]/p[text()="content"]', output, 1
74
- end
75
-
76
- test 'should not fail to rewind input if reading document from stdin' do
77
- io = STDIN.dup
78
- class << io
79
- def readlines
80
- ['paragraph']
81
- end
82
- end
83
- invoker = invoke_cli_to_buffer(%w(-s), '-') { io }
84
- assert_equal 0, invoker.code
85
- assert_equal 1, invoker.document.blocks.size
86
- end
87
-
88
- test 'should accept document from stdin and write to output file' do
89
- sample_outpath = fixture_path 'sample-output.html'
90
- begin
91
- invoker = invoke_cli(%W(-s -o #{sample_outpath}), '-') { 'content' }
92
- doc = invoker.document
93
- refute doc.attr?('docname')
94
- refute doc.attr?('docfile')
95
- assert_equal Dir.pwd, doc.attr('docdir')
96
- assert_equal doc.attr('docdate'), doc.attr('localdate')
97
- assert_equal doc.attr('docyear'), doc.attr('localyear')
98
- assert_equal doc.attr('doctime'), doc.attr('localtime')
99
- assert_equal doc.attr('docdatetime'), doc.attr('localdatetime')
100
- assert doc.attr?('outfile')
101
- assert_equal sample_outpath, doc.attr('outfile')
102
- assert File.exist?(sample_outpath)
103
- ensure
104
- FileUtils.rm_f(sample_outpath)
105
- end
106
- end
107
-
108
- test 'should fail if input file matches resolved output file' do
109
- invoker = invoke_cli_to_buffer %W(-a outfilesuffix=.asciidoc), 'sample.asciidoc'
110
- assert_match(/input file and output file cannot be the same/, invoker.read_error)
111
- end
112
-
113
- test 'should fail if input file matches specified output file' do
114
- sample_outpath = fixture_path 'sample.asciidoc'
115
- invoker = invoke_cli_to_buffer %W(-o #{sample_outpath}), 'sample.asciidoc'
116
- assert_match(/input file and output file cannot be the same/, invoker.read_error)
117
- end
118
-
119
- test 'should accept input from named pipe and output to stdout' do
120
- sample_inpath = fixture_path 'sample-pipe.adoc'
121
- begin
122
- %x(mkfifo #{sample_inpath})
123
- write_thread = Thread.new do
124
- IO.write sample_inpath, 'pipe content'
125
- end
126
- invoker = invoke_cli_to_buffer %w(-a stylesheet!), sample_inpath
127
- result = invoker.read_output
128
- assert_match(/pipe content/, result)
129
- write_thread.join
130
- ensure
131
- FileUtils.rm_f sample_inpath
132
- end
133
- end if RUBY_MIN_VERSION_1_9 && !windows?
134
-
135
- test 'should allow docdir to be specified when input is a string' do
136
- expected_docdir = fixturedir
137
- invoker = invoke_cli_to_buffer(%w(-s --base-dir test/fixtures -o /dev/null), '-') { 'content' }
138
- doc = invoker.document
139
- assert_equal expected_docdir, doc.attr('docdir')
140
- assert_equal expected_docdir, doc.base_dir
141
- end
142
-
143
- test 'should display version and exit' do
144
- expected = %(Asciidoctor #{Asciidoctor::VERSION} [https://asciidoctor.org]\nRuntime Environment (#{RUBY_DESCRIPTION}))
145
- ['--version', '-V'].each do |switch|
146
- actual = nil
147
- redirect_streams do |out, err|
148
- invoke_cli [switch]
149
- actual = out.string.rstrip
150
- end
151
- refute_nil actual
152
- assert actual.start_with?(expected), %(Expected to print version when using #{switch} switch)
153
- end
154
- end
155
-
156
- test 'should print warnings to stderr by default' do
157
- input = <<-EOS
158
- 2. second
159
- 3. third
160
- EOS
161
- warnings = nil
162
- redirect_streams do |out, err|
163
- invoke_cli_to_buffer(%w(-o /dev/null), '-') { input }
164
- warnings = err.string
165
- end
166
- assert_match(/WARNING/, warnings)
167
- end
168
-
169
- test 'should silence warnings if -q flag is specified' do
170
- input = <<-EOS
171
- 2. second
172
- 3. third
173
- EOS
174
- warnings = nil
175
- redirect_streams do |out, err|
176
- invoke_cli_to_buffer(%w(-q -o /dev/null), '-') { input }
177
- warnings = err.string
178
- end
179
- assert_equal '', warnings
180
- end
181
-
182
- test 'should return non-zero exit code if failure level is reached' do
183
- input = <<-EOS
184
- 2. second
185
- 3. third
186
- EOS
187
- exit_code, messages = redirect_streams do |_, err|
188
- [invoke_cli(%w(-q --failure-level=WARN -o /dev/null), '-') { input }.code, err.string]
189
- end
190
- assert_equal 1, exit_code
191
- assert messages.empty?
192
- end
193
-
194
- test 'should report usage if no input file given' do
195
- redirect_streams do |out, err|
196
- invoke_cli [], nil
197
- assert_match(/Usage:/, err.string)
198
- end
199
- end
200
-
201
- test 'should report error if input file does not exist' do
202
- redirect_streams do |out, err|
203
- invoker = invoke_cli [], 'missing_file.asciidoc'
204
- assert_match(/input file .* is missing/, err.string)
205
- assert_equal 1, invoker.code
206
- end
207
- end
208
-
209
- test 'should treat extra arguments as files' do
210
- redirect_streams do |out, err|
211
- invoker = invoke_cli %w(-o /dev/null extra arguments sample.asciidoc), nil
212
- assert_match(/input file .* is missing/, err.string)
213
- assert_equal 1, invoker.code
214
- end
215
- end
216
-
217
- test 'should output to file name based on input file name' do
218
- sample_outpath = fixture_path 'sample.html'
219
- begin
220
- invoker = invoke_cli
221
- doc = invoker.document
222
- assert_equal sample_outpath, doc.attr('outfile')
223
- assert File.exist?(sample_outpath)
224
- output = IO.read(sample_outpath)
225
- refute_empty output
226
- assert_xpath '/html', output, 1
227
- assert_xpath '/html/head', output, 1
228
- assert_xpath '/html/body', output, 1
229
- assert_xpath '/html/head/title[text() = "Document Title"]', output, 1
230
- assert_xpath '/html/body/*[@id="header"]/h1[text() = "Document Title"]', output, 1
231
- ensure
232
- FileUtils.rm_f(sample_outpath)
233
- end
234
- end
235
-
236
- test 'should output to file in destination directory if set' do
237
- destination_path = File.join testdir, 'test_output'
238
- sample_outpath = File.join destination_path, 'sample.html'
239
- begin
240
- FileUtils.mkdir_p(destination_path)
241
- # QUESTION should -D be relative to working directory or source directory?
242
- invoker = invoke_cli %w(-D test/test_output)
243
- #invoker = invoke_cli %w(-D ../../test/test_output)
244
- doc = invoker.document
245
- assert_equal sample_outpath, doc.attr('outfile')
246
- assert File.exist?(sample_outpath)
247
- ensure
248
- FileUtils.rm_f(sample_outpath)
249
- FileUtils.rmdir(destination_path)
250
- end
251
- end
252
-
253
- test 'should preserve directory structure in destination directory if source directory is set' do
254
- sample_inpath = 'subdir/index.adoc'
255
- destination_path = 'test_output'
256
- destination_subdir_path = File.join destination_path, 'subdir'
257
- sample_outpath = File.join destination_subdir_path, 'index.html'
258
- begin
259
- FileUtils.mkdir_p(destination_path)
260
- invoke_cli %W(-D #{destination_path} -R test/fixtures), sample_inpath
261
- assert File.directory?(destination_subdir_path)
262
- assert File.exist?(sample_outpath)
263
- ensure
264
- FileUtils.rm_f(sample_outpath)
265
- FileUtils.rmdir(destination_subdir_path)
266
- FileUtils.rmdir(destination_path)
267
- end
268
- end
269
-
270
- test 'should output to file specified' do
271
- sample_outpath = fixture_path 'sample-output.html'
272
- begin
273
- invoker = invoke_cli %W(-o #{sample_outpath})
274
- doc = invoker.document
275
- assert_equal sample_outpath, doc.attr('outfile')
276
- assert File.exist?(sample_outpath)
277
- ensure
278
- FileUtils.rm_f(sample_outpath)
279
- end
280
- end
281
-
282
- test 'should copy default stylesheet to target directory if linkcss is specified' do
283
- sample_outpath = fixture_path 'sample-output.html'
284
- asciidoctor_stylesheet = fixture_path 'asciidoctor.css'
285
- coderay_stylesheet = fixture_path 'coderay-asciidoctor.css'
286
- begin
287
- invoker = invoke_cli %W(-o #{sample_outpath} -a linkcss -a source-highlighter=coderay)
288
- invoker.document
289
- assert File.exist?(sample_outpath)
290
- assert File.exist?(asciidoctor_stylesheet)
291
- assert File.exist?(coderay_stylesheet)
292
- ensure
293
- FileUtils.rm_f(sample_outpath)
294
- FileUtils.rm_f(asciidoctor_stylesheet)
295
- FileUtils.rm_f(coderay_stylesheet)
296
- end
297
- end
298
-
299
- test 'should not copy default stylesheet to target directory if linkcss is set and copycss is unset' do
300
- sample_outpath = fixture_path 'sample-output.html'
301
- default_stylesheet = fixture_path 'asciidoctor.css'
302
- begin
303
- invoker = invoke_cli %W(-o #{sample_outpath} -a linkcss -a copycss!)
304
- invoker.document
305
- assert File.exist?(sample_outpath)
306
- refute File.exist?(default_stylesheet)
307
- ensure
308
- FileUtils.rm_f(sample_outpath)
309
- FileUtils.rm_f(default_stylesheet)
310
- end
311
- end
312
-
313
- test 'should copy custom stylesheet to target directory if stylesheet and linkcss is specified' do
314
- destdir = fixture_path 'output'
315
- sample_outpath = File.join destdir, 'sample-output.html'
316
- stylesdir = File.join destdir, 'styles'
317
- custom_stylesheet = File.join stylesdir, 'custom.css'
318
- begin
319
- invoker = invoke_cli %W(-o #{sample_outpath} -a linkcss -a copycss=stylesheets/custom.css -a stylesdir=./styles -a stylesheet=custom.css)
320
- invoker.document
321
- assert File.exist?(sample_outpath)
322
- assert File.exist?(custom_stylesheet)
323
- ensure
324
- FileUtils.rm_f(sample_outpath)
325
- FileUtils.rm_f(custom_stylesheet)
326
- FileUtils.rmdir(stylesdir)
327
- FileUtils.rmdir(destdir)
328
- end
329
- end
330
-
331
- test 'should not copy custom stylesheet to target directory if stylesheet and linkcss are set and copycss is unset' do
332
- destdir = fixture_path 'output'
333
- sample_outpath = File.join destdir, 'sample-output.html'
334
- stylesdir = File.join destdir, 'styles'
335
- custom_stylesheet = File.join stylesdir, 'custom.css'
336
- begin
337
- invoker = invoke_cli %W(-o #{sample_outpath} -a linkcss -a stylesdir=./styles -a stylesheet=custom.css -a copycss!)
338
- invoker.document
339
- assert File.exist?(sample_outpath)
340
- refute File.exist?(custom_stylesheet)
341
- ensure
342
- FileUtils.rm_f(sample_outpath)
343
- FileUtils.rm_f(custom_stylesheet)
344
- FileUtils.rmdir(stylesdir) if File.directory? stylesdir
345
- FileUtils.rmdir(destdir)
346
- end
347
- end
348
-
349
- test 'should not copy custom stylesheet to target directory if stylesdir is a URI' do
350
- destdir = fixture_path 'output'
351
- sample_outpath = File.join destdir, 'sample-output.html'
352
- stylesdir = File.join destdir, 'http:'
353
- begin
354
- invoker = invoke_cli %W(-o #{sample_outpath} -a linkcss -a stylesdir=http://example.org/styles -a stylesheet=custom.css)
355
- invoker.document
356
- assert File.exist?(sample_outpath)
357
- refute File.exist?(stylesdir)
358
- ensure
359
- FileUtils.rm_f(sample_outpath)
360
- FileUtils.rmdir(stylesdir) if File.directory? stylesdir
361
- FileUtils.rmdir(destdir)
362
- end
363
- end
364
-
365
- test 'should convert all passed files' do
366
- basic_outpath = fixture_path 'basic.html'
367
- sample_outpath = fixture_path 'sample.html'
368
- begin
369
- invoke_cli_with_filenames [], %w(basic.asciidoc sample.asciidoc)
370
- assert File.exist?(basic_outpath)
371
- assert File.exist?(sample_outpath)
372
- ensure
373
- FileUtils.rm_f(basic_outpath)
374
- FileUtils.rm_f(sample_outpath)
375
- end
376
- end
377
-
378
- test 'options should not be modified when processing multiple files' do
379
- destination_path = File.join testdir, 'test_output'
380
- basic_outpath = File.join destination_path, 'basic.htm'
381
- sample_outpath = File.join destination_path, 'sample.htm'
382
- begin
383
- invoke_cli_with_filenames %w(-D test/test_output -a outfilesuffix=.htm), %w(basic.asciidoc sample.asciidoc)
384
- assert File.exist?(basic_outpath)
385
- assert File.exist?(sample_outpath)
386
- ensure
387
- FileUtils.rm_f(basic_outpath)
388
- FileUtils.rm_f(sample_outpath)
389
- FileUtils.rmdir(destination_path)
390
- end
391
- end
392
-
393
- test 'should convert all files that matches a glob expression' do
394
- basic_outpath = fixture_path 'basic.html'
395
- begin
396
- invoke_cli_to_buffer [], "ba*.asciidoc"
397
- assert File.exist?(basic_outpath)
398
- ensure
399
- FileUtils.rm_f(basic_outpath)
400
- end
401
- end
402
-
403
- test 'should convert all files that matches an absolute path glob expression' do
404
- basic_outpath = fixture_path 'basic.html'
405
- glob = fixture_path 'ba*.asciidoc'
406
- # test Windows using backslash-style pathname
407
- if File::ALT_SEPARATOR == '\\'
408
- glob = glob.tr '/', '\\'
409
- end
410
-
411
- begin
412
- invoke_cli_to_buffer [], glob
413
- assert File.exist?(basic_outpath)
414
- ensure
415
- FileUtils.rm_f(basic_outpath)
416
- end
417
- end
418
-
419
- test 'should suppress header footer if specified' do
420
- invoker = invoke_cli_to_buffer %w(-s -o -)
421
- output = invoker.read_output
422
- assert_xpath '/html', output, 0
423
- assert_xpath '/*[@id="preamble"]', output, 1
424
- end
425
-
426
- test 'should write page for each alternate manname' do
427
- outdir = fixturedir
428
- outfile_1 = File.join outdir, 'eve.1'
429
- outfile_2 = File.join outdir, 'islifeform.1'
430
- input = <<-EOS
431
- = eve(1)
432
- Andrew Stanton
433
- v1.0.0
434
- :doctype: manpage
435
- :manmanual: EVE
436
- :mansource: EVE
437
-
438
- == NAME
439
-
440
- eve, islifeform - analyzes an image to determine if it's a picture of a life form
441
-
442
- == SYNOPSIS
443
-
444
- *eve* ['OPTION']... 'FILE'...
445
- EOS
446
-
447
- begin
448
- invoke_cli(%W(-b manpage -o #{outfile_1}), '-') { input }
449
- assert File.exist?(outfile_1)
450
- assert File.exist?(outfile_2)
451
- assert_equal '.so eve.1', (IO.read outfile_2).chomp
452
- ensure
453
- FileUtils.rm_f outfile_1
454
- FileUtils.rm_f outfile_2
455
- end
456
- end
457
-
458
- test 'should output a trailing endline to stdout' do
459
- invoker = nil
460
- output = nil
461
- redirect_streams do |out, err|
462
- invoker = invoke_cli %w(-o -)
463
- output = out.string
464
- end
465
- refute_nil invoker
466
- refute_nil output
467
- assert output.end_with?("\n")
468
- end
469
-
470
- test 'should set backend to html5 if specified' do
471
- invoker = invoke_cli_to_buffer %w(-b html5 -o -)
472
- doc = invoker.document
473
- assert_equal 'html5', doc.attr('backend')
474
- assert_equal '.html', doc.attr('outfilesuffix')
475
- output = invoker.read_output
476
- assert_xpath '/html', output, 1
477
- end
478
-
479
- test 'should set backend to docbook45 if specified' do
480
- invoker = invoke_cli_to_buffer %w(-b docbook45 -a xmlns -o -)
481
- doc = invoker.document
482
- assert_equal 'docbook45', doc.attr('backend')
483
- assert_equal '.xml', doc.attr('outfilesuffix')
484
- output = invoker.read_output
485
- assert_xpath '/xmlns:article', output, 1
486
- end
487
-
488
- test 'should set doctype to article if specified' do
489
- invoker = invoke_cli_to_buffer %w(-d article -o -)
490
- doc = invoker.document
491
- assert_equal 'article', doc.attr('doctype')
492
- output = invoker.read_output
493
- assert_xpath '/html/body[@class="article"]', output, 1
494
- end
495
-
496
- test 'should set doctype to book if specified' do
497
- invoker = invoke_cli_to_buffer %w(-d book -o -)
498
- doc = invoker.document
499
- assert_equal 'book', doc.attr('doctype')
500
- output = invoker.read_output
501
- assert_xpath '/html/body[@class="book"]', output, 1
502
- end
503
-
504
- test 'should warn if doctype is inline and the first block is not a candidate for inline conversion' do
505
- ['== Section Title', 'image::tiger.png[]'].each do |input|
506
- warnings = redirect_streams do |out, err|
507
- invoke_cli_to_buffer(%w(-d inline), '-') { input }
508
- err.string
509
- end
510
- assert_match(/WARNING: no inline candidate/, warnings)
511
- end
512
- end
513
-
514
- test 'should not warn if doctype is inline and the document has no blocks' do
515
- warnings = redirect_streams do |out, err|
516
- invoke_cli_to_buffer(%w(-d inline), '-') { '// comment' }
517
- err.string
518
- end
519
- refute_match(/WARNING/, warnings)
520
- end
521
-
522
- test 'should not warn if doctype is inline and the document contains multiple blocks' do
523
- warnings = redirect_streams do |out, err|
524
- invoke_cli_to_buffer(%w(-d inline), '-') { %(paragraph one\n\nparagraph two\n\nparagraph three) }
525
- err.string
526
- end
527
- refute_match(/WARNING/, warnings)
528
- end
529
-
530
- test 'should locate custom templates based on template dir, template engine and backend' do
531
- custom_backend_root = fixture_path 'custom-backends'
532
- invoker = invoke_cli_to_buffer %W(-E haml -T #{custom_backend_root} -o -)
533
- doc = invoker.document
534
- assert_kind_of Asciidoctor::Converter::CompositeConverter, doc.converter
535
- selected = doc.converter.find_converter 'paragraph'
536
- assert_kind_of Asciidoctor::Converter::TemplateConverter, selected
537
- assert_kind_of Tilt::HamlTemplate, selected.templates['paragraph']
538
- end
539
-
540
- test 'should load custom templates from multiple template directories' do
541
- custom_backend_1 = fixture_path 'custom-backends/haml/html5'
542
- custom_backend_2 = fixture_path 'custom-backends/haml/html5-tweaks'
543
- invoker = invoke_cli_to_buffer %W(-T #{custom_backend_1} -T #{custom_backend_2} -o - -s)
544
- output = invoker.read_output
545
- assert_css '.paragraph', output, 0
546
- assert_css '#preamble > .sectionbody > p', output, 1
547
- end
548
-
549
- test 'should set attribute with value' do
550
- invoker = invoke_cli_to_buffer %w(--trace -a idprefix=id -s -o -)
551
- doc = invoker.document
552
- assert_equal 'id', doc.attr('idprefix')
553
- output = invoker.read_output
554
- assert_xpath '//h2[@id="idsection_a"]', output, 1
555
- end
556
-
557
- test 'should set attribute with value containing equal sign' do
558
- invoker = invoke_cli_to_buffer %w(--trace -a toc -a toc-title=t=o=c -o -)
559
- doc = invoker.document
560
- assert_equal 't=o=c', doc.attr('toc-title')
561
- output = invoker.read_output
562
- assert_xpath '//*[@id="toctitle"][text() = "t=o=c"]', output, 1
563
- end
564
-
565
- test 'should set attribute with quoted value containing a space' do
566
- # emulating commandline arguments: --trace -a toc -a note-caption="Note to self:" -o -
567
- invoker = invoke_cli_to_buffer %w(--trace -a toc -a note-caption=Note\ to\ self: -o -)
568
- doc = invoker.document
569
- assert_equal 'Note to self:', doc.attr('note-caption')
570
- output = invoker.read_output
571
- assert_xpath %(//*[#{contains_class('admonitionblock')}]//*[@class='title'][text() = 'Note to self:']), output, 1
572
- end
573
-
574
- test 'should not set attribute ending in @ if defined in document' do
575
- invoker = invoke_cli_to_buffer %w(--trace -a idprefix=id@ -s -o -)
576
- doc = invoker.document
577
- assert_equal 'id_', doc.attr('idprefix')
578
- output = invoker.read_output
579
- assert_xpath '//h2[@id="id_section_a"]', output, 1
580
- end
581
-
582
- test 'should set attribute with no value' do
583
- invoker = invoke_cli_to_buffer %w(-a icons -s -o -)
584
- doc = invoker.document
585
- assert_equal '', doc.attr('icons')
586
- output = invoker.read_output
587
- assert_xpath '//*[@class="admonitionblock note"]//img[@alt="Note"]', output, 1
588
- end
589
-
590
- test 'should unset attribute ending in bang' do
591
- invoker = invoke_cli_to_buffer %w(-a sectids! -s -o -)
592
- doc = invoker.document
593
- refute doc.attr?('sectids')
594
- output = invoker.read_output
595
- # leave the count loose in case we add more sections
596
- assert_xpath '//h2[not(@id)]', output
597
- end
598
-
599
- test 'default mode for cli should be unsafe' do
600
- invoker = invoke_cli_to_buffer %w(-o /dev/null)
601
- doc = invoker.document
602
- assert_equal Asciidoctor::SafeMode::UNSAFE, doc.safe
603
- end
604
-
605
- test 'should set safe mode if specified' do
606
- invoker = invoke_cli_to_buffer %w(--safe -o /dev/null)
607
- doc = invoker.document
608
- assert_equal Asciidoctor::SafeMode::SAFE, doc.safe
609
- end
610
-
611
- test 'should set safe mode to specified level' do
612
- levels = {
613
- 'unsafe' => Asciidoctor::SafeMode::UNSAFE,
614
- 'safe' => Asciidoctor::SafeMode::SAFE,
615
- 'server' => Asciidoctor::SafeMode::SERVER,
616
- 'secure' => Asciidoctor::SafeMode::SECURE,
617
- }
618
- levels.each do |name, const|
619
- invoker = invoke_cli_to_buffer %W(-S #{name} -o /dev/null)
620
- doc = invoker.document
621
- assert_equal const, doc.safe
622
- end
623
- end
624
-
625
- test 'should set eRuby impl if specified' do
626
- invoker = invoke_cli_to_buffer %w(--eruby erubis -o /dev/null)
627
- doc = invoker.document
628
- assert_equal 'erubis', doc.instance_variable_get('@options')[:eruby]
629
- end
630
-
631
- test 'should force default external encoding to UTF-8' do
632
- ruby = File.join RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']
633
- executable = File.join ASCIIDOCTOR_PROJECT_DIR, 'bin', 'asciidoctor'
634
- input_path = fixture_path 'encoding.asciidoc'
635
- old_lang = ENV['LANG']
636
- ENV['LANG'] = 'US-ASCII'
637
- begin
638
- # using open3 to work around a bug in JRuby process_manager.rb,
639
- # which tries to run a gsub on stdout prematurely breaking the test
640
- cmd = %(#{ruby} #{executable} -o - --trace #{input_path})
641
- # warnings may be issued, so don't assert on stderr
642
- stdout_lines = Open3.popen3(cmd) {|_, out| out.readlines }
643
- refute_empty stdout_lines
644
- stdout_lines.each {|l| l.force_encoding Encoding::UTF_8 } if Asciidoctor::FORCE_ENCODING
645
- stdout_str = stdout_lines.join
646
- assert_includes stdout_str, 'Codierungen sind verrückt auf älteren Versionen von Ruby'
647
- ensure
648
- ENV['LANG'] = old_lang
649
- end
650
- end
651
-
652
- test 'should print timings when -t flag is specified' do
653
- input = <<-EOS
654
- Sample *AsciiDoc*
655
- EOS
656
- invoker = nil
657
- error = nil
658
- redirect_streams do |_, err|
659
- invoker = invoke_cli(%w(-t -o /dev/null), '-') { input }
660
- error = err.string
661
- end
662
- refute_nil invoker
663
- refute_nil error
664
- assert_match(/Total time/, error)
665
- end
666
-
667
- test 'should show timezone as UTC if system TZ is set to UTC' do
668
- ruby = File.join RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']
669
- executable = File.join ASCIIDOCTOR_PROJECT_DIR, 'bin', 'asciidoctor'
670
- input_path = fixture_path 'doctime-localtime.adoc'
671
- cmd = %(#{ruby} #{executable} -d inline -o - -s #{input_path})
672
- old_tz = ENV['TZ']
673
- begin
674
- ENV['TZ'] = 'UTC'
675
- result = Open3.popen3(cmd) {|_, out| out.read }
676
- doctime, localtime = result.lines.map {|l| l.chomp }
677
- assert doctime.end_with?(' UTC')
678
- assert localtime.end_with?(' UTC')
679
- rescue
680
- if old_tz
681
- ENV['TZ'] = old_tz
682
- else
683
- ENV.delete 'TZ'
684
- end
685
- end
686
- end
687
-
688
- test 'should show timezone as offset if system TZ is not set to UTC' do
689
- ruby = File.join RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']
690
- executable = File.join ASCIIDOCTOR_PROJECT_DIR, 'bin', 'asciidoctor'
691
- input_path = fixture_path 'doctime-localtime.adoc'
692
- cmd = %(#{ruby} #{executable} -d inline -o - -s #{input_path})
693
- old_tz = ENV['TZ']
694
- begin
695
- ENV['TZ'] = 'EST+5'
696
- result = Open3.popen3(cmd) {|_, out| out.read }
697
- doctime, localtime = result.lines.map {|l| l.chomp }
698
- assert doctime.end_with?(' -0500')
699
- assert localtime.end_with?(' -0500')
700
- ensure
701
- if old_tz
702
- ENV['TZ'] = old_tz
703
- else
704
- ENV.delete 'TZ'
705
- end
706
- end
707
- end
708
-
709
- test 'should use SOURCE_DATE_EPOCH as modified time of input file and local time' do
710
- old_source_date_epoch = ENV.delete 'SOURCE_DATE_EPOCH'
711
- begin
712
- ENV['SOURCE_DATE_EPOCH'] = '1234123412'
713
- sample_filepath = fixture_path 'sample.asciidoc'
714
- invoker = invoke_cli_to_buffer %w(-o /dev/null), sample_filepath
715
- doc = invoker.document
716
- assert_equal '2009-02-08', (doc.attr 'docdate')
717
- assert_equal '2009', (doc.attr 'docyear')
718
- assert_match(/2009-02-08 20:03:32 UTC/, (doc.attr 'docdatetime'))
719
- assert_equal '2009-02-08', (doc.attr 'localdate')
720
- assert_equal '2009', (doc.attr 'localyear')
721
- assert_match(/2009-02-08 20:03:32 UTC/, (doc.attr 'localdatetime'))
722
- ensure
723
- if old_source_date_epoch
724
- ENV['SOURCE_DATE_EPOCH'] = old_source_date_epoch
725
- else
726
- ENV.delete 'SOURCE_DATE_EPOCH'
727
- end
728
- end
729
- end
730
-
731
- test 'should fail if SOURCE_DATE_EPOCH is malformed' do
732
- old_source_date_epoch = ENV.delete 'SOURCE_DATE_EPOCH'
733
- begin
734
- ENV['SOURCE_DATE_EPOCH'] = 'aaaaaaaa'
735
- sample_filepath = fixture_path 'sample.asciidoc'
736
- assert_equal 1, (invoke_cli_to_buffer %w(-o /dev/null), sample_filepath).code
737
- ensure
738
- if old_source_date_epoch
739
- ENV['SOURCE_DATE_EPOCH'] = old_source_date_epoch
740
- else
741
- ENV.delete 'SOURCE_DATE_EPOCH'
742
- end
743
- end
744
- end
745
- end