asciidoctor 1.5.1 → 1.5.2

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 (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +85 -0
  3. data/README.adoc +79 -6
  4. data/Rakefile +22 -1
  5. data/benchmark/benchmark.rb +3 -1
  6. data/compat/asciidoc.conf +2 -2
  7. data/data/stylesheets/asciidoctor-default.css +3 -3
  8. data/features/step_definitions.rb +12 -1
  9. data/lib/asciidoctor.rb +74 -42
  10. data/lib/asciidoctor/abstract_block.rb +5 -1
  11. data/lib/asciidoctor/abstract_node.rb +40 -23
  12. data/lib/asciidoctor/attribute_list.rb +14 -5
  13. data/lib/asciidoctor/block.rb +45 -12
  14. data/lib/asciidoctor/callouts.rb +1 -0
  15. data/lib/asciidoctor/cli/invoker.rb +6 -2
  16. data/lib/asciidoctor/cli/options.rb +23 -9
  17. data/lib/asciidoctor/converter.rb +9 -19
  18. data/lib/asciidoctor/converter/base.rb +11 -14
  19. data/lib/asciidoctor/converter/composite.rb +8 -19
  20. data/lib/asciidoctor/converter/docbook45.rb +1 -0
  21. data/lib/asciidoctor/converter/docbook5.rb +24 -2
  22. data/lib/asciidoctor/converter/factory.rb +1 -0
  23. data/lib/asciidoctor/converter/html5.rb +61 -25
  24. data/lib/asciidoctor/converter/template.rb +19 -26
  25. data/lib/asciidoctor/document.rb +73 -45
  26. data/lib/asciidoctor/extensions.rb +121 -9
  27. data/lib/asciidoctor/helpers.rb +1 -0
  28. data/lib/asciidoctor/inline.rb +1 -0
  29. data/lib/asciidoctor/list.rb +1 -0
  30. data/lib/asciidoctor/opal_ext.rb +22 -0
  31. data/lib/asciidoctor/opal_ext/file.rb +26 -13
  32. data/lib/asciidoctor/parser.rb +15 -18
  33. data/lib/asciidoctor/path_resolver.rb +18 -0
  34. data/lib/asciidoctor/reader.rb +8 -9
  35. data/lib/asciidoctor/section.rb +5 -8
  36. data/lib/asciidoctor/stylesheets.rb +1 -0
  37. data/lib/asciidoctor/substitutors.rb +18 -18
  38. data/lib/asciidoctor/table.rb +2 -1
  39. data/lib/asciidoctor/timings.rb +1 -0
  40. data/lib/asciidoctor/version.rb +1 -1
  41. data/man/asciidoctor.1 +10 -11
  42. data/man/asciidoctor.adoc +80 -99
  43. data/test/attributes_test.rb +42 -0
  44. data/test/blocks_test.rb +19 -7
  45. data/test/document_test.rb +114 -0
  46. data/test/extensions_test.rb +100 -0
  47. data/test/fixtures/custom-docinfodir/basic-docinfo.html +1 -0
  48. data/test/fixtures/custom-docinfodir/docinfo.html +1 -0
  49. data/test/fixtures/hello-asciidoctor.pdf +0 -0
  50. data/test/invoker_test.rb +4 -3
  51. data/test/lists_test.rb +31 -5
  52. data/test/options_test.rb +1 -1
  53. data/test/paths_test.rb +21 -0
  54. data/test/preamble_test.rb +33 -0
  55. data/test/reader_test.rb +13 -0
  56. data/test/sections_test.rb +22 -0
  57. data/test/substitutions_test.rb +49 -0
  58. data/test/tables_test.rb +76 -0
  59. data/test/test_helper.rb +4 -2
  60. metadata +7 -5
  61. data/lib/asciidoctor/debug.rb +0 -25
data/test/lists_test.rb CHANGED
@@ -3990,30 +3990,56 @@ foo::
3990
3990
  assert_xpath '//ol/li/p[text()="Not pointing to a callout"]', output, 1
3991
3991
  end
3992
3992
 
3993
- test 'should remove leading line comment chars' do
3993
+ test 'should remove line comment chars that precedes callout number' do
3994
3994
  input = <<-EOS
3995
+ [source,ruby]
3995
3996
  ----
3996
3997
  puts 'Hello, world!' # <1>
3997
3998
  ----
3998
3999
  <1> Ruby
3999
4000
 
4001
+ [source,groovy]
4000
4002
  ----
4001
4003
  println 'Hello, world!' // <1>
4002
4004
  ----
4003
4005
  <1> Groovy
4004
4006
 
4007
+ [source,clojure]
4005
4008
  ----
4006
4009
  (def hello (fn [] "Hello, world!")) ;; <1>
4007
4010
  (hello)
4008
4011
  ----
4009
4012
  <1> Clojure
4013
+
4014
+ [source,haskell]
4015
+ ----
4016
+ main = putStrLn "Hello, World!" -- <1>
4017
+ ----
4018
+ <1> Haskell
4019
+ EOS
4020
+ [{}, {'source-highlighter' => 'coderay'}].each do |attributes|
4021
+ output = render_embedded_string input, :attributes => attributes
4022
+ assert_xpath '//b', output, 4
4023
+ nodes = xmlnodes_at_css 'pre', output
4024
+ assert_equal %(puts 'Hello, world!' (1)), nodes[0].text
4025
+ assert_equal %(println 'Hello, world!' (1)), nodes[1].text
4026
+ assert_equal %((def hello (fn [] "Hello, world!")) (1)\n(hello)), nodes[2].text
4027
+ assert_equal %(main = putStrLn "Hello, World!" (1)), nodes[3].text
4028
+ end
4029
+ end
4030
+
4031
+ test 'should allow line comment chars that precede callout number to be specified' do
4032
+ input = <<-EOS
4033
+ [source,erlang,line-comment=%]
4034
+ ----
4035
+ hello_world() -> io:fwrite("hello, world\n"). % <1>
4036
+ ----
4037
+ <1> Erlang
4010
4038
  EOS
4011
4039
  output = render_embedded_string input
4012
- assert_xpath '//b', output, 3
4040
+ assert_xpath '//b', output, 1
4013
4041
  nodes = xmlnodes_at_css 'pre', output
4014
- assert_equal "puts 'Hello, world!' (1)", nodes[0].text
4015
- assert_equal "println 'Hello, world!' (1)", nodes[1].text
4016
- assert_equal %((def hello (fn [] "Hello, world!")) (1)\n(hello)), nodes[2].text
4042
+ assert_equal %(hello_world() -> io:fwrite("hello, world\n"). (1)), nodes[0].text
4017
4043
  end
4018
4044
 
4019
4045
  test 'literal block with callouts' do
data/test/options_test.rb CHANGED
@@ -77,7 +77,7 @@ context 'Options' do
77
77
  end
78
78
 
79
79
  test 'should allow safe mode to be specified' do
80
- options = Asciidoctor::Cli::Options.parse!(%w(-S safe /dev/null))
80
+ options = Asciidoctor::Cli::Options.parse!(%w(-S safe test/fixtures/sample.asciidoc))
81
81
  assert_equal Asciidoctor::SafeMode::SAFE, options[:safe]
82
82
  end
83
83
 
data/test/paths_test.rb CHANGED
@@ -56,6 +56,16 @@ context 'Path Resolver' do
56
56
  assert_equal 'http://www.example.com/assets/images', @resolver.web_path('images', 'http://www.example.com/assets')
57
57
  end
58
58
 
59
+ # enable if we want to allow web_path to detect and preserve a target URI
60
+ #test 'target with file url appended to relative path' do
61
+ # assert_equal 'file:///home/username/styles/asciidoctor.css', @resolver.web_path('file:///home/username/styles/asciidoctor.css', '.')
62
+ #end
63
+
64
+ # enable if we want to allow web_path to detect and preserve a target URI
65
+ #test 'target with http url appended to relative path' do
66
+ # assert_equal 'http://example.com/asciidoctor.css', @resolver.web_path('http://example.com/asciidoctor.css', '.')
67
+ #end
68
+
59
69
  test 'normalize target' do
60
70
  assert_equal '../images', @resolver.web_path('../images/../images')
61
71
  end
@@ -227,5 +237,16 @@ context 'Path Resolver' do
227
237
  assert_equal 'master', Asciidoctor::Helpers.rootname('master')
228
238
  assert_equal 'docs/master', Asciidoctor::Helpers.rootname('docs/master')
229
239
  end
240
+
241
+ test 'UriSniffRx should detect URIs' do
242
+ assert Asciidoctor::UriSniffRx =~ 'http://example.com'
243
+ assert Asciidoctor::UriSniffRx =~ 'https://example.com'
244
+ assert Asciidoctor::UriSniffRx =~ 'data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs='
245
+ end
246
+
247
+ test 'UriSniffRx should not detect an absolute Windows path as a URI' do
248
+ assert Asciidoctor::UriSniffRx !~ 'c:/sample.adoc'
249
+ assert Asciidoctor::UriSniffRx !~ 'c:\\sample.adoc'
250
+ end
230
251
  end
231
252
  end
@@ -24,6 +24,39 @@ Section paragraph 1.
24
24
  assert_xpath '//*[@id="preamble"]/following-sibling::*//p', result, 1
25
25
  end
26
26
 
27
+ test 'title of preface is blank by default in DocBook output' do
28
+ input = <<-EOS
29
+ = Document Title
30
+ :doctype: book
31
+
32
+ Preface content.
33
+
34
+ == First Section
35
+
36
+ Section content.
37
+ EOS
38
+ result = render_string input, :backend => :docbook
39
+ assert_xpath '//preface/title', result, 1
40
+ title_node = xmlnodes_at_xpath '//preface/title', result, 1
41
+ assert_equal '', title_node.text
42
+ end
43
+
44
+ test 'preface-title attribute is assigned as title of preface in DocBook output' do
45
+ input = <<-EOS
46
+ = Document Title
47
+ :doctype: book
48
+ :preface-title: Preface
49
+
50
+ Preface content.
51
+
52
+ == First Section
53
+
54
+ Section content.
55
+ EOS
56
+ result = render_string input, :backend => :docbook
57
+ assert_xpath '//preface/title[text()="Preface"]', result, 1
58
+ end
59
+
27
60
  test 'title and multi-paragraph preamble before section' do
28
61
  input = <<-EOS
29
62
  = Title
data/test/reader_test.rb CHANGED
@@ -613,6 +613,19 @@ include::fixtures/no-such-file.adoc[]
613
613
  flunk 'include directive should not raise exception on missing file'
614
614
  end
615
615
  end
616
+
617
+ # IMPORTANT this test needs to be run on Windows to verify proper behavior in Windows
618
+ test 'can resolve include directive with absolute path' do
619
+ include_path = ::File.join DIRNAME, 'fixtures', 'chapter-a.adoc'
620
+ input = <<-EOS
621
+ include::#{include_path}[]
622
+ EOS
623
+ result = document_from_string input, :safe => :safe
624
+ assert_equal 'Chapter A', result.doctitle
625
+
626
+ result = document_from_string input, :safe => :unsafe, :base_dir => ::Dir.tmpdir
627
+ assert_equal 'Chapter A', result.doctitle
628
+ end
616
629
 
617
630
  test 'include directive can retrieve data from uri' do
618
631
  #url = 'http://echo.jsontest.com/name/asciidoctor'
@@ -114,6 +114,28 @@ text
114
114
  assert_equal '_some_section_2', doc.blocks[1].id
115
115
  end
116
116
 
117
+ # NOTE test cannot be run in parallel with other tests
118
+ test 'can set start index of synthetic ids' do
119
+ old_unique_id_start_index = Asciidoctor::Compliance.unique_id_start_index
120
+ begin
121
+ input = <<-EOS
122
+ == Some section
123
+
124
+ text
125
+
126
+ == Some section
127
+
128
+ text
129
+ EOS
130
+ Asciidoctor::Compliance.unique_id_start_index = 1
131
+ doc = document_from_string input
132
+ assert_equal '_some_section', doc.blocks[0].id
133
+ assert_equal '_some_section_1', doc.blocks[1].id
134
+ ensure
135
+ Asciidoctor::Compliance.unique_id_start_index = old_unique_id_start_index
136
+ end
137
+ end
138
+
117
139
  test 'should use specified id and reftext when registering section reference' do
118
140
  input = <<-EOS
119
141
  [[install,Install Procedure]]
@@ -1558,6 +1558,55 @@ foo&#8201;&#8212;&#8201;'
1558
1558
  block.lock_in_subs
1559
1559
  assert_equal [:specialcharacters], block.subs
1560
1560
  end
1561
+
1562
+ test 'should not use subs if subs option passed to block constructor is nil' do
1563
+ doc = empty_document
1564
+ block = Asciidoctor::Block.new doc, :paragraph, :source => '*bold* _italic_', :subs => nil, :attributes => {'subs' => 'quotes'}
1565
+ assert block.subs.empty?
1566
+ block.lock_in_subs
1567
+ assert block.subs.empty?
1568
+ end
1569
+
1570
+ test 'should not use subs if subs option passed to block constructor is empty array' do
1571
+ doc = empty_document
1572
+ block = Asciidoctor::Block.new doc, :paragraph, :source => '*bold* _italic_', :subs => [], :attributes => {'subs' => 'quotes'}
1573
+ assert block.subs.empty?
1574
+ block.lock_in_subs
1575
+ assert block.subs.empty?
1576
+ end
1577
+
1578
+ test 'should use subs from subs option passed to block constructor' do
1579
+ doc = empty_document
1580
+ block = Asciidoctor::Block.new doc, :paragraph, :source => '*bold* _italic_', :subs => [:specialcharacters], :attributes => {'subs' => 'quotes'}
1581
+ assert_equal [:specialcharacters], block.subs
1582
+ block.lock_in_subs
1583
+ assert_equal [:specialcharacters], block.subs
1584
+ end
1585
+
1586
+ test 'should use subs from subs attribute if subs option is not passed to block constructor' do
1587
+ doc = empty_document
1588
+ block = Asciidoctor::Block.new doc, :paragraph, :source => '*bold* _italic_', :attributes => {'subs' => 'quotes'}
1589
+ assert block.subs.empty?
1590
+ # in this case, we have to call lock_in_subs to resolve the subs
1591
+ block.lock_in_subs
1592
+ assert_equal [:quotes], block.subs
1593
+ end
1594
+
1595
+ test 'should use subs from subs attribute if subs option passed to block constructor is :default' do
1596
+ doc = empty_document
1597
+ block = Asciidoctor::Block.new doc, :paragraph, :source => '*bold* _italic_', :subs => :default, :attributes => {'subs' => 'quotes'}
1598
+ assert_equal [:quotes], block.subs
1599
+ block.lock_in_subs
1600
+ assert_equal [:quotes], block.subs
1601
+ end
1602
+
1603
+ test 'should use built-in subs if subs option passed to block constructor is :default and subs attribute is absent' do
1604
+ doc = empty_document
1605
+ block = Asciidoctor::Block.new doc, :paragraph, :source => '*bold* _italic_', :subs => :default
1606
+ assert_equal [:specialcharacters, :quotes, :attributes, :replacements, :macros, :post_replacements], block.subs
1607
+ block.lock_in_subs
1608
+ assert_equal [:specialcharacters, :quotes, :attributes, :replacements, :macros, :post_replacements], block.subs
1609
+ end
1561
1610
  end
1562
1611
 
1563
1612
  # TODO move to helpers_test.rb
data/test/tables_test.rb CHANGED
@@ -102,6 +102,24 @@ context 'Tables' do
102
102
  assert_xpath '/table/tbody/tr/td[2]/p[text()="a | there"]', output, 1
103
103
  end
104
104
 
105
+ test 'should treat trailing pipe as an empty cell' do
106
+ input = <<-EOS
107
+ |====
108
+ |A1 |
109
+ |B1 |B2
110
+ |C1 |C2
111
+ |====
112
+ EOS
113
+ output = render_embedded_string input
114
+ assert_css 'table', output, 1
115
+ assert_css 'table > colgroup > col', output, 2
116
+ assert_css 'table > tbody > tr', output, 3
117
+ assert_xpath '/table/tbody/tr[1]/td', output, 2
118
+ assert_xpath '/table/tbody/tr[1]/td[1]/p[text()="A1"]', output, 1
119
+ assert_xpath '/table/tbody/tr[1]/td[2]/p', output, 0
120
+ assert_xpath '/table/tbody/tr[2]/td[1]/p[text()="B1"]', output, 1
121
+ end
122
+
105
123
  test 'should auto recover with warning if missing leading separator on first cell' do
106
124
  input = <<-EOS
107
125
  |===
@@ -808,10 +826,57 @@ a:b:c
808
826
  assert_css 'table > tbody > tr:nth-child(1) > td', output, 3
809
827
  assert_css 'table > tbody > tr:nth-child(2) > td', output, 3
810
828
  end
829
+
830
+ test 'single cell in DSV table should only produce single row' do
831
+ input = <<-EOS
832
+ :===
833
+ single cell
834
+ :===
835
+ EOS
836
+
837
+ output = render_embedded_string input
838
+ assert_css 'table td', output, 1
839
+ end
840
+
841
+ test 'should treat trailing colon as an empty cell' do
842
+ input = <<-EOS
843
+ :====
844
+ A1:
845
+ B1:B2
846
+ C1:C2
847
+ :====
848
+ EOS
849
+ output = render_embedded_string input
850
+ assert_css 'table', output, 1
851
+ assert_css 'table > colgroup > col', output, 2
852
+ assert_css 'table > tbody > tr', output, 3
853
+ assert_xpath '/table/tbody/tr[1]/td', output, 2
854
+ assert_xpath '/table/tbody/tr[1]/td[1]/p[text()="A1"]', output, 1
855
+ assert_xpath '/table/tbody/tr[1]/td[2]/p', output, 0
856
+ assert_xpath '/table/tbody/tr[2]/td[1]/p[text()="B1"]', output, 1
857
+ end
811
858
  end
812
859
 
813
860
  context 'CSV' do
814
861
 
862
+ test 'should treat trailing comma as an empty cell' do
863
+ input = <<-EOS
864
+ ,====
865
+ A1,
866
+ B1,B2
867
+ C1,C2
868
+ ,====
869
+ EOS
870
+ output = render_embedded_string input
871
+ assert_css 'table', output, 1
872
+ assert_css 'table > colgroup > col', output, 2
873
+ assert_css 'table > tbody > tr', output, 3
874
+ assert_xpath '/table/tbody/tr[1]/td', output, 2
875
+ assert_xpath '/table/tbody/tr[1]/td[1]/p[text()="A1"]', output, 1
876
+ assert_xpath '/table/tbody/tr[1]/td[2]/p', output, 0
877
+ assert_xpath '/table/tbody/tr[2]/td[1]/p[text()="B1"]', output, 1
878
+ end
879
+
815
880
  test 'mixed unquoted records and quoted records with escaped quotes, commas and wrapped lines' do
816
881
  input = <<-EOS
817
882
  [format="csv",options="header"]
@@ -884,5 +949,16 @@ asciidoctor -o - -s test.adoc | view -
884
949
  assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(1) p', output, 1
885
950
  assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(2) .listingblock', output, 1
886
951
  end
952
+
953
+ test 'single cell in CSV table should only produce single row' do
954
+ input = <<-EOS
955
+ ,===
956
+ single cell
957
+ ,===
958
+ EOS
959
+
960
+ output = render_embedded_string input
961
+ assert_css 'table td', output, 1
962
+ end
887
963
  end
888
964
  end
data/test/test_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  ASCIIDOCTOR_PROJECT_DIR = File.dirname File.dirname(__FILE__)
2
3
  Dir.chdir ASCIIDOCTOR_PROJECT_DIR
3
4
 
@@ -5,17 +6,18 @@ if RUBY_VERSION < '1.9'
5
6
  require 'rubygems'
6
7
  end
7
8
 
9
+ require 'simplecov' if ENV['COVERAGE'] == 'true'
10
+
8
11
  require File.join(ASCIIDOCTOR_PROJECT_DIR, 'lib', 'asciidoctor')
9
12
 
10
13
  require 'minitest/autorun'
11
14
  require 'socket'
12
15
  require 'nokogiri'
16
+ require 'tmpdir'
13
17
 
14
18
  autoload :FileUtils, 'fileutils'
15
19
  autoload :Pathname, 'pathname'
16
20
 
17
- ENV['SUPPRESS_DEBUG'] ||= 'true'
18
-
19
21
  RE_XMLNS_ATTRIBUTE = / xmlns="[^"]+"/
