asciidoctor 1.5.8 → 2.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
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,4 +0,0 @@
1
- [#section-a]
2
- == Section A
3
-
4
- contents
@@ -1,3 +0,0 @@
1
- body {
2
- color: red;
3
- }
@@ -1,3 +0,0 @@
1
- = Sample Document
2
-
3
- content
@@ -1,3 +0,0 @@
1
- first line of inner
2
-
3
- last line of inner
@@ -1,5 +0,0 @@
1
- first line of middle
2
-
3
- include::inner-include.adoc[]
4
-
5
- last line of middle
@@ -1,2 +0,0 @@
1
- <meta name="copyright" content="(C) OpenDevise">
2
- <script src="bootstrap.{bootstrap-version}.min.js"></script>
@@ -1,6 +0,0 @@
1
- = Document Title
2
- Doc Writer <doc.writer@asciidoc.org>
3
- v1.0, 2013-01-01
4
- :bootstrap-version: 3.2.0
5
-
6
- Body content.
@@ -1,25 +0,0 @@
1
- #tag::all[]
2
- class Dog
3
- #tag::init[]
4
- def initialize breed
5
- @breed = breed
6
- end
7
- #end::init[]
8
- #tag::bark[]
9
-
10
- def bark
11
- #tag::bark-beagle[]
12
- if @breed == 'beagle'
13
- 'woof woof woof woof woof'
14
- #end::bark-beagle[]
15
- #tag::bark-other[]
16
- else
17
- 'woof woof'
18
- #end::bark-other[]
19
- #tag::bark-all[]
20
- end
21
- #end::bark-all[]
22
- end
23
- #end::bark[]
24
- end
25
- #end::all[]
@@ -1,23 +0,0 @@
1
- class Dog
2
- #tag::init[]
3
- def initialize breed
4
- @breed = breed
5
- end
6
- #end::init[]
7
- #tag::bark[]
8
-
9
- def bark
10
- #tag::bark-beagle[]
11
- if @breed == 'beagle'
12
- 'woof woof woof woof woof'
13
- #end::bark-beagle[]
14
- #tag::bark-other[]
15
- else
16
- 'woof woof'
17
- #end::bark-other[]
18
- #tag::bark-all[]
19
- end
20
- #end::bark-all[]
21
- end
22
- #end::bark[]
23
- end
Binary file
@@ -1,3 +0,0 @@
1
- x
2
- // tag::a[]
3
- a
@@ -1,4 +0,0 @@
1
- // tag::a[]
2
- a
3
- // end::a[]
4
- // end::a[]
@@ -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