asciidoctor 1.5.6 → 1.5.6.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.

@@ -68,7 +68,7 @@ context 'Sections' do
68
68
 
69
69
  test 'synthetic ids can be disabled' do
70
70
  sec = block_from_string(":sectids!:\n\n== Section One\n")
71
- assert sec.id.nil?
71
+ assert_nil sec.id
72
72
  end
73
73
 
74
74
  test 'explicit id in anchor above section title overrides synthetic id' do
@@ -301,7 +301,7 @@ preamble
301
301
  assert_xpath '//h1', render_string(title + "\n" + chars), 0
302
302
  end
303
303
 
304
- test "document title with single-line syntax" do
304
+ test "document title with atx syntax" do
305
305
  assert_xpath "//h1[not(@id)][text() = 'My Title']", render_string("= My Title")
306
306
  end
307
307
 
@@ -373,7 +373,7 @@ preamble
373
373
  content
374
374
  EOS
375
375
  doc = document_from_string input
376
- assert doc.blocks[0].attributes.empty?
376
+ assert_empty doc.blocks[0].attributes
377
377
  output = doc.convert
378
378
  assert_css 'body#idname', output, 1
379
379
  assert_css '.rolename', output, 0
@@ -385,7 +385,7 @@ content
385
385
  assert_xpath "//h2[@id='_my_section'][text() = 'My Section']", render_string("My Section\n-----------")
386
386
  end
387
387
 
388
- test 'should not recognize underline containing a mix of characters' do
388
+ test 'should not recognize underline containing a mix of characters as setext section title' do
389
389
  input = <<-EOS
390
390
  My Section
391
391
  ----^^----
@@ -396,21 +396,32 @@ My Section
396
396
  assert_includes result, '----^^----'
397
397
  end
398
398
 
399
+ test 'should preprocess second line of setext section title' do
400
+ input = <<-EOS
401
+ Section Title
402
+ ifdef::asciidoctor[]
403
+ -------------
404
+ endif::[]
405
+ EOS
406
+ result = render_embedded_string input
407
+ assert_xpath '//h2', result, 1
408
+ end
409
+
399
410
  test "heading title with multiline syntax cannot begin with a dot" do
400
411
  title = ".My Title"
401
412
  chars = "-" * title.length
402
413
  assert_xpath '//h2', render_string(title + "\n" + chars), 0
403
414
  end
404
415
 
405
- test "with single-line syntax" do
416
+ test "with atx syntax" do
406
417
  assert_xpath "//h2[@id='_my_title'][text() = 'My Title']", render_string("== My Title")
407
418
  end
408
419
 
409
- test "with single-line symmetric syntax" do
420
+ test "with atx symmetric syntax" do
410
421
  assert_xpath "//h2[@id='_my_title'][text() = 'My Title']", render_string("== My Title ==")
411
422
  end
412
423
 
413
- test "with single-line non-matching symmetric syntax" do
424
+ test "with atx non-matching symmetric syntax" do
414
425
  assert_xpath "//h2[@id='_my_title'][text() = 'My Title ===']", render_string("== My Title ===")
415
426
  end
416
427
 
@@ -481,7 +492,7 @@ content
481
492
  assert_xpath "//h3[@id='_my_section'][text() = 'My Section']", render_string(":fragment:\nMy Section\n~~~~~~~~~~~")
482
493
  end
483
494
 
484
- test "with single line syntax" do
495
+ test "with atx line syntax" do
485
496
  assert_xpath "//h3[@id='_my_title'][text() = 'My Title']", render_string(":fragment:\n=== My Title")
486
497
  end
487
498
  end
@@ -491,7 +502,7 @@ content
491
502
  assert_xpath "//h4[@id='_my_section'][text() = 'My Section']", render_string(":fragment:\nMy Section\n^^^^^^^^^^")
492
503
  end
493
504
 
494
- test "with single line syntax" do
505
+ test "with atx line syntax" do
495
506
  assert_xpath "//h4[@id='_my_title'][text() = 'My Title']", render_string(":fragment:\n==== My Title")
496
507
  end
497
508
  end
@@ -501,19 +512,19 @@ content
501
512
  assert_xpath "//h5[@id='_my_section'][text() = 'My Section']", render_string(":fragment:\nMy Section\n++++++++++")
502
513
  end
503
514
 
504
- test "with single line syntax" do
515
+ test "with atx line syntax" do
505
516
  assert_xpath "//h5[@id='_my_title'][text() = 'My Title']", render_string(":fragment:\n===== My Title")
