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,262 +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
-
8
- context 'Options' do
9
- test 'should print usage and return error code 0 when help flag is present' do
10
- redirect_streams do |stdout, stderr|
11
- exitval = Asciidoctor::Cli::Options.parse!(%w(-h))
12
- assert_equal 0, exitval
13
- assert_match(/^Usage:/, stdout.string)
14
- end
15
- end
16
-
17
- test 'should print usage and return error code 0 when help flag is unknown' do
18
- exitval, output = redirect_streams do |out, _|
19
- [Asciidoctor::Cli::Options.parse!(%w(-h unknown)), out.string]
20
- end
21
- assert_equal 0, exitval
22
- assert_match(/^Usage:/, output)
23
- end
24
-
25
- test 'should dump man page and return error code 0 when help topic is manpage' do
26
- exitval, output = redirect_streams do |out, _|
27
- [Asciidoctor::Cli::Options.parse!(%w(-h manpage)), out.string]
28
- end
29
- assert_equal 0, exitval
30
- assert_includes output, 'Manual: Asciidoctor Manual'
31
- assert_includes output, '.TH "ASCIIDOCTOR"'
32
- end
33
-
34
- test 'should print message and return error code 1 when manpage is not found' do
35
- old_manpage_path = ENV['ASCIIDOCTOR_MANPAGE_PATH']
36
- begin
37
- ENV['ASCIIDOCTOR_MANPAGE_PATH'] = (manpage_path = fixture_path 'no-such-file.1')
38
- redirect_streams do |out, stderr|
39
- exitval = Asciidoctor::Cli::Options.parse!(%w(-h manpage))
40
- assert_equal 1, exitval
41
- assert_equal %(asciidoctor: FAILED: manual page not found: #{manpage_path}), stderr.string.chomp
42
- end
43
- ensure
44
- if old_manpage_path
45
- ENV['ASCIIDOCTOR_MANPAGE_PATH'] = old_manpage_path
46
- else
47
- ENV.delete 'ASCIIDOCTOR_MANPAGE_PATH'
48
- end
49
- end
50
- end
51
-
52
- test 'should return error code 1 when invalid option present' do
53
- redirect_streams do |stdout, stderr|
54
- exitval = Asciidoctor::Cli::Options.parse!(%w(--foobar))
55
- assert_equal 1, exitval
56
- assert_equal 'asciidoctor: invalid option: --foobar', stderr.string.chomp
57
- end
58
- end
59
-
60
- test 'should return error code 1 when option has invalid argument' do
61
- redirect_streams do |stdout, stderr|
62
- exitval = Asciidoctor::Cli::Options.parse!(%w(-d chapter input.ad)) # had to change for #320
63
- assert_equal 1, exitval
64
- assert_equal 'asciidoctor: invalid argument: -d chapter', stderr.string.chomp
65
- end
66
- end
67
-
68
- test 'should return error code 1 when option is missing required argument' do
69
- redirect_streams do |stdout, stderr|
70
- exitval = Asciidoctor::Cli::Options.parse!(%w(-b))
71
- assert_equal 1, exitval
72
- assert_equal 'asciidoctor: option missing argument: -b', stderr.string.chomp
73
- end
74
- end
75
-
76
- test 'should emit warning when unparsed options remain' do
77
- redirect_streams do |stdout, stderr|
78
- options = Asciidoctor::Cli::Options.parse!(%w(-b docbook - -))
79
- assert_kind_of Hash, options
80
- assert_match(/asciidoctor: WARNING: extra arguments .*/, stderr.string.chomp)
81
- end
82
- end
83
-
84
- test 'basic argument assignment' do
85
- options = Asciidoctor::Cli::Options.parse!(%w(-v -s -d book test/fixtures/sample.asciidoc))
86
-
87
- assert_equal 2, options[:verbose]
88
- assert_equal false, options[:header_footer]
89
- assert_equal 'book', options[:attributes]['doctype']
90
- assert_equal 1, options[:input_files].size
91
- assert_equal 'test/fixtures/sample.asciidoc', options[:input_files][0]
92
- end
93
-
94
- test 'standard attribute assignment' do
95
- options = Asciidoctor::Cli::Options.parse!(%w(-a docinfosubs=attributes,replacements -a icons test/fixtures/sample.asciidoc))
96
-
97
- assert_equal 'attributes,replacements', options[:attributes]['docinfosubs']
98
- assert_equal '', options[:attributes]['icons']
99
- end
100
-
101
- test 'multiple attribute arguments' do
102
- options = Asciidoctor::Cli::Options.parse!(%w(-a imagesdir=images -a icons test/fixtures/sample.asciidoc))
103
-
104
- assert_equal 'images', options[:attributes]['imagesdir']
105
- assert_equal '', options[:attributes]['icons']
106
- end
107
-
108
- test 'should only split attribute key/value pairs on first equal sign' do
109
- options = Asciidoctor::Cli::Options.parse!(%w(-a name=value=value test/fixtures/sample.asciidoc))
110
-
111
- assert_equal 'value=value', options[:attributes]['name']
112
- end
113
-
114
- test 'should allow safe mode to be specified' do
115
- options = Asciidoctor::Cli::Options.parse!(%w(-S safe test/fixtures/sample.asciidoc))
116
- assert_equal Asciidoctor::SafeMode::SAFE, options[:safe]
117
- end
118
-
119
- test 'should allow any backend to be specified' do
120
- options = Asciidoctor::Cli::Options.parse!(%w(-b my_custom_backend test/fixtures/sample.asciidoc))
121
-
122
- assert_equal 'my_custom_backend', options[:attributes]['backend']
123
- end
124
-
125
- test 'article doctype assignment' do
126
- options = Asciidoctor::Cli::Options.parse!(%w(-d article test/fixtures/sample.asciidoc))
127
- assert_equal 'article', options[:attributes]['doctype']
128
- end
129
-
130
- test 'book doctype assignment' do
131
- options = Asciidoctor::Cli::Options.parse!(%w(-d book test/fixtures/sample.asciidoc))
132
- assert_equal 'book', options[:attributes]['doctype']
133
- end
134
-
135
- test 'inline doctype assignment' do
136
- options = Asciidoctor::Cli::Options.parse!(%w(-d inline test/fixtures/sample.asciidoc))
137
- assert_equal 'inline', options[:attributes]['doctype']
138
- end
139
-
140
- test 'template engine assignment' do
141
- options = Asciidoctor::Cli::Options.parse!(%w(-E haml test/fixtures/sample.asciidoc))
142
- assert_equal 'haml', options[:template_engine]
143
- end
144
-
145
- test 'template directory assignment' do
146
- options = Asciidoctor::Cli::Options.parse!(%w(-T custom-backend test/fixtures/sample.asciidoc))
147
- assert_equal ['custom-backend'], options[:template_dirs]
148
- end
149
-
150
- test 'multiple template directory assignments' do
151
- options = Asciidoctor::Cli::Options.parse!(%w(-T custom-backend -T custom-backend-hacks test/fixtures/sample.asciidoc))
152
- assert_equal ['custom-backend', 'custom-backend-hacks'], options[:template_dirs]
153
- end
154
-
155
- test 'multiple -r flags requires specified libraries' do
156
- options = Asciidoctor::Cli::Options.new
157
- redirect_streams do |stdout, stderr|
158
- exitval = options.parse! %w(-r foobar -r foobaz test/fixtures/sample.asciidoc)
159
- assert_match(%(asciidoctor: FAILED: 'foobar' could not be loaded), stderr.string)
160
- assert_equal 1, exitval
161
- assert_equal ['foobar', 'foobaz'], options[:requires]
162
- end
163
- end
164
-
165
- test '-r flag with multiple values requires specified libraries' do
166
- options = Asciidoctor::Cli::Options.new
167
- redirect_streams do |stdout, stderr|
168
- exitval = options.parse! %w(-r foobar,foobaz test/fixtures/sample.asciidoc)
169
- assert_match(%(asciidoctor: FAILED: 'foobar' could not be loaded), stderr.string)
170
- assert_equal 1, exitval
171
- assert_equal ['foobar', 'foobaz'], options[:requires]
172
- end
173
- end
174
-
175
- test '-I option appends paths to $LOAD_PATH' do
176
- options = Asciidoctor::Cli::Options.new
177
- old_load_path = $LOAD_PATH.dup
178
- begin
179
- exitval = options.parse! %w(-I foobar -I foobaz test/fixtures/sample.asciidoc)
180
- refute_equal 1, exitval
181
- assert_equal old_load_path.size + 2, $LOAD_PATH.size
182
- assert_equal File.expand_path('foobar'), $LOAD_PATH[0]
183
- assert_equal File.expand_path('foobaz'), $LOAD_PATH[1]
184
- assert_equal ['foobar', 'foobaz'], options[:load_paths]
185
- ensure
186
- ($LOAD_PATH.size - old_load_path.size).times { $LOAD_PATH.shift }
187
- end
188
- end
189
-
190
- test '-I option appends multiple paths to $LOAD_PATH' do
191
- options = Asciidoctor::Cli::Options.new
192
- old_load_path = $LOAD_PATH.dup
193
- begin
194
- exitval = options.parse! %W(-I foobar#{File::PATH_SEPARATOR}foobaz test/fixtures/sample.asciidoc)
195
- refute_equal 1, exitval
196
- assert_equal old_load_path.size + 2, $LOAD_PATH.size
197
- assert_equal File.expand_path('foobar'), $LOAD_PATH[0]
198
- assert_equal File.expand_path('foobaz'), $LOAD_PATH[1]
199
- assert_equal ['foobar', 'foobaz'], options[:load_paths]
200
- ensure
201
- ($LOAD_PATH.size - old_load_path.size).times { $LOAD_PATH.shift }
202
- end
203
- end
204
-
205
- test 'should set failure level to FATAL by default' do
206
- options = Asciidoctor::Cli::Options.parse! %W(test/fixtures/sample.asciidoc)
207
- assert_equal ::Logger::Severity::FATAL, options[:failure_level]
208
- end
209
-
210
- test 'should allow failure level to be set to WARN' do
211
- %w(w warn WARN warning WARNING).each do |val|
212
- options = Asciidoctor::Cli::Options.parse!(%W(--failure-level=#{val} test/fixtures/sample.asciidoc))
213
- assert_equal ::Logger::Severity::WARN, options[:failure_level]
214
- end
215
- end
216
-
217
- test 'should allow failure level to be set to ERROR' do
218
- %w(e err ERR error ERROR).each do |val|
219
- options = Asciidoctor::Cli::Options.parse!(%W(--failure-level=#{val} test/fixtures/sample.asciidoc))
220
- assert_equal ::Logger::Severity::ERROR, options[:failure_level]
221
- end
222
- end
223
-
224
- test 'should not allow failure level to be set to unknown value' do
225
- exit_code, messages = redirect_streams do |_, err|
226
- [(Asciidoctor::Cli::Options.parse! %W(--failure-level=foobar test/fixtures/sample.asciidoc)), err.string]
227
- end
228
- assert_equal 1, exit_code
229
- assert_includes messages, 'invalid argument: --failure-level=foobar'
230
- end
231
-
232
- test 'should set verbose to 2 when -v flag is specified' do
233
- options = Asciidoctor::Cli::Options.parse!(%w(-v test/fixtures/sample.asciidoc))
234
- assert_equal 2, options[:verbose]
235
- end
236
-
237
- test 'should set verbose to 0 when -q flag is specified' do
238
- options = Asciidoctor::Cli::Options.parse!(%w(-q test/fixtures/sample.asciidoc))
239
- assert_equal 0, options[:verbose]
240
- end
241
-
242
- test 'should set verbose to 2 when -v flag is specified after -q flag' do
243
- options = Asciidoctor::Cli::Options.parse!(%w(-q -v test/fixtures/sample.asciidoc))
244
- assert_equal 2, options[:verbose]
245
- end
246
-
247
- test 'should set verbose to 0 when -q flag is specified after -v flag' do
248
- options = Asciidoctor::Cli::Options.parse!(%w(-v -q test/fixtures/sample.asciidoc))
249
- assert_equal 0, options[:verbose]
250
- end
251
-
252
- test 'should enable timings when -t flag is specified' do
253
- options = Asciidoctor::Cli::Options.parse!(%w(-t test/fixtures/sample.asciidoc))
254
- assert_equal true, options[:timings]
255
- end
256
-
257
- test 'timings option is disable by default' do
258
- options = Asciidoctor::Cli::Options.parse!(%w(test/fixtures/sample.asciidoc))
259
- assert_equal false, options[:timings]
260
- end
261
-
262
- end
@@ -1,562 +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 'Paragraphs' do
8
- context 'Normal' do
9
- test 'should treat plain text separated by blank lines as paragraphs' do
10
- input = <<-EOS
11
- Plain text for the win!
12
-
13
- Yep. Text. Plain and simple.
14
- EOS
15
- output = convert_string_to_embedded input
16
- assert_css 'p', output, 2
17
- assert_xpath '(//p)[1][text() = "Plain text for the win!"]', output, 1
18
- assert_xpath '(//p)[2][text() = "Yep. Text. Plain and simple."]', output, 1
19
- end
20
-
21
- test 'should associate block title with paragraph' do
22
- input = <<-EOS
23
- .Titled
24
- Paragraph.
25
-
26
- Winning.
27
- EOS
28
- output = convert_string_to_embedded input
29
-
30
- assert_css 'p', output, 2
31
- assert_xpath '(//p)[1]/preceding-sibling::*[@class = "title"]', output, 1
32
- assert_xpath '(//p)[1]/preceding-sibling::*[@class = "title"][text() = "Titled"]', output, 1
33
- assert_xpath '(//p)[2]/preceding-sibling::*[@class = "title"]', output, 0
34
- end
35
-
36
- test 'no duplicate block before next section' do
37
- input = <<-EOS
38
- = Title
39
-
40
- Preamble
41
-
42
- == First Section
43
-
44
- Paragraph 1
45
-
46
- Paragraph 2
47
-
48
- == Second Section
49
-
50
- Last words
51
- EOS
52
-
53
- output = convert_string input
54
- assert_xpath '//p[text() = "Paragraph 2"]', output, 1
55
- end
56
-
57
- test 'does not treat wrapped line as a list item' do
58
- input = <<-EOS
59
- paragraph
60
- . wrapped line
61
- EOS
62
-
63
- output = convert_string_to_embedded input
64
- assert_css 'p', output, 1
65
- assert_xpath %(//p[text()="paragraph\n. wrapped line"]), output, 1
66
- end
67
-
68
- test 'does not treat wrapped line as a block title' do
69
- input = <<-EOS
70
- paragraph
71
- .wrapped line
72
- EOS
73
-
74
- output = convert_string_to_embedded input
75
- assert_css 'p', output, 1
76
- assert_xpath %(//p[text()="paragraph\n.wrapped line"]), output, 1
77
- end
78
-
79
- test 'interprets normal paragraph style as normal paragraph' do
80
- input = <<-EOS
81
- [normal]
82
- Normal paragraph.
83
- Nothing special.
84
- EOS
85
-
86
- output = convert_string_to_embedded input
87
- assert_css 'p', output, 1
88
- end
89
-
90
- test 'removes indentation from literal paragraph marked as normal' do
91
- input = <<-EOS
92
- [normal]
93
- Normal paragraph.
94
- Nothing special.
95
- Last line.
96
- EOS
97
-
98
- output = convert_string_to_embedded input
99
- assert_css 'p', output, 1
100
- assert_xpath %(//p[text()="Normal paragraph.\n Nothing special.\nLast line."]), output, 1
101
- end
102
-
103
- test 'normal paragraph terminates at block attribute list' do
104
- input = <<-EOS
105
- normal text
106
- [literal]
107
- literal text
108
- EOS
109
- output = convert_string_to_embedded input
110
- assert_css '.paragraph:root', output, 1
111
- assert_css '.literalblock:root', output, 1
112
- end
113
-
114
- test 'normal paragraph terminates at block delimiter' do
115
- input = <<-EOS
116
- normal text
117
- --
118
- text in open block
119
- --
120
- EOS
121
- output = convert_string_to_embedded input
122
- assert_css '.paragraph:root', output, 1
123
- assert_css '.openblock:root', output, 1
124
- end
125
-
126
- test 'normal paragraph terminates at list continuation' do
127
- input = <<-EOS
128
- normal text
129
- +
130
- EOS
131
- output = convert_string_to_embedded input
132
- assert_css '.paragraph:root', output, 2
133
- assert_xpath %((/*[@class="paragraph"])[1]/p[text() = "normal text"]), output, 1
134
- assert_xpath %((/*[@class="paragraph"])[2]/p[text() = "+"]), output, 1
135
- end
136
-
137
- test 'normal style turns literal paragraph into normal paragraph' do
138
- input = <<-EOS
139
- [normal]
140
- normal paragraph,
141
- despite the leading indent
142
- EOS
143
-
144
- output = convert_string_to_embedded input
145
- assert_css '.paragraph:root > p', output, 1
146
- end
147
-
148
- test 'expands index term macros in DocBook backend' do
149
- input = <<-EOS
150
- Here is an index entry for ((tigers)).
151
- indexterm:[Big cats,Tigers,Siberian Tiger]
152
- Here is an index entry for indexterm2:[Linux].
153
- (((Operating Systems,Linux,Fedora)))
154
- Note that multi-entry terms generate separate index entries.
155
- EOS
156
-
157
- output = convert_string_to_embedded input, :attributes => {'backend' => 'docbook45'}
158
- assert_xpath '/simpara', output, 1
159
- term1 = xmlnodes_at_xpath '(//indexterm)[1]', output, 1
160
- assert_equal '<indexterm><primary>tigers</primary></indexterm>', term1.to_s
161
- assert term1.next.content.start_with?('tigers')
162
-
163
- term2 = xmlnodes_at_xpath '(//indexterm)[2]', output, 1
164
- term2_elements = term2.elements
165
- assert_equal 3, term2_elements.size
166
- assert_equal '<primary>Big cats</primary>', term2_elements[0].to_s
167
- assert_equal '<secondary>Tigers</secondary>', term2_elements[1].to_s
168
- assert_equal '<tertiary>Siberian Tiger</tertiary>', term2_elements[2].to_s
169
-
170
- term3 = xmlnodes_at_xpath '(//indexterm)[3]', output, 1
171
- term3_elements = term3.elements
172
- assert_equal 2, term3_elements.size
173
- assert_equal '<primary>Tigers</primary>', term3_elements[0].to_s
174
- assert_equal '<secondary>Siberian Tiger</secondary>', term3_elements[1].to_s
175
-
176
- term4 = xmlnodes_at_xpath '(//indexterm)[4]', output, 1
177
- term4_elements = term4.elements
178
- assert_equal 1, term4_elements.size
179
- assert_equal '<primary>Siberian Tiger</primary>', term4_elements[0].to_s
180
-
181
- term5 = xmlnodes_at_xpath '(//indexterm)[5]', output, 1
182
- assert_equal '<indexterm><primary>Linux</primary></indexterm>', term5.to_s
183
- assert term5.next.content.start_with?('Linux')
184
-
185
- assert_xpath '(//indexterm)[6]/*', output, 3
186
- assert_xpath '(//indexterm)[7]/*', output, 2
187
- assert_xpath '(//indexterm)[8]/*', output, 1
188
- end
189
-
190
- test 'normal paragraph should honor explicit subs list' do
191
- input = <<-EOS
192
- [subs="specialcharacters"]
193
- *<Hey Jude>*
194
- EOS
195
-
196
- output = convert_string_to_embedded input
197
- assert_includes output, '*&lt;Hey Jude&gt;*'
198
- end
199
-
200
- test 'normal paragraph should honor specialchars shorthand' do
201
- input = <<-EOS
202
- [subs="specialchars"]
203
- *<Hey Jude>*
204
- EOS
205
-
206
- output = convert_string_to_embedded input
207
- assert_includes output, '*&lt;Hey Jude&gt;*'
208
- end
209
-
210
- test 'should add a hardbreak at end of each line when hardbreaks option is set' do
211
- input = <<-EOS
212
- [%hardbreaks]
213
- read
214
- my
215
- lips
216
- EOS
217
-
218
- output = convert_string_to_embedded input
219
- assert_css 'br', output, 2
220
- assert_xpath '//p', output, 1
221
- assert_includes output, "<p>read<br>\nmy<br>\nlips</p>"
222
- end
223
- end
224
-
225
- context 'Literal' do
226
- test 'single-line literal paragraphs' do
227
- input = <<-EOS
228
- LITERALS
229
-
230
- ARE LITERALLY
231
-
232
- AWESOME!
233
- EOS
234
- output = convert_string_to_embedded input
235
- assert_xpath '//pre', output, 3
236
- end
237
-
238
- test 'multi-line literal paragraph' do
239
- input = <<-EOS
240
- Install instructions:
241
-
242
- yum install ruby rubygems
243
- gem install asciidoctor
244
-
245
- You're good to go!
246
- EOS
247
- output = convert_string_to_embedded input
248
- assert_xpath '//pre', output, 1
249
- # indentation should be trimmed from literal block
250
- assert_xpath %(//pre[text() = "yum install ruby rubygems\ngem install asciidoctor"]), output, 1
251
- end
252
-
253
- test 'literal paragraph' do
254
- input = <<-EOS
255
- [literal]
256
- this text is literally literal
257
- EOS
258
- output = convert_string_to_embedded input
259
- assert_xpath %(/*[@class="literalblock"]//pre[text()="this text is literally literal"]), output, 1
260
- end
261
-
262
- test 'should read content below literal style verbatim' do
263
- input = <<-EOS
264
- [literal]
265
- image::not-an-image-block[]
266
- EOS
267
- output = convert_string_to_embedded input
268
- assert_xpath %(/*[@class="literalblock"]//pre[text()="image::not-an-image-block[]"]), output, 1
269
- assert_css 'img', output, 0
270
- end
271
-
272
- test 'listing paragraph' do
273
- input = <<-EOS
274
- [listing]
275
- this text is a listing
276
- EOS
277
- output = convert_string_to_embedded input
278
- assert_xpath %(/*[@class="listingblock"]//pre[text()="this text is a listing"]), output, 1
279
- end
280
-
281
- test 'source paragraph' do
282
- input = <<-EOS
283
- [source]
284
- use the source, luke!
285
- EOS
286
- output = convert_string_to_embedded input
287
- assert_xpath %(/*[@class="listingblock"]//pre[@class="highlight"]/code[text()="use the source, luke!"]), output, 1
288
- end
289
-
290
- test 'source code paragraph with language' do
291
- input = <<-EOS
292
- [source, perl]
293
- die 'zomg perl sucks';
294
- EOS
295
- output = convert_string_to_embedded input
296
- assert_xpath %(/*[@class="listingblock"]//pre[@class="highlight"]/code[@class="language-perl"][@data-lang="perl"][text()="die 'zomg perl sucks';"]), output, 1
297
- end
298
-
299
- test 'literal paragraph terminates at block attribute list' do
300
- input = <<-EOS
301
- literal text
302
- [normal]
303
- normal text
304
- EOS
305
- output = convert_string_to_embedded input
306
- assert_xpath %(/*[@class="literalblock"]), output, 1
307
- assert_xpath %(/*[@class="paragraph"]), output, 1
308
- end
309
-
310
- test 'literal paragraph terminates at block delimiter' do
311
- input = <<-EOS
312
- literal text
313
- --
314
- normal text
315
- --
316
- EOS
317
- output = convert_string_to_embedded input
318
- assert_xpath %(/*[@class="literalblock"]), output, 1
319
- assert_xpath %(/*[@class="openblock"]), output, 1
320
- end
321
-
322
- test 'literal paragraph terminates at list continuation' do
323
- input = <<-EOS
324
- literal text
325
- +
326
- EOS
327
- output = convert_string_to_embedded input
328
- assert_xpath %(/*[@class="literalblock"]), output, 1
329
- assert_xpath %(/*[@class="literalblock"]//pre[text() = "literal text"]), output, 1
330
- assert_xpath %(/*[@class="paragraph"]), output, 1
331
- assert_xpath %(/*[@class="paragraph"]/p[text() = "+"]), output, 1
332
- end
333
- end
334
-
335
- context 'Quote' do
336
- test "single-line quote paragraph" do
337
- input = <<-EOS
338
- [quote]
339
- Famous quote.
340
- EOS
341
- output = convert_string input
342
- assert_xpath '//*[@class = "quoteblock"]', output, 1
343
- assert_xpath '//*[@class = "quoteblock"]//p', output, 0
344
- assert_xpath '//*[@class = "quoteblock"]//*[contains(text(), "Famous quote.")]', output, 1
345
- end
346
-
347
- test 'quote paragraph terminates at list continuation' do
348
- input = <<-EOS
349
- [quote]
350
- A famouse quote.
351
- +
352
- EOS
353
- output = convert_string_to_embedded input
354
- assert_css '.quoteblock:root', output, 1
355
- assert_css '.paragraph:root', output, 1
356
- assert_xpath %(/*[@class="paragraph"]/p[text() = "+"]), output, 1
357
- end
358
-
359
- test "verse paragraph" do
360
- output = convert_string("[verse]\nFamous verse.")
361
- assert_xpath '//*[@class = "verseblock"]', output, 1
362
- assert_xpath '//*[@class = "verseblock"]/pre', output, 1
363
- assert_xpath '//*[@class = "verseblock"]//p', output, 0
364
- assert_xpath '//*[@class = "verseblock"]/pre[normalize-space(text()) = "Famous verse."]', output, 1
365
- end
366
-
367
- test 'should perform normal subs on a verse paragraph' do
368
- input = <<-EOS
369
- [verse]
370
- _GET /groups/link:#group-id[\{group-id\}]_
371
- EOS
372
-
373
- output = convert_string_to_embedded input
374
- assert_includes output, '<pre class="content"><em>GET /groups/<a href="#group-id">{group-id}</a></em></pre>'
375
- end
376
-
377
- test 'quote paragraph should honor explicit subs list' do
378
- input = <<-EOS
379
- [subs="specialcharacters"]
380
- [quote]
381
- *Hey Jude*
382
- EOS
383
-
384
- output = convert_string_to_embedded input
385
- assert_includes output, '*Hey Jude*'
386
- end
387
- end
388
-
389
- context "special" do
390
- test "note multiline syntax" do
391
- Asciidoctor::ADMONITION_STYLES.each do |style|
392
- assert_xpath "//div[@class='admonitionblock #{style.downcase}']", convert_string("[#{style}]\nThis is a winner.")
393
- end
394
- end
395
-
396
- test "note block syntax" do
397
- Asciidoctor::ADMONITION_STYLES.each do |style|
398
- assert_xpath "//div[@class='admonitionblock #{style.downcase}']", convert_string("[#{style}]\n====\nThis is a winner.\n====")
399
- end
400
- end
401
-
402
- test "note inline syntax" do
403
- Asciidoctor::ADMONITION_STYLES.each do |style|
404
- assert_xpath "//div[@class='admonitionblock #{style.downcase}']", convert_string("#{style}: This is important, fool!")
405
- end
406
- end
407
-
408
- test "sidebar block" do
409
- input = <<-EOS
410
- == Section
411
-
412
- .Sidebar
413
- ****
414
- Content goes here
415
- ****
416
- EOS
417
- result = convert_string(input)
418
- assert_xpath "//*[@class='sidebarblock']//p", result, 1
419
- end
420
-
421
- test 'should process preprocessor conditional in paragrpah content' do
422
- input = <<-EOS
423
- ifdef::asciidoctor-version[]
424
- [sidebar]
425
- First line of sidebar.
426
- ifdef::backend[The backend is {backend}.]
427
- Last line of sidebar.
428
- endif::[]
429
- EOS
430
-
431
- result = convert_string_to_embedded input
432
- assert_equal %(<div class="sidebarblock">
433
- <div class="content">
434
- First line of sidebar.
435
- The backend is html5.
436
- Last line of sidebar.
437
- </div>
438
- </div>), result
439
- end
440
-
441
- context 'Styled Paragraphs' do
442
- test 'should wrap text in simpara for styled paragraphs when converted to DocBook' do
443
- input = <<-EOS
444
- = Book
445
- :doctype: book
446
-
447
- [preface]
448
- = About this book
449
-
450
- [abstract]
451
- An abstract for the book.
452
-
453
- = Part 1
454
-
455
- [partintro]
456
- An intro to this part.
457
-
458
- == Chapter 1
459
-
460
- [sidebar]
461
- Just a side note.
462
-
463
- [example]
464
- As you can see here.
465
-
466
- [quote]
467
- Wise words from a wise person.
468
-
469
- [open]
470
- Make it what you want.
471
- EOS
472
-
473
- output = convert_string input, :backend => 'docbook'
474
- assert_css 'abstract > simpara', output, 1
475
- assert_css 'partintro > simpara', output, 1
476
- assert_css 'sidebar > simpara', output, 1
477
- assert_css 'informalexample > simpara', output, 1
478
- assert_css 'blockquote > simpara', output, 1
479
- assert_css 'chapter > simpara', output, 1
480
- end
481
-
482
- test 'should convert open paragraph to open block' do
483
- input = <<-EOS
484
- [open]
485
- Make it what you want.
486
- EOS
487
-
488
- output = convert_string_to_embedded input
489
- assert_css '.openblock', output, 1
490
- assert_css '.openblock p', output, 0
491
- end
492
-
493
- test 'should wrap text in simpara for styled paragraphs with title when converted to DocBook' do
494
- input = <<-EOS
495
- = Book
496
- :doctype: book
497
-
498
- [preface]
499
- = About this book
500
-
501
- [abstract]
502
- .Abstract title
503
- An abstract for the book.
504
-
505
- = Part 1
506
-
507
- [partintro]
508
- .Part intro title
509
- An intro to this part.
510
-
511
- == Chapter 1
512
-
513
- [sidebar]
514
- .Sidebar title
515
- Just a side note.
516
-
517
- [example]
518
- .Example title
519
- As you can see here.
520
-
521
- [quote]
522
- .Quote title
523
- Wise words from a wise person.
524
- EOS
525
-
526
- output = convert_string input, :backend => 'docbook'
527
- assert_css 'abstract > title', output, 1
528
- assert_xpath '//abstract/title[text() = "Abstract title"]', output, 1
529
- assert_css 'abstract > title + simpara', output, 1
530
- assert_css 'partintro > title', output, 1
531
- assert_xpath '//partintro/title[text() = "Part intro title"]', output, 1
532
- assert_css 'partintro > title + simpara', output, 1
533
- assert_css 'sidebar > title', output, 1
534
- assert_xpath '//sidebar/title[text() = "Sidebar title"]', output, 1
535
- assert_css 'sidebar > title + simpara', output, 1
536
- assert_css 'example > title', output, 1
537
- assert_xpath '//example/title[text() = "Example title"]', output, 1
538
- assert_css 'example > title + simpara', output, 1
539
- assert_css 'blockquote > title', output, 1
540
- assert_xpath '//blockquote/title[text() = "Quote title"]', output, 1
541
- assert_css 'blockquote > title + simpara', output, 1
542
- end
543
- end
544
-
545
- context 'Inline doctype' do
546
- test 'should only format and output text in first paragraph when doctype is inline' do
547
- input = "http://asciidoc.org[AsciiDoc] is a _lightweight_ markup language...\n\nignored"
548
- output = convert_string input, :doctype => 'inline'
549
- assert_equal '<a href="http://asciidoc.org">AsciiDoc</a> is a <em>lightweight</em> markup language&#8230;&#8203;', output
550
- end
551
-
552
- test 'should output nil and warn if first block is not a paragraph' do
553
- input = '* bullet'
554
- using_memory_logger do |logger|
555
- output = convert_string input, :doctype => 'inline'
556
- assert_nil output
557
- assert_message logger, :WARN, '~no inline candidate'
558
- end
559
- end
560
- end
561
- end
562
- end