asciidoctor 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of asciidoctor might be problematic. Click here for more details.

Files changed (40) hide show
  1. data/README.asciidoc +11 -2
  2. data/asciidoctor.gemspec +3 -2
  3. data/lib/asciidoctor.rb +95 -62
  4. data/lib/asciidoctor/abstract_block.rb +7 -5
  5. data/lib/asciidoctor/abstract_node.rb +63 -15
  6. data/lib/asciidoctor/attribute_list.rb +3 -1
  7. data/lib/asciidoctor/backends/base_template.rb +17 -7
  8. data/lib/asciidoctor/backends/docbook45.rb +182 -150
  9. data/lib/asciidoctor/backends/html5.rb +138 -110
  10. data/lib/asciidoctor/block.rb +21 -18
  11. data/lib/asciidoctor/callouts.rb +3 -1
  12. data/lib/asciidoctor/cli/invoker.rb +3 -3
  13. data/lib/asciidoctor/cli/options.rb +6 -6
  14. data/lib/asciidoctor/debug.rb +7 -6
  15. data/lib/asciidoctor/document.rb +197 -25
  16. data/lib/asciidoctor/errors.rb +1 -1
  17. data/lib/asciidoctor/helpers.rb +29 -0
  18. data/lib/asciidoctor/inline.rb +11 -4
  19. data/lib/asciidoctor/lexer.rb +338 -182
  20. data/lib/asciidoctor/list_item.rb +14 -12
  21. data/lib/asciidoctor/reader.rb +423 -206
  22. data/lib/asciidoctor/renderer.rb +59 -15
  23. data/lib/asciidoctor/section.rb +7 -4
  24. data/lib/asciidoctor/substituters.rb +536 -511
  25. data/lib/asciidoctor/table.rb +473 -472
  26. data/lib/asciidoctor/version.rb +1 -1
  27. data/man/asciidoctor.1 +23 -14
  28. data/man/asciidoctor.ad +13 -7
  29. data/test/attributes_test.rb +42 -8
  30. data/test/blocks_test.rb +161 -1
  31. data/test/document_test.rb +134 -16
  32. data/test/invoker_test.rb +14 -6
  33. data/test/lexer_test.rb +45 -18
  34. data/test/lists_test.rb +79 -0
  35. data/test/paragraphs_test.rb +9 -1
  36. data/test/reader_test.rb +456 -19
  37. data/test/sections_test.rb +19 -0
  38. data/test/substitutions_test.rb +14 -12
  39. data/test/tables_test.rb +10 -10
  40. metadata +3 -5
@@ -1,3 +1,3 @@
1
1
  module Asciidoctor
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/man/asciidoctor.1 CHANGED
@@ -2,12 +2,12 @@
2
2
  .\" Title: asciidoctor
3
3
  .\" Author: [see the "AUTHORS" section]
4
4
  .\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
5
- .\" Date: 01/30/2013
5
+ .\" Date: 02/18/2013
6
6
  .\" Manual: \ \&
7
7
  .\" Source: \ \&
8
8
  .\" Language: English
9
9
  .\"
10
- .TH "ASCIIDOCTOR" "1" "01/30/2013" "\ \&" "\ \&"
10
+ .TH "ASCIIDOCTOR" "1" "02/18/2013" "\ \&" "\ \&"
11
11
  .\" -----------------------------------------------------------------
12
12
  .\" * Define some portability stuff
13
13
  .\" -----------------------------------------------------------------
@@ -47,19 +47,22 @@ Base directory containing the document and resources\&. Defaults to the director
47
47
  .PP
48
48
  \fB\-S, \-\-safe\-mode\fR=\fISAFE_MODE\fR
49
49
  .RS 4
50
- Set safe mode level explicity:
50
+ Set safe mode level:
51
51
  \fIunsafe\fR,
52
52
  \fIsafe\fR,
53
- \fIsecure\fR\&. Defaults to
54
- \fIsecure\fR\&. Disables potentially dangerous macros in source files, such as include::[]\&.
53
+ \fIserver\fR
54
+ or
55
+ \fIsecure\fR\&. Disables potentially dangerous macros in source files, such as include::[]\&. If not set, the safe mode level defaults to
56
+ \fIunsafe\fR
57
+ when Asciidoctor is invoked using this script\&.
55
58
  .RE