20
22
  RE_DOCTYPE = /\s*<!DOCTYPE (.*)/
21
23
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Allen
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2014-09-19 00:00:00.000000000 Z
16
+ date: 2014-11-27 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: coderay
@@ -133,14 +133,14 @@ dependencies:
133
133
  requirements:
134
134
  - - "~>"
135
135
  - !ruby/object:Gem::Version
136
- version: 0.1.3
136
+ version: 0.3.4
137
137
  type: :development
138
138
  prerelease: false
139
139
  version_requirements: !ruby/object:Gem::Requirement
140
140
  requirements:
141
141
  - - "~>"
142
142
  - !ruby/object:Gem::Version
143
- version: 0.1.3
143
+ version: 0.3.4
144
144
  - !ruby/object:Gem::Dependency
145
145
  name: tilt
146
146
  requirement: !ruby/object:Gem::Requirement
@@ -246,7 +246,6 @@ files:
246
246
  - lib/asciidoctor/core_ext/object/nil_or_empty.rb
247
247
  - lib/asciidoctor/core_ext/string/chr.rb
248
248
  - lib/asciidoctor/core_ext/symbol/length.rb
249
- - lib/asciidoctor/debug.rb
250
249
  - lib/asciidoctor/document.rb
251
250
  - lib/asciidoctor/extensions.rb