506
517
  end
507
518
  end
508
519
 
509
520
  context "level 5" do
510
- test "with single line syntax" do
521
+ test "with atx line syntax" do
511
522
  assert_xpath "//h6[@id='_my_title'][text() = 'My Title']", render_string(":fragment:\n====== My Title")
512
523
  end
513
524
  end
514
525
 
515
526
  context 'Markdown-style headings' do
516
- test 'single-line document title with leading marker' do
527
+ test 'atx document title with leading marker' do
517
528
  input = <<-EOS
518
529
  # Document Title
519
530
  EOS
@@ -521,7 +532,7 @@ content
521
532
  assert_xpath "//h1[not(@id)][text() = 'Document Title']", output, 1
522
533
  end
523
534
 
524
- test 'single-line document title with symmetric markers' do
535
+ test 'atx document title with symmetric markers' do
525
536
  input = <<-EOS
526
537
  # Document Title #
527
538
  EOS
@@ -529,7 +540,7 @@ content
529
540
  assert_xpath "//h1[not(@id)][text() = 'Document Title']", output, 1
530
541
  end
531
542
 
532
- test 'single-line section title with leading marker' do
543
+ test 'atx section title with leading marker' do
533
544
  input = <<-EOS
534
545
  ## Section One
535
546
 
@@ -539,7 +550,7 @@ blah blah
539
550
  assert_xpath "//h2[@id='_section_one'][text() = 'Section One']", output, 1
540
551
  end
541
552
 
542
- test 'single-line section title with symmetric markers' do
553
+ test 'atx section title with symmetric markers' do
543
554
  input = <<-EOS
544
555
  ## Section One ##
545
556
 
@@ -549,7 +560,7 @@ blah blah
549
560
  assert_xpath "//h2[@id='_section_one'][text() = 'Section One']", output, 1
550
561
  end
551
562
 
552
- test 'should not match mixed single-line syntax' do
563
+ test 'should not match atx syntax with mixed markers' do
553
564
  input = <<-EOS
554
565
  =#= My Title
555
566
  EOS
@@ -559,8 +570,8 @@ blah blah
559
570
  end
560
571
  end
561
572
 
562
- context 'Floating Title' do
563
- test 'should create floating title if style is float' do
573
+ context 'Discrete Heading' do
574
+ test 'should create discrete heading instead of section if style is float' do
564
575
  input = <<-EOS
565
576
  [float]
566
577
  = Independent Heading!
@@ -577,7 +588,7 @@ not in section
577
588
  assert_xpath '/h1/following-sibling::*[@class="paragraph"]/p[text()="not in section"]', output, 1
578
589
  end
579
590
 
580
- test 'should create floating title if style is discrete' do
591
+ test 'should create discrete heading instead of section if style is discrete' do
581
592
  input = <<-EOS
582
593
  [discrete]
583
594
  === Independent Heading!
@@ -595,7 +606,7 @@ not in section
595
606
  assert_xpath '/h3/following-sibling::*[@class="paragraph"]/p[text()="not in section"]', output, 1
596
607
  end
597
608
 
598
- test 'should generate id for floating title from converted title' do
609
+ test 'should generate id for discrete heading from converted title' do
599
610
  input = <<-EOS
600
611
  [discrete]
601
612
  === {sp}Heading{sp}
@@ -609,7 +620,7 @@ not in section
609
620
  assert_xpath '/h3[@class="discrete"][@id="_heading"][text()=" Heading "]', output, 1
610
621
  end
611
622
 
612
- test 'should create floating title if style is float with shorthand role and id' do
623
+ test 'should create discrete heading if style is float with shorthand role and id' do
613
624
  input = <<-EOS