56
59
  .PP
57
60
  \fB\-\-safe\fR
58
61
  .RS 4
59
- Set safe mode to
60
- \fIsafe\fR
61
- from the default safe mode of
62
- \fIsecure\fR\&. Enables include macros, but restricts access to ancestor paths of source file\&. Provided for compatibility with the asciidoc command\&.
62
+ Set safe mode level to
63
+ \fIsafe\fR\&. Enables include macros, but restricts access to ancestor paths of source file\&. Provided for compatibility with the asciidoc command\&. If not set, the safe mode level defaults to
64
+ \fIunsafe\fR
65
+ when Asciidoctor is invoked using this script\&.
63
66
  .RE
64
67
  .SS "Document Settings"
65
68
  .PP
@@ -161,7 +164,7 @@ Suppress the document header and footer in the output\&.
161
164
  .PP
162
165
  \fB\-T, \-\-template\-dir\fR=\fIDIR\fR
163
166
  .RS 4
164
- Directory containing custom render templates that override one or more templates from the the built\-in set\&.
167
+ Directory containing custom render templates that override one or more templates from the the built\-in set\&. If there is a folder in the directory that matches the backend, the templates from that folder will be used\&.
165
168
  .RE
166
169
  .SS "Processing Information"
167
170
  .PP
@@ -198,15 +201,21 @@ Failure (syntax or usage error; configuration error; document processing failure
198
201
  .RE
199
202
  .SH "BUGS"
200
203
  .sp
201
- See the \fBAsciidoctor\fR issue tracker: <\fBhttps://github\&.com/erebor/asciidoctor/issues?state=open\fR>
204
+ See the \fBAsciidoctor\fR issue tracker: <\fBhttps://github\&.com/asciidoctor/asciidoctor/issues?state=open\fR>
202
205
  .SH "AUTHORS"
203
206
  .sp
204
- \fBAsciidoctor\fR was written by Ryan Waldron, Dan Allen and other contributors\&. \fBAsciiDoc\fR was written by Stuart Rackham and has received contributions from many other individuals\&.
207
+ \fBAsciidoctor\fR was written by Ryan Waldron, Dan Allen and other contributors\&.
208
+ .sp
209
+ \fBAsciiDoc\fR was written by Stuart Rackham and has received contributions from many other individuals\&.
205
210
  .SH "RESOURCES"
206
211
  .sp
207
- Git source repository on GitHub: <\fBhttps://github\&.com/erebor/asciidoctor\fR>
212
+ Git source repository on GitHub: <\fBhttps://github\&.com/asciidoctor/asciidoctor\fR>
213
+ .sp
214
+ Project web site: <\fBhttp://asciidoctor\&.org\fR>
215
+ .sp
216
+ GitHub organization: <\fBhttp://github\&.com/asciidoctor\fR>
208
217
  .sp
209
- Main web site: <\fBhttp://asciidoctor\&.org\fR>
218
+ Mailinglist / forum: <\fBhttp://discuss\&.asciidoctor\&.org\fR>
210
219
  .SH "COPYING"
211
220
  .sp
212
221
  Copyright (C) Ryan Waldron\&. Free use of this software is granted under the terms of the MIT License\&.
data/man/asciidoctor.ad CHANGED
@@ -34,14 +34,16 @@ Security Settings
34
34
  of the program.
35
35
 
36
36
  *-S, --safe-mode*='SAFE_MODE'::
37
- Set safe mode level explicity: 'unsafe', 'safe', 'secure'. Defaults to
38
- 'secure'. Disables potentially dangerous macros in source files, such as
39
- include::[].
37
+ Set safe mode level: 'unsafe', 'safe', 'server' or 'secure'. Disables
38
+ potentially dangerous macros in source files, such as include::[]. If not
39
+ set, the safe mode level defaults to 'unsafe' when Asciidoctor is invoked
40
+ using this script.
40
41
 
41
42
  *--safe*::
42
- Set safe mode to 'safe' from the default safe mode of 'secure'. Enables
43
- include macros, but restricts access to ancestor paths of source file.
44
- Provided for compatibility with the asciidoc command.
43
+ Set safe mode level to 'safe'. Enables include macros, but restricts access
44
+ to ancestor paths of source file. Provided for compatibility with the
45
+ asciidoc command. If not set, the safe mode level defaults to 'unsafe' when
46
+ Asciidoctor is invoked using this script.
45
47
 
46
48
  Document Settings
47
49
  ~~~~~~~~~~~~~~~~~
@@ -97,7 +99,8 @@ Rendering Control
97
99
 
98
100
  *-T, --template-dir*='DIR'::
99
101
  Directory containing custom render templates that override one or more
100
- templates from the the built-in set.
102
+ templates from the the built-in set. If there is a folder in the directory
103
+ that matches the backend, the templates from that folder will be used.
101
104
 
102
105
  Processing Information
103
106
  ~~~~~~~~~~~~~~~~~~~~~~
@@ -137,6 +140,7 @@ See the *Asciidoctor* issue tracker: <**https://github.com/asciidoctor/asciidoct
137
140
  AUTHORS
138
141
  -------
139
142
  *Asciidoctor* was written by Ryan Waldron, Dan Allen and other contributors.
143
+
140
144
  *AsciiDoc* was written by Stuart Rackham and has received contributions from
141
145
  many other individuals.
142
146
 
@@ -149,6 +153,8 @@ Project web site: <**http://asciidoctor.org**>
149
153
 
150
154
  GitHub organization: <**http://github.com/asciidoctor**>
151
155
 
156
+ Mailinglist / forum: <**http://discuss.asciidoctor.org**>
157
+
152
158
 
153
159
  COPYING
154
160
  -------
@@ -7,6 +7,11 @@ context 'Attributes' do
7
7
  assert_equal 'Tanglefoot', doc.attributes['frog']
8
8
  end
9
9
 
10
+ test 'requires a space after colon following attribute name' do
11
+ doc = document_from_string 'foo:bar'
12
+ assert_equal nil, doc.attributes['foo']
13
+ end
14
+
10
15
  test 'creates an attribute by fusing a multi-line value' do
11
16
  str = <<-EOS
12
17
  :description: This is the first +
@@ -130,9 +135,15 @@ endif::holygrail[]
130
135
  end
131
136
 
132
137
  test "convert multi-word names and render" do
133
- html = render_string("Main Header\n===========\n:My frog: Tanglefoot\n\nYo, {myfrog}!")
134
- result = Nokogiri::HTML(html)
135
- assert_equal 'Yo, Tanglefoot!', result.css("p").first.content.strip
138
+ input = <<-EOS
139
+ Main Header
140
+ ===========
141
+ :My frog: Tanglefoot
142
+
143
+ Yo, {myfrog}!
144
+ EOS
145
+ output = render_string input
146
+ assert_xpath '(//p)[1][text()="Yo, Tanglefoot!"]', output, 1
136
147
  end
137
148
 
138
149
  test "ignores lines with bad attributes" do
@@ -182,11 +193,18 @@ To use {gem_name}, the first thing to do is to import it in your Ruby source fil
182
193
  end
183
194
 
184
195
  test 'renders attribute until it is deleted' do
185
- pending 'This requires that we consume attributes as the document is being lexed, not up front'
186
- #output = render_string(":foo: bar\n\nCrossing the {foo}\n\n:foo!:\nBelly up to the {foo}")
187
- # result = Nokogiri::HTML(html)
188
- # assert_match /Crossing the bar/, result.css("p").first.content.strip
189
- # assert_no_match /Belly up to the bar/, result.css("p").last.content.strip
196
+ input = <<-EOS
197
+ :foo: bar
198
+
199
+ Crossing the {foo}.
200
+
201
+ :foo!:
202
+
203
+ Belly up to the {foo}.
204
+ EOS
205
+ output = render_embedded_string input
206
+ assert_xpath '//p[text()="Crossing the bar."]', output, 1
207
+ assert_xpath '//p[text()="Belly up to the bar."]', output, 0
190
208
  end
191
209
 
192
210
  test 'does not disturb attribute-looking things escaped with backslash' do
@@ -421,6 +439,22 @@ paragraph
421
439
  assert_equal 'coolio', subsec.id
422
440
  end
423
441
 
442
+ test 'block id above document title sets id on document' do
443
+ input = <<-EOS
444
+ [[reference]]
445
+ Reference Manual
446
+ ================
447
+ :css-signature: refguide
448
+
449
+ preamble
450
+ EOS
451
+ doc = document_from_string input
452
+ assert_equal 'reference', doc.id
453
+ assert_equal 'refguide', doc.attr('css-signature')
454
+ output = doc.render
455
+ assert_xpath '//body[@id="reference"]', output, 1
456
+ end
457
+
424
458
  test "trailing block attributes tranfer to the following section" do
425
459
  input = <<-EOS
426
460
  [[one]]
data/test/blocks_test.rb CHANGED
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
  require 'pathname'
3
3
 
4
4
  context "Blocks" do
5
- context "Rulers" do
5
+ context 'Line Breaks' do
6
6
  test "ruler" do
7
7
  output = render_string("'''")
8
8
  assert_xpath '//*[@id="content"]/hr', output, 1
@@ -15,6 +15,13 @@ context "Blocks" do
15
15
  assert_xpath '//*[@id="content"]/hr/preceding-sibling::*', output, 1
16
16
  assert_xpath '//*[@id="content"]/hr/following-sibling::*', output, 1
17
17
  end
18
+
19
+ test "page break" do
20
+ output = render_embedded_string("page 1\n\n<<<\n\npage 2")
21
+ assert_xpath '/*[@style="page-break-after: always"]', output, 1
22
+ assert_xpath '/*[@style="page-break-after: always"]/preceding-sibling::div/p[text()="page 1"]', output, 1
23
+ assert_xpath '/*[@style="page-break-after: always"]/following-sibling::div/p[text()="page 2"]', output, 1
24
+ end
18
25
  end
19
26
 
20
27
  context 'Comments' do
@@ -99,6 +106,15 @@ block comment
99
106
  assert_equal 1, d.blocks.size
100
107
  assert_xpath '//p', d.render, 1
101
108
  end
109
+
110
+ test 'line starting with three slashes should not be line comment' do
111
+ input = <<-EOS
112
+ /// not a line comment
113
+ EOS
114
+
115
+ output = render_embedded_string input
116
+ assert !output.strip.empty?, "Line should be emitted => #{input.rstrip}"
117
+ end
102
118
  end
103
119
 
104
120
  context "Example Blocks" do
@@ -181,6 +197,72 @@ You just write.
181
197
  assert_xpath '(//*[@class="exampleblock"])[1]/*[@class="title"][text()="Look! Writing Docs with AsciiDoc"]', output, 1
182
198
  assert !doc.attributes.has_key?('example-number')
183
199
  end
200
+
201
+ test 'automatic caption can be turned off and on and modified' do
202
+ input = <<-EOS
203
+ .first example
204
+ ====
205
+ an example
206
+ ====
207
+
208
+ :caption:
209
+
210
+ .second example
211
+ ====
212
+ another example
213
+ ====
214
+
215
+ :caption!:
216
+ :example-caption: Exhibit
217
+
218
+ .third example
219
+ ====
220
+ yet another example
221
+ ====
222
+ EOS
223
+
224
+ output = render_embedded_string input
225
+ assert_xpath '/*[@class="exampleblock"]', output, 3
226
+ assert_xpath '(/*[@class="exampleblock"])[1]/*[@class="title"][starts-with(text(), "Example ")]', output, 1
227
+ assert_xpath '(/*[@class="exampleblock"])[2]/*[@class="title"][text()="second example"]', output, 1
228
+ assert_xpath '(/*[@class="exampleblock"])[3]/*[@class="title"][starts-with(text(), "Exhibit ")]', output, 1
229
+ end
230
+ end
231
+
232
+ context 'Admonition Blocks' do
233
+ test 'caption block-level attribute should be used as caption' do
234
+ input = <<-EOS
235
+ :tip-caption: Pro Tip
236
+
237
+ [caption="Pro Tip"]
238
+ TIP: Override the caption of an admonition block using an attribute entry
239
+ EOS
240
+
241
+ output = render_embedded_string input
242
+ assert_xpath '/*[@class="admonitionblock"]//*[@class="icon"]/*[@class="title"][text()="Pro Tip"]', output, 1
243
+ end
244
+
245
+ test 'can override caption of admonition block using document attribute' do
246
+ input = <<-EOS
247
+ :tip-caption: Pro Tip
248
+
249
+ TIP: Override the caption of an admonition block using an attribute entry
250
+ EOS
251
+
252
+ output = render_embedded_string input
253
+ assert_xpath '/*[@class="admonitionblock"]//*[@class="icon"]/*[@class="title"][text()="Pro Tip"]', output, 1
254
+ end
255
+
256
+ test 'blank caption document attribute should not blank admonition block caption' do
257
+ input = <<-EOS
258
+ :caption:
259
+
260
+ TIP: Override the caption of an admonition block using an attribute entry
261
+ EOS
262
+
263
+ output = render_embedded_string input
264
+ assert_xpath '/*[@class="admonitionblock"]//*[@class="icon"]/*[@class="title"][text()="Tip"]', output, 1
265
+ end
184
266
  end
185
267
 
186
268
  context "Preformatted Blocks" do
@@ -394,6 +476,30 @@ paragraph
394
476
  assert_xpath '//*[@class="paragraph"]/*[@class="title"][text() = "Title"]', output, 1
395
477
  assert_xpath '//*[@class="paragraph"]/p[text() = "paragraph"]', output, 1
396
478
  end
479
+
480
+ test 'block title above document title gets carried over to preamble' do
481
+ input = <<-EOS
482
+ .Block title
483
+ = Document Title
484
+
485
+ preamble
486
+ EOS
487
+ output = render_string input
488
+ assert_xpath '//*[@id="preamble"]//*[@class="paragraph"]/*[@class="title"][text()="Block title"]', output, 1
489
+ end
490
+
491
+ test 'block title above document title gets carried over to first block in first section if no preamble' do
492
+ input = <<-EOS
493
+ .Block title
494
+ = Document Title
495
+
496
+ == First Section
497
+
498
+ paragraph
499
+ EOS
500
+ output = render_string input
501
+ assert_xpath '//*[@class="sect1"]//*[@class="paragraph"]/*[@class="title"][text() = "Block title"]', output, 1
502
+ end
397
503
  end
398
504
 
399
505
  context "Images" do
@@ -446,6 +552,17 @@ image::images/tiger.png[Tiger]
446
552
  assert_equal 1, doc.attributes['figure-number']
447
553
  end
448
554
 
555
+ test 'should pass through image that is a uri reference' do
556
+ input = <<-EOS
557
+ :imagesdir: images
558
+
559
+ image::http://asciidoc.org/images/tiger.png[Tiger]
560
+ EOS
561
+
562
+ output = render_string input
563
+ assert_xpath '//*[@class="imageblock"]//img[@src="http://asciidoc.org/images/tiger.png"][@alt="Tiger"]', output, 1
564
+ end
565
+
449
566
  test 'can resolve image relative to imagesdir' do
450
567
  input = <<-EOS
451
568
  :imagesdir: images
@@ -593,6 +710,49 @@ image::asciidoctor.png[Asciidoctor]
593
710
  end
594
711
 
595
712
  context 'Source code' do
713
+ test 'should support fenced code block using backticks' do
714
+ input = <<-EOS
715
+ ```
716
+ puts "Hello, World!"
717
+ ```
718
+ EOS
719
+
720
+ output = render_embedded_string input
721
+ assert_css '.listingblock', output, 1
722
+ assert_css '.listingblock pre code', output, 1
723
+ assert_css '.listingblock pre code:not([class])', output, 1
724
+ end
725
+
726
+ test 'should support fenced code block using tildes' do
727
+ input = <<-EOS
728
+ ~~~
729
+ puts "Hello, World!"
730
+ ~~~
731
+ EOS
732
+
733
+ output = render_embedded_string input
734
+ assert_css '.listingblock', output, 1
735
+ assert_css '.listingblock pre code', output, 1
736
+ assert_css '.listingblock pre code:not([class])', output, 1
737
+ end
738
+
739
+ test 'should support fenced code blocks with languages' do
740
+ input = <<-EOS
741
+ ```ruby
742
+ puts "Hello, World!"
743
+ ```
744
+
745
+ ~~~ javascript
746
+ alert("Hello, World!")
747
+ ~~~
748
+ EOS
749
+
750
+ output = render_embedded_string input
751
+ assert_css '.listingblock', output, 2
752
+ assert_css '.listingblock pre code.ruby', output, 1
753
+ assert_css '.listingblock pre code.javascript', output, 1
754
+ end
755
+
596
756
  test 'should highlight source if source-highlighter attribute is coderay' do
597
757
  input = <<-EOS
598
758
  :source-highlighter: coderay
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  context 'Document' do
4
4
 
5
5
  context 'Example document' do
6
- test 'test_title' do
6
+ test 'document title' do
7
7
  doc = example_document(:asciidoc_index)
8
8
  assert_equal 'AsciiDoc Home Page', doc.doctitle
9
9
  assert_equal 'AsciiDoc Home Page', doc.name
@@ -219,7 +219,7 @@ preamble
219
219
  assert !renderer.nil?
220
220
  views = renderer.views
221
221
  assert !views.nil?
222
- assert_equal 29, views.size
222
+ assert_equal 30, views.size
223
223
  assert views.has_key? 'document'
224
224
  assert views['document'].is_a?(Asciidoctor::HTML5::DocumentTemplate)
225
225
  assert_equal 'ERB', views['document'].eruby.to_s
@@ -235,7 +235,7 @@ preamble
235
235
  assert !renderer.nil?
236
236
  views = renderer.views
237
237
  assert !views.nil?
238
- assert_equal 29, views.size
238
+ assert_equal 30, views.size
239
239
  assert views.has_key? 'document'
240
240
  assert views['document'].is_a?(Asciidoctor::DocBook45::DocumentTemplate)
241
241
  assert_equal 'ERB', views['document'].eruby.to_s
@@ -255,7 +255,7 @@ preamble
255
255
  end
256
256
 
257
257
  context 'Structure' do
258
- test 'test_with_no_title' do
258
+ test 'document with no doctitle' do
259
259
  doc = document_from_string('Snorf')
260
260
  assert_nil doc.doctitle
261
261
  assert_nil doc.name
@@ -263,7 +263,22 @@ preamble
263
263
  assert_nil doc.header
264
264
  end
265
265
 
266
- test 'test_with_explicit_title' do
266
+ test 'document with doctitle defined as attribute entry' do
267
+ input = <<-EOS
268
+ :doctitle: Document Title
269
+
270
+ preamble
271
+
272
+ == First Section
273
+ EOS
274
+ doc = document_from_string input
275
+ assert_equal 'Document Title', doc.doctitle
276
+ assert doc.has_header?
277
+ assert_equal 'Document Title', doc.header.title
278
+ assert_equal 'Document Title', doc.first_section.title
279
+ end
280
+
281
+ test 'document with title attribute entry overrides doctitle' do
267
282
  input = <<-EOS
268
283
  = Title
269
284
  :title: Document Title
@@ -280,6 +295,23 @@ preamble
280
295
  assert_equal 'Title', doc.first_section.title
281
296
  end
282
297
 
298
+ test 'document with doctitle attribute entry overrides header title and doctitle' do
299
+ input = <<-EOS
300
+ = Title
301
+ :doctitle: Override
302
+
303
+ preamble
304
+
305
+ == First Section
306
+ EOS
307
+ doc = document_from_string input
308
+ assert_equal 'Override', doc.doctitle
309
+ assert_nil doc.title
310
+ assert doc.has_header?
311
+ assert_equal 'Override', doc.header.title
312
+ assert_equal 'Override', doc.first_section.title
313
+ end
314
+
283
315
  test 'should recognize document title when preceded by blank lines' do
284
316
  input = <<-EOS
285
317
  :doctype: book
@@ -297,15 +329,23 @@ text
297
329
  assert_css '#content h1', output, 0
298
330
  end
299
331
 
300
- test 'test_empty_document' do
301
- doc = document_from_string('')
332
+ test 'should not choke on empty source' do
333
+ doc = Asciidoctor::Document.new ''
334
+ assert doc.blocks.empty?
335
+ assert_nil doc.doctitle
336
+ assert !doc.has_header?
337
+ assert_nil doc.header
338
+ end
339
+
340
+ test 'should not choke on nil source' do
341
+ doc = Asciidoctor::Document.new nil
302
342
  assert doc.blocks.empty?
303
343
  assert_nil doc.doctitle
304
344
  assert !doc.has_header?
305
345
  assert_nil doc.header
306
346
  end
307
347
 
308
- test 'test_with_metadata' do
348
+ test 'with metadata' do
309
349
  input = <<-EOS
310
350
  = AsciiDoc
311
351
  Stuart Rackham <founder@asciidoc.org>
@@ -323,20 +363,50 @@ more info...
323
363
  assert_xpath '//*[@id="header"]/span[@id="revremark"][text() = "See changelog."]', output, 1
324
364
  end
325
365
 
326
- test 'test_with_header_footer' do
366
+ test 'with header footer' do
327
367
  result = render_string("= Title\n\npreamble")
328
368
  assert_xpath '/html', result, 1
329
369
  assert_xpath '//*[@id="header"]', result, 1
370
+ assert_xpath '//*[@id="header"]/h1', result, 1
330
371
  assert_xpath '//*[@id="footer"]', result, 1
331
372
  assert_xpath '//*[@id="preamble"]', result, 1
332
373
  end
333
374
 
334
- test 'test_with_no_header_footer' do
375
+ test 'no header footer' do
335
376
  result = render_string("= Title\n\npreamble", :header_footer => false)
336
377
  assert_xpath '/html', result, 0
378
+ assert_xpath '/h1', result, 0
379
+ assert_xpath '/*[@id="header"]', result, 0
380
+ assert_xpath '/*[@id="footer"]', result, 0
381
+ assert_xpath '/*[@id="preamble"]', result, 1
382
+ end
383
+
384
+ test 'wip enable title when no header footer' do
385
+ result = render_string("= Title\n\npreamble", :header_footer => false, :attributes => {'notitle!' => ''})
386
+ assert_xpath '/html', result, 0
387
+ assert_xpath '/h1', result, 1
337
388
  assert_xpath '/*[@id="header"]', result, 0
338
389
  assert_xpath '/*[@id="footer"]', result, 0
339
390
  assert_xpath '/*[@id="preamble"]', result, 1
391
+ assert_xpath '(/*)[1]/self::h1', result, 1
392
+ assert_xpath '(/*)[2]/self::*[@id="preamble"]', result, 1
393
+ end
394
+
395
+ test 'parse header only' do
396
+ input = <<-EOS
397
+ = Document Title
398
+ Author Name
399
+ :foo: bar
400
+
401
+ preamble
402
+ EOS
403
+
404
+ doc = document_from_string input, :parse_header_only => true
405
+ assert_equal 'Document Title', doc.doctitle
406
+ assert_equal 'Author Name', doc.author
407
+ assert_equal 'bar', doc.attributes['foo']
408
+ # there would be at least 1 block had it parsed beyond the header
409
+ assert_equal 0, doc.blocks.size
340
410
  end
341
411
 
342
412
  test 'renders footnotes in footer' do
@@ -361,7 +431,7 @@ finally a reference to the second footnote footnoteref:[note2].
361
431
  end
362
432
 
363
433
  context 'Backends and Doctypes' do
364
- test 'test_html5_backend_doctype_article' do
434
+ test 'html5 backend doctype article' do
365
435
  result = render_string("= Title\n\npreamble", :attributes => {'backend' => 'html5'})
366
436
  assert_xpath '/html', result, 1
367
437
  assert_xpath '/html/body[@class="article"]', result, 1
@@ -369,7 +439,7 @@ finally a reference to the second footnote footnoteref:[note2].
369
439
  assert_xpath '/html//*[@id="preamble"]//p[text() = "preamble"]', result, 1
370
440
  end
371
441
 
372
- test 'test_html5_backend_doctype_book' do
442
+ test 'html5 backend doctype book' do
373
443
  result = render_string("= Title\n\npreamble", :attributes => {'backend' => 'html5', 'doctype' => 'book'})
374
444
  assert_xpath '/html', result, 1
375
445
  assert_xpath '/html/body[@class="book"]', result, 1
@@ -377,7 +447,7 @@ finally a reference to the second footnote footnoteref:[note2].
377
447
  assert_xpath '/html//*[@id="preamble"]//p[text() = "preamble"]', result, 1
378
448
  end
379
449
 
380
- test 'test_docbook45_backend_doctype_article' do
450
+ test 'docbook45 backend doctype article' do
381
451
  input = <<-EOS
382
452
  = Title
383
453
 
@@ -396,14 +466,14 @@ section body
396
466
  assert_xpath '/article/section[@id = "_first_section"]/simpara[text() = "section body"]', result, 1
397
467
  end
398
468
 
399
- test 'test_docbook45_backend_doctype_article_no_title' do
469
+ test 'docbook45 backend doctype article no title' do
400
470
  result = render_string('text', :attributes => {'backend' => 'docbook45'})
401
471
  assert_xpath '/article', result, 1
402
472
  assert_xpath '/article/articleinfo/date', result, 1
403
473
  assert_xpath '/article/simpara[text() = "text"]', result, 1
404
474
  end
405
475
 
406
- test 'test_docbook45_backend_doctype_book' do
476
+ test 'docbook45 backend doctype book' do
407
477
  input = <<-EOS
408
478
  = Title
409
479
 
@@ -422,13 +492,33 @@ chapter body
422
492
  assert_xpath '/book/chapter[@id = "_first_chapter"]/simpara[text() = "chapter body"]', result, 1
423
493
  end
424
494
 
425
- test 'test_docbook45_backend_doctype_book_no_title' do
495
+ test 'docbook45 backend doctype book no title' do
426
496
  result = render_string('text', :attributes => {'backend' => 'docbook45', 'doctype' => 'book'})
427
497
  assert_xpath '/book', result, 1
428
498
  assert_xpath '/book/bookinfo/date', result, 1
429
499
  assert_xpath '/book/simpara[text() = "text"]', result, 1
430
500
  end
431
501
 
502
+ test 'should be able to set backend using :backend option key' do
503
+ doc = Asciidoctor::Document.new([], :backend => 'html5')
504
+ assert_equal 'html5', doc.attributes['backend']
505
+ end
506
+
507
+ test ':backend option should override backend attribute' do
508
+ doc = Asciidoctor::Document.new([], :backend => 'html5', :attributes => {'backend' => 'docbook45'})
509
+ assert_equal 'html5', doc.attributes['backend']
510
+ end
511
+
512
+ test 'should be able to set doctype using :doctype option key' do
513
+ doc = Asciidoctor::Document.new([], :doctype => 'book')
514
+ assert_equal 'book', doc.attributes['doctype']
515
+ end
516
+
517
+ test ':doctype option should override doctype attribute' do
518
+ doc = Asciidoctor::Document.new([], :doctype => 'book', :attributes => {'doctype' => 'article'})
519
+ assert_equal 'book', doc.attributes['doctype']
520
+ end
521
+
432
522
  test 'do not override explicit author initials' do
433
523
  input = <<-EOS
434
524
  = AsciiDoc
@@ -440,5 +530,33 @@ more info...
440
530
  output = render_string input, :attributes => {'backend' => 'docbook45'}
441
531
  assert_xpath '/article/articleinfo/authorinitials[text()="SJR"]', output, 1
442
532
  end
533
+
534
+ test 'attribute entry can appear immediately after document title' do
535
+ input = <<-EOS
536
+ Reference Guide
537
+ ===============
538
+ :toc:
539
+
540
+ preamble
541
+ EOS
542
+ doc = document_from_string input
543
+ assert doc.attr?('toc')
544
+ assert_equal '', doc.attr('toc')
545
+ end
546
+
547
+ test 'attribute entry can appear before author line under document title' do
548
+ input = <<-EOS
549
+ Reference Guide
550
+ ===============
551
+ :toc:
552
+ Dan Allen
553
+
554
+ preamble
555
+ EOS
556
+ doc = document_from_string input
557
+ assert doc.attr?('toc')
558
+ assert_equal '', doc.attr('toc')
559
+ assert_equal 'Dan Allen', doc.attr('author')
560
+ end
443
561
  end
444
562
  end