252
251
  - lib/asciidoctor/helpers.rb
@@ -289,6 +288,8 @@ files:
289
288
  - test/fixtures/custom-backends/slim/docbook45/block_paragraph.xml.slim
290
289
  - test/fixtures/custom-backends/slim/html5/block_paragraph.html.slim
291
290
  - test/fixtures/custom-backends/slim/html5/block_sidebar.html.slim
291
+ - test/fixtures/custom-docinfodir/basic-docinfo.html
292
+ - test/fixtures/custom-docinfodir/docinfo.html
292
293
  - test/fixtures/docinfo-footer.html
293
294
  - test/fixtures/docinfo-footer.xml
294
295
  - test/fixtures/docinfo.html
@@ -296,6 +297,7 @@ files:
296
297
  - test/fixtures/dot.gif
297
298
  - test/fixtures/encoding.asciidoc
298
299
  - test/fixtures/grandchild-include.adoc
300
+ - test/fixtures/hello-asciidoctor.pdf
299
301
  - test/fixtures/include-file.asciidoc
300
302
  - test/fixtures/include-file.xml
301
303
  - test/fixtures/master.adoc
@@ -1,25 +0,0 @@
1
- module Asciidoctor
2
- module Debug
3
- @show_debug = nil
4
-
5
- def self.debug
6
- warn yield if self.show_debug_output?
7
- end
8
-
9
- def self.set_debug(value)
10
- @show_debug = value
11
- end
12
-
13
- def self.show_debug_output?
14
- @show_debug || (ENV['DEBUG'] == 'true' && ENV['SUPPRESS_DEBUG'] != 'true')
15
- end
16
-
17
- def self.puts_indented(level, *args)
18
- indentation = " " * level * 2
19
-
20
- args.each do |arg|
21
- self.debug { "#{indentation}#{arg}" }
22
- end
23
- end
24
- end
25
- end