614
625
  [float.independent#first]
615
626
  = Independent Heading!
@@ -626,7 +637,7 @@ not in section
626
637
  assert_xpath '/h1/following-sibling::*[@class="paragraph"]/p[text()="not in section"]', output, 1
627
638
  end
628
639
 
629
- test 'should create floating title if style is discrete with shorthand role and id' do
640
+ test 'should create discrete heading if style is discrete with shorthand role and id' do
630
641
  input = <<-EOS
631
642
  [discrete.independent#first]
632
643
  = Independent Heading!
@@ -643,7 +654,7 @@ not in section
643
654
  assert_xpath '/h1/following-sibling::*[@class="paragraph"]/p[text()="not in section"]', output, 1
644
655
  end
645
656
 
646
- test 'floating title should be a block with context floating_title' do
657
+ test 'discrete heading should be a block with context floating_title' do
647
658
  input = <<-EOS
648
659
  [float]
649
660
  === Independent Heading!
@@ -652,15 +663,26 @@ not in section
652
663
  EOS
653
664
 
654
665
  doc = document_from_string input
655
- floatingtitle = doc.blocks.first
656
- assert floatingtitle.is_a?(Asciidoctor::Block)
657
- assert floatingtitle.context != :section
658
- assert_equal :floating_title, floatingtitle.context
659
- assert_equal '_independent_heading', floatingtitle.id
666
+ heading = doc.blocks.first
667
+ assert heading.is_a?(Asciidoctor::Block)
668
+ assert_equal :floating_title, heading.context
669
+ assert_equal '_independent_heading', heading.id
660
670
  assert doc.catalog[:ids].has_key?('_independent_heading')
661
671
  end
662
672
 
663
- test 'can assign explicit id to floating title' do
673
+ test 'should preprocess second line of setext discrete heading' do
674
+ input = <<-EOS
675
+ [discrete]
676
+ Heading Title
677
+ ifdef::asciidoctor[]
678
+ -------------
679
+ endif::[]
680
+ EOS
681
+ result = render_embedded_string input
682
+ assert_xpath '//h2', result, 1
683
+ end
684
+
685
+ test 'can assign explicit id to discrete heading' do
664
686
  input = <<-EOS
665
687
  [[unchained]]
666
688
  [float]
@@ -670,12 +692,12 @@ not in section
670
692
  EOS
671
693
 
672
694
  doc = document_from_string input
673
- floating_title = doc.blocks.first
674
- assert_equal 'unchained', floating_title.id
695
+ heading = doc.blocks.first
696
+ assert_equal 'unchained', heading.id
675
697
  assert doc.catalog[:ids].has_key?('unchained')
676
698
  end
677
699
 
678
- test 'should not include floating title in toc' do
700
+ test 'should not include discrete heading in toc' do
679
701
  input = <<-EOS
680
702
  :toc:
681
703
 
@@ -693,7 +715,7 @@ not in section
693
715
  assert_xpath %(//*[@id="toc"]//a[text()="Miss Independent"]), output, 0
694
716
  end
695
717
 
696
- test 'should not set id on floating title if sectids attribute is unset' do
718
+ test 'should not set id on discrete heading if sectids attribute is unset' do
697
719
  input = <<-EOS
698
720
  [float]
699
721
  === Independent Heading!
@@ -707,7 +729,7 @@ not in section
707
729
  assert_xpath '/h3[@class="float"]', output, 1
708
730
  end
709
731
 
710
- test 'should use explicit id for floating title if specified' do
732
+ test 'should use explicit id for discrete heading if specified' do
711
733
  input = <<-EOS
712
734
  [[free]]
713
735
  [float]
@@ -722,7 +744,7 @@ not in section
722
744
  assert_xpath '/h2[@class="float"]', output, 1
723
745
  end
724
746
 
725
- test 'should add role to class attribute on floating title' do
747
+ test 'should add role to class attribute on discrete heading' do
726
748
  input = <<-EOS
727
749
  [float, role="isolated"]
728
750
  == Independent Heading!
@@ -804,7 +826,7 @@ text in standalone
804
826
  warnings = err.string
805
827
  end
806
828
 
807
- assert !warnings.empty?
829
+ refute_empty warnings
808
830
  assert_match(/only book doctypes can contain level 0 sections/, warnings)
809
831
  end
810
832
 
@@ -841,7 +863,7 @@ Master section text.
841
863
  warnings = err.string
842
864
  end
843
865
 
844
- assert warnings.empty?
866
+ assert_empty warnings
845
867
  assert_match(/Master document written by Doc Writer/, output)
846
868
  assert_match(/Standalone document written by Junior Writer/, output)
847
869
  assert_xpath '//*[@class="sect1"]/h2[text() = "Standalone Document"]', output, 1
@@ -849,7 +871,7 @@ Master section text.
849
871
  assert_xpath '//*[@class="sect1"]/h2[text() = "Section in Master"]', output, 1
850
872
  end
851
873
 
852
- test 'level offset should be added to floating title' do
874
+ test 'level offset should be added to discrete heading' do
853
875
  input = <<-EOS
854
876
  = Master Document
855
877
  Doc Writer
@@ -857,11 +879,11 @@ Doc Writer
857
879
  :leveloffset: 1
858
880
 
859
881
  [float]
860
- = Floating Title
882
+ = Discrete Heading
861
883
  EOS
862
884
 
863
885
  output = render_string input
864
- assert_xpath '//h2[@class="float"][text() = "Floating Title"]', output, 1
886
+ assert_xpath '//h2[@class="float"][text() = "Discrete Heading"]', output, 1
865
887
  end
866
888
 
867
889
  test 'should be able to reset level offset' do
@@ -2746,7 +2768,7 @@ intro
2746
2768
  end
2747
2769
 
2748
2770
  refute_nil warnings
2749
- assert !warnings.empty?
2771
+ refute_empty warnings
2750
2772
  assert_match(/ERROR:.*section/, warnings)
2751
2773
  end
2752
2774
 
@@ -2833,7 +2855,7 @@ Appendix subsection content
2833
2855
  output = render_string input, :backend => 'docbook'
2834
2856
  warnings = err.string
2835
2857
  end
2836
- assert warnings.empty?
2858
+ assert_empty warnings
2837
2859
  assert_xpath '/book/preface', output, 1
2838
2860
  assert_xpath '/book/preface/section', output, 1
2839
2861
  assert_xpath '/book/part', output, 1
@@ -38,6 +38,12 @@ context 'Substitutions' do
38
38
  result = para.apply_subs para.lines, [:normal], true
39
39
  assert_equal ['Asciidoctor', '<strong>bold</strong>', '2 &gt; 1'], result
40
40
  end
41
+
42
+ test 'apply_subs should allow the subs argument to be nil' do
43
+ block = block_from_string %([pass]\n*raw*)
44
+ result = block.apply_subs block.source, nil
45
+ assert_equal '*raw*', result
46
+ end
41
47
  end
42
48
 
43
49
  context 'Quotes' do
@@ -790,7 +796,7 @@ context 'Substitutions' do
790
796
  test 'should not match an inline image macro if target contains an endline character' do
791
797
  para = block_from_string(%(Fear not. There are no image:big\ncats.png[] around here.))
792
798
  result = para.sub_macros(para.source)
793
- assert !result.include?('<img ')
799
+ refute result.include?('<img ')
794
800
  assert_includes result, %(image:big\ncats.png[])
795
801
  end
796
802
 
@@ -798,7 +804,7 @@ context 'Substitutions' do
798
804
  ['image: big cats.png[]', 'image:big cats.png []'].each do |input|
799
805
  para = block_from_string %(Fear not. There are no #{input} around here.)
800
806
  result = para.sub_macros(para.source)
801
- assert !result.include?('<img ')
807
+ refute result.include?('<img ')
802
808
  assert_includes result, input
803
809
  end
804
810
  end
@@ -806,10 +812,24 @@ context 'Substitutions' do
806
812
  test 'should not detect a block image macro found inline' do
807
813
  para = block_from_string(%(Not an inline image macro image::tiger.png[].))
808
814
  result = para.sub_macros(para.source)
809
- assert !result.include?('<img ')
815
+ refute result.include?('<img ')
810
816
  assert result.include?('image::tiger.png[]')
811
817
  end
812
818
 
819
+ # NOTE this test verifies attributes get substituted eagerly in target of image in title
820
+ test 'should substitute attributes in target of inline image in section title' do
821
+ input = <<-EOS
822
+ == image:{iconsdir}/dot.gif[dot] Title
823
+ EOS
824
+
825
+ sect, warnings = redirect_streams do |_, err|
826
+ [(block_from_string input, :attributes => { 'data-uri' => '', 'iconsdir' => 'fixtures', 'docdir' => ::File.dirname(__FILE__) }, :safe => :server, :catalog_assets => true), err.string]
827
+ end
828
+ assert sect.document.catalog[:images].include? 'fixtures/dot.gif'
829
+ refute_nil warnings
830
+ assert_empty warnings
831
+ end
832
+
813
833
  test 'an icon macro should be interpreted as an icon if icons are enabled' do
814
834
  para = block_from_string 'icon:github[]', :attributes => {'icons' => ''}
815
835
  assert_equal %{<span class="icon"><img src="./images/icons/github.png" alt="github"></span>}, para.sub_macros(para.source).gsub(/>\s+</, '><')
@@ -846,7 +866,7 @@ context 'Substitutions' do
846
866
  assert_equal 1, para.document.catalog[:footnotes].size
847
867
  footnote = para.document.catalog[:footnotes].first
848
868
  assert_equal 1, footnote.index
849
- assert footnote.id.nil?
869
+ assert_nil footnote.id
850
870
  assert_equal 'An example footnote.', footnote.text
851
871
  end
852
872
 
@@ -856,7 +876,7 @@ context 'Substitutions' do
856
876
  assert_equal 1, para.document.catalog[:footnotes].size
857
877
  footnote = para.document.catalog[:footnotes].first
858
878
  assert_equal 1, footnote.index
859
- assert footnote.id.nil?
879
+ assert_nil footnote.id
860
880
  assert_equal "An example footnote with wrapped text.", footnote.text
861
881
  end
862
882
 
@@ -946,11 +966,11 @@ foofootnote:[+http://example.com+]barfootnote:[+http://acme.com+]baz
946
966
  assert_equal 2, para.document.catalog[:footnotes].size
947
967
  footnote1 = para.document.catalog[:footnotes][0]
948
968
  assert_equal 1, footnote1.index
949
- assert footnote1.id.nil?
969
+ assert_nil footnote1.id
950
970
  assert_equal "An example footnote.", footnote1.text
951
971
  footnote2 = para.document.catalog[:footnotes][1]
952
972
  assert_equal 2, footnote2.index
953
- assert footnote2.id.nil?
973
+ assert_nil footnote2.id
954
974
  assert_equal "Another footnote.", footnote2.text
955
975
  end
956
976
 
@@ -1392,7 +1412,7 @@ EOS
1392
1412
  assert_equal Asciidoctor::Substitutors::PASS_START + '0' + Asciidoctor::Substitutors::PASS_END, result
1393
1413
  assert_equal 1, para.passthroughs.size
1394
1414
  assert_equal '<code>inline code</code>', para.passthroughs[0][:text]
1395
- assert para.passthroughs[0][:subs].empty?
1415
+ assert_empty para.passthroughs[0][:subs]
1396
1416
  end
1397
1417
 
1398
1418
  test 'collect multi-line inline triple plus passthroughs' do
@@ -1401,7 +1421,7 @@ EOS
1401
1421
  assert_equal Asciidoctor::Substitutors::PASS_START + '0' + Asciidoctor::Substitutors::PASS_END, result
1402
1422
  assert_equal 1, para.passthroughs.size
1403
1423
  assert_equal "<code>inline\ncode</code>", para.passthroughs[0][:text]
1404
- assert para.passthroughs[0][:subs].empty?
1424
+ assert_empty para.passthroughs[0][:subs]
1405
1425
  end
1406
1426
 
1407
1427
  test 'collect inline double dollar passthroughs' do
@@ -1823,17 +1843,17 @@ foo&#8201;&#8212;&#8201;'
1823
1843
  test 'should not use subs if subs option passed to block constructor is nil' do
1824
1844
  doc = empty_document
1825
1845
  block = Asciidoctor::Block.new doc, :paragraph, :source => '*bold* _italic_', :subs => nil, :attributes => {'subs' => 'quotes'}
1826
- assert block.subs.empty?
1846
+ assert_empty block.subs
1827
1847
  block.lock_in_subs
1828
- assert block.subs.empty?
1848
+ assert_empty block.subs
1829
1849
  end
1830
1850
 
1831
1851
  test 'should not use subs if subs option passed to block constructor is empty array' do
1832
1852
  doc = empty_document
1833
1853
  block = Asciidoctor::Block.new doc, :paragraph, :source => '*bold* _italic_', :subs => [], :attributes => {'subs' => 'quotes'}
1834
- assert block.subs.empty?
1854
+ assert_empty block.subs
1835
1855
  block.lock_in_subs
1836
- assert block.subs.empty?
1856
+ assert_empty block.subs
1837
1857
  end
1838
1858
 
1839
1859
  test 'should use subs from subs option passed to block constructor' do
@@ -1847,7 +1867,7 @@ foo&#8201;&#8212;&#8201;'
1847
1867
  test 'should use subs from subs attribute if subs option is not passed to block constructor' do
1848
1868
  doc = empty_document
1849
1869
  block = Asciidoctor::Block.new doc, :paragraph, :source => '*bold* _italic_', :attributes => {'subs' => 'quotes'}
1850
- assert block.subs.empty?
1870
+ assert_empty block.subs
1851
1871
  # in this case, we have to call lock_in_subs to resolve the subs
1852
1872
  block.lock_in_subs
1853
1873
  assert_equal [:quotes], block.subs