pseudohikiparser 0.0.3 → 0.0.4.develop
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.ja.md +132 -8
- data/README.md +134 -10
- data/lib/htmlelement.rb +42 -42
- data/lib/pseudohiki/autolink.rb +60 -0
- data/lib/pseudohiki/blockparser.rb +233 -125
- data/lib/pseudohiki/converter.rb +140 -81
- data/lib/pseudohiki/htmlformat.rb +156 -82
- data/lib/pseudohiki/htmlplugin.rb +9 -28
- data/lib/pseudohiki/inlineparser.rb +21 -24
- data/lib/pseudohiki/markdownformat.rb +94 -98
- data/lib/pseudohiki/plaintextformat.rb +67 -57
- data/lib/pseudohiki/sinatra_helpers.rb +23 -0
- data/lib/pseudohiki/treestack.rb +4 -4
- data/lib/pseudohiki/utils.rb +1 -2
- data/lib/pseudohiki/version.rb +1 -1
- data/lib/pseudohikiparser.rb +49 -28
- data/test/test_autolink.rb +104 -0
- data/test/test_blockparser.rb +78 -11
- data/test/test_htmlformat.rb +436 -0
- data/test/test_htmlplugin.rb +43 -0
- data/test/test_markdownformat.rb +156 -3
- data/test/test_plaintextformat.rb +85 -0
- data/test/test_pseudohiki2html.rb +82 -0
- data/test/test_pseudohikiparser.rb +286 -0
- data/test/test_utils.rb +1 -1
- metadata +22 -4
data/test/test_htmlformat.rb
CHANGED
@@ -677,6 +677,20 @@ HTML
|
|
677
677
|
assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
|
678
678
|
end
|
679
679
|
|
680
|
+
def test_no_automatical_link_generation
|
681
|
+
text = <<TEXT
|
682
|
+
a line with a url http://www.example.org/ to test an automatical link generation.
|
683
|
+
TEXT
|
684
|
+
|
685
|
+
xhtml = <<HTML
|
686
|
+
<p>
|
687
|
+
a line with a url http://www.example.org/ to test an automatical link generation.
|
688
|
+
</p>
|
689
|
+
HTML
|
690
|
+
tree = BlockParser.parse(text.lines.to_a, AutoLink::Off)
|
691
|
+
assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
|
692
|
+
end
|
693
|
+
|
680
694
|
def test_automatical_link_generation_in_verbatim_blocks
|
681
695
|
text = <<TEXT
|
682
696
|
a line with a url http://www.example.org/ to test an automatical link generation.
|
@@ -696,6 +710,428 @@ HTML
|
|
696
710
|
assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
|
697
711
|
end
|
698
712
|
|
713
|
+
def test_no_automatical_link_generation_in_verbatim_blocks
|
714
|
+
text = <<TEXT
|
715
|
+
a line with a url http://www.example.org/ to test an automatical link generation.
|
716
|
+
|
717
|
+
another line with [[link|sample.html]]
|
718
|
+
TEXT
|
719
|
+
|
720
|
+
xhtml = <<HTML
|
721
|
+
<pre>
|
722
|
+
a line with a url http://www.example.org/ to test an automatical link generation.
|
723
|
+
</pre>
|
724
|
+
<pre>
|
725
|
+
another line with [[link|sample.html]]
|
726
|
+
</pre>
|
727
|
+
HTML
|
728
|
+
tree = BlockParser.parse(text.lines.to_a)
|
729
|
+
XhtmlFormat.auto_link_in_verbatim = false
|
730
|
+
assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
|
731
|
+
XhtmlFormat.auto_link_in_verbatim = true
|
732
|
+
end
|
733
|
+
|
734
|
+
def test_temporal_no_automatical_link_generation_in_verbatim_blocks
|
735
|
+
text = <<TEXT
|
736
|
+
a line with a url http://www.example.org/ to test an automatical link generation.
|
737
|
+
|
738
|
+
another line with [[link|sample.html]]
|
739
|
+
TEXT
|
740
|
+
|
741
|
+
xhtml = <<HTML
|
742
|
+
<pre>
|
743
|
+
a line with a url http://www.example.org/ to test an automatical link generation.
|
744
|
+
</pre>
|
745
|
+
<pre>
|
746
|
+
another line with [[link|sample.html]]
|
747
|
+
</pre>
|
748
|
+
HTML
|
749
|
+
tree = BlockParser.parse(text.lines.to_a)
|
750
|
+
assert_equal(xhtml, XhtmlFormat.format(tree, {:auto_link_in_verbatim => false }).to_s)
|
751
|
+
end
|
752
|
+
|
753
|
+
def test_temporal_no_automatical_link_generation_in_verbatim_blocks_with_html
|
754
|
+
text = <<TEXT
|
755
|
+
a line with a url http://www.example.org/ to test an automatical link generation.
|
756
|
+
|
757
|
+
another line with [[link|sample.html]]
|
758
|
+
TEXT
|
759
|
+
|
760
|
+
xhtml = <<HTML
|
761
|
+
<pre>
|
762
|
+
a line with a url http://www.example.org/ to test an automatical link generation.
|
763
|
+
</pre>
|
764
|
+
<pre>
|
765
|
+
another line with [[link|sample.html]]
|
766
|
+
</pre>
|
767
|
+
HTML
|
768
|
+
tree = BlockParser.parse(text.lines.to_a)
|
769
|
+
assert_equal(xhtml, HtmlFormat.format(tree, {:auto_link_in_verbatim => false }).to_s)
|
770
|
+
end
|
771
|
+
|
772
|
+
def test_decorator
|
773
|
+
text = <<TEXT
|
774
|
+
//@class[section_type]
|
775
|
+
!!title of section
|
776
|
+
|
777
|
+
a paragraph.
|
778
|
+
|
779
|
+
//@class[class_name]
|
780
|
+
//@id[id_name]
|
781
|
+
another paragraph.
|
782
|
+
TEXT
|
783
|
+
|
784
|
+
xhtml = <<HTML
|
785
|
+
<div class="section_type">
|
786
|
+
<h2>title of section</h2>
|
787
|
+
<p>
|
788
|
+
a paragraph.</p>
|
789
|
+
<p class="class_name" id="ID_NAME">
|
790
|
+
another paragraph.</p>
|
791
|
+
<!-- end of section_type -->
|
792
|
+
</div>
|
793
|
+
HTML
|
794
|
+
tree = BlockParser.parse(text.lines.to_a.map {|line| line.chomp })
|
795
|
+
assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
|
796
|
+
end
|
797
|
+
|
798
|
+
def test_decorator_for_table
|
799
|
+
text = <<TEXT
|
800
|
+
//@summary: Summary of the table
|
801
|
+
||!header 1||! header 2
|
802
|
+
||cell 1||cell 2
|
803
|
+
TEXT
|
804
|
+
|
805
|
+
xhtml = <<HTML
|
806
|
+
<table summary="Summary of the table">
|
807
|
+
<tr><th>header 1</th><th> header 2</th></tr>
|
808
|
+
<tr><td>cell 1</td><td>cell 2</td></tr>
|
809
|
+
</table>
|
810
|
+
HTML
|
811
|
+
tree = BlockParser.parse(text.lines.to_a.map {|line| line.chomp })
|
812
|
+
assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
|
813
|
+
end
|
814
|
+
|
815
|
+
def test_decorator_for_verbatim
|
816
|
+
text = <<TEXT
|
817
|
+
//@code[ruby]
|
818
|
+
def bonjour!
|
819
|
+
puts "Bonjour!"
|
820
|
+
end
|
821
|
+
TEXT
|
822
|
+
|
823
|
+
xhtml = <<HTML
|
824
|
+
<pre>
|
825
|
+
def bonjour!
|
826
|
+
puts "Bonjour!"
|
827
|
+
end
|
828
|
+
</pre>
|
829
|
+
HTML
|
830
|
+
|
831
|
+
tree = BlockParser.parse(text.lines.to_a)
|
832
|
+
assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
|
833
|
+
end
|
834
|
+
|
835
|
+
def test_sectioning_node
|
836
|
+
text = <<TEXT
|
837
|
+
! Main title
|
838
|
+
|
839
|
+
//@begin[header]
|
840
|
+
!! first title in header
|
841
|
+
|
842
|
+
paragraph
|
843
|
+
|
844
|
+
!! second title in header
|
845
|
+
|
846
|
+
paragraph2
|
847
|
+
|
848
|
+
//@end[header]
|
849
|
+
|
850
|
+
!! first subtitle in main part
|
851
|
+
|
852
|
+
paragraph3
|
853
|
+
|
854
|
+
//@begin[#footer]
|
855
|
+
|
856
|
+
paragraph4
|
857
|
+
|
858
|
+
//@end[#footer]
|
859
|
+
|
860
|
+
TEXT
|
861
|
+
|
862
|
+
expected_html = <<HTML
|
863
|
+
<div class="section h1">
|
864
|
+
<h1> Main title
|
865
|
+
</h1>
|
866
|
+
<div class="header">
|
867
|
+
<div class="section h2">
|
868
|
+
<h2> first title in header
|
869
|
+
</h2>
|
870
|
+
<p>
|
871
|
+
paragraph
|
872
|
+
</p>
|
873
|
+
<!-- end of section h2 -->
|
874
|
+
</div>
|
875
|
+
<div class="section h2">
|
876
|
+
<h2> second title in header
|
877
|
+
</h2>
|
878
|
+
<p>
|
879
|
+
paragraph2
|
880
|
+
</p>
|
881
|
+
<!-- end of section h2 -->
|
882
|
+
</div>
|
883
|
+
<!-- end of header -->
|
884
|
+
</div>
|
885
|
+
<div class="section h2">
|
886
|
+
<h2> first subtitle in main part
|
887
|
+
</h2>
|
888
|
+
<p>
|
889
|
+
paragraph3
|
890
|
+
</p>
|
891
|
+
<div class="section" id="footer">
|
892
|
+
<p>
|
893
|
+
paragraph4
|
894
|
+
</p>
|
895
|
+
<!-- end of footer -->
|
896
|
+
</div>
|
897
|
+
<!-- end of section h2 -->
|
898
|
+
</div>
|
899
|
+
<!-- end of section h1 -->
|
900
|
+
</div>
|
901
|
+
HTML
|
902
|
+
|
903
|
+
tree = BlockParser.parse(text.lines.to_a)
|
904
|
+
assert_equal(expected_html, XhtmlFormat.format(tree).to_s)
|
905
|
+
end
|
906
|
+
|
907
|
+
def test_sectioning_node_for_html5
|
908
|
+
text = <<TEXT
|
909
|
+
! Main title
|
910
|
+
|
911
|
+
//@begin[header]
|
912
|
+
!! first title in header
|
913
|
+
|
914
|
+
paragraph
|
915
|
+
|
916
|
+
!! second title in header
|
917
|
+
|
918
|
+
paragraph2
|
919
|
+
|
920
|
+
//@end[header]
|
921
|
+
|
922
|
+
!! first subtitle in main part
|
923
|
+
|
924
|
+
paragraph3
|
925
|
+
|
926
|
+
//@begin[#footer]
|
927
|
+
|
928
|
+
paragraph4
|
929
|
+
|
930
|
+
//@end[#footer]
|
931
|
+
|
932
|
+
TEXT
|
933
|
+
|
934
|
+
expected_html = <<HTML
|
935
|
+
<section class="h1">
|
936
|
+
<h1> Main title
|
937
|
+
</h1>
|
938
|
+
<header>
|
939
|
+
<section class="h2">
|
940
|
+
<h2> first title in header
|
941
|
+
</h2>
|
942
|
+
<p>
|
943
|
+
paragraph
|
944
|
+
</p>
|
945
|
+
<!-- end of h2 -->
|
946
|
+
</section>
|
947
|
+
<section class="h2">
|
948
|
+
<h2> second title in header
|
949
|
+
</h2>
|
950
|
+
<p>
|
951
|
+
paragraph2
|
952
|
+
</p>
|
953
|
+
<!-- end of h2 -->
|
954
|
+
</section>
|
955
|
+
</header>
|
956
|
+
<section class="h2">
|
957
|
+
<h2> first subtitle in main part
|
958
|
+
</h2>
|
959
|
+
<p>
|
960
|
+
paragraph3
|
961
|
+
</p>
|
962
|
+
<section id="footer">
|
963
|
+
<p>
|
964
|
+
paragraph4
|
965
|
+
</p>
|
966
|
+
<!-- end of footer -->
|
967
|
+
</section>
|
968
|
+
<!-- end of h2 -->
|
969
|
+
</section>
|
970
|
+
<!-- end of h1 -->
|
971
|
+
</section>
|
972
|
+
HTML
|
973
|
+
|
974
|
+
tree = BlockParser.parse(text.lines.to_a)
|
975
|
+
assert_equal(expected_html, Xhtml5Format.format(tree).to_s)
|
976
|
+
end
|
977
|
+
|
978
|
+
def test_sectioning_node_when_end_tag_is_omitted
|
979
|
+
text = <<TEXT
|
980
|
+
!! First part
|
981
|
+
|
982
|
+
paragraph1
|
983
|
+
|
984
|
+
//@begin[first_sub_part]
|
985
|
+
!!! first title in first sub-part
|
986
|
+
|
987
|
+
paragraph2
|
988
|
+
|
989
|
+
!!! second title in first sub-part
|
990
|
+
|
991
|
+
paragraph3
|
992
|
+
|
993
|
+
//you should put //@end[first_sub_part] here.
|
994
|
+
|
995
|
+
!! Second part
|
996
|
+
|
997
|
+
paragraph4
|
998
|
+
|
999
|
+
//@begin[#footer]
|
1000
|
+
|
1001
|
+
paragraph5
|
1002
|
+
|
1003
|
+
//@end[#footer]
|
1004
|
+
|
1005
|
+
TEXT
|
1006
|
+
|
1007
|
+
expected_html = <<HTML
|
1008
|
+
<div class=\"section h2\">
|
1009
|
+
<h2> First part
|
1010
|
+
</h2>
|
1011
|
+
<p>
|
1012
|
+
paragraph1
|
1013
|
+
</p>
|
1014
|
+
<div class=\"section first_sub_part\">
|
1015
|
+
<div class=\"section h3\">
|
1016
|
+
<h3> first title in first sub-part
|
1017
|
+
</h3>
|
1018
|
+
<p>
|
1019
|
+
paragraph2
|
1020
|
+
</p>
|
1021
|
+
<!-- end of section h3 -->
|
1022
|
+
</div>
|
1023
|
+
<div class=\"section h3\">
|
1024
|
+
<h3> second title in first sub-part
|
1025
|
+
</h3>
|
1026
|
+
<p>
|
1027
|
+
paragraph3
|
1028
|
+
</p>
|
1029
|
+
<!-- end of section h3 -->
|
1030
|
+
</div>
|
1031
|
+
<!-- end of section first_sub_part -->
|
1032
|
+
</div>
|
1033
|
+
<!-- end of section h2 -->
|
1034
|
+
</div>
|
1035
|
+
<div class=\"section h2\">
|
1036
|
+
<h2> Second part
|
1037
|
+
</h2>
|
1038
|
+
<p>
|
1039
|
+
paragraph4
|
1040
|
+
</p>
|
1041
|
+
<div class=\"section\" id=\"footer\">
|
1042
|
+
<p>
|
1043
|
+
paragraph5
|
1044
|
+
</p>
|
1045
|
+
<!-- end of footer -->
|
1046
|
+
</div>
|
1047
|
+
<!-- end of section h2 -->
|
1048
|
+
</div>
|
1049
|
+
HTML
|
1050
|
+
|
1051
|
+
tree = BlockParser.parse(text.lines.to_a)
|
1052
|
+
assert_equal(expected_html, XhtmlFormat.format(tree).to_s)
|
1053
|
+
end
|
1054
|
+
|
1055
|
+
def test_sectioning_node_when_end_tag_is_wrongly_placed
|
1056
|
+
text = <<TEXT
|
1057
|
+
!! First part
|
1058
|
+
|
1059
|
+
paragraph1
|
1060
|
+
|
1061
|
+
//@begin[first_sub_part]
|
1062
|
+
!!! first title in first sub-part
|
1063
|
+
|
1064
|
+
paragraph2
|
1065
|
+
|
1066
|
+
!!! second title in first sub-part
|
1067
|
+
|
1068
|
+
paragraph3
|
1069
|
+
|
1070
|
+
//you should put //@end[first_sub_part] here.
|
1071
|
+
|
1072
|
+
!! Second part
|
1073
|
+
|
1074
|
+
paragraph4
|
1075
|
+
|
1076
|
+
|
1077
|
+
//@end[first_sub_part] this end tag is wrongly placed.
|
1078
|
+
|
1079
|
+
//@begin[#footer]
|
1080
|
+
|
1081
|
+
paragraph5
|
1082
|
+
|
1083
|
+
//@end[#footer]
|
1084
|
+
|
1085
|
+
TEXT
|
1086
|
+
|
1087
|
+
expected_html = <<HTML
|
1088
|
+
<div class=\"section h2\">
|
1089
|
+
<h2> First part
|
1090
|
+
</h2>
|
1091
|
+
<p>
|
1092
|
+
paragraph1
|
1093
|
+
</p>
|
1094
|
+
<div class=\"section first_sub_part\">
|
1095
|
+
<div class=\"section h3\">
|
1096
|
+
<h3> first title in first sub-part
|
1097
|
+
</h3>
|
1098
|
+
<p>
|
1099
|
+
paragraph2
|
1100
|
+
</p>
|
1101
|
+
<!-- end of section h3 -->
|
1102
|
+
</div>
|
1103
|
+
<div class=\"section h3\">
|
1104
|
+
<h3> second title in first sub-part
|
1105
|
+
</h3>
|
1106
|
+
<p>
|
1107
|
+
paragraph3
|
1108
|
+
</p>
|
1109
|
+
<!-- end of section h3 -->
|
1110
|
+
</div>
|
1111
|
+
<!-- end of section first_sub_part -->
|
1112
|
+
</div>
|
1113
|
+
<!-- end of section h2 -->
|
1114
|
+
</div>
|
1115
|
+
<div class=\"section h2\">
|
1116
|
+
<h2> Second part
|
1117
|
+
</h2>
|
1118
|
+
<p>
|
1119
|
+
paragraph4
|
1120
|
+
</p>
|
1121
|
+
<div class=\"section\" id=\"footer\">
|
1122
|
+
<p>
|
1123
|
+
paragraph5
|
1124
|
+
</p>
|
1125
|
+
<!-- end of footer -->
|
1126
|
+
</div>
|
1127
|
+
<!-- end of section h2 -->
|
1128
|
+
</div>
|
1129
|
+
HTML
|
1130
|
+
|
1131
|
+
tree = BlockParser.parse(text.lines.to_a)
|
1132
|
+
assert_equal(expected_html, XhtmlFormat.format(tree).to_s)
|
1133
|
+
end
|
1134
|
+
|
699
1135
|
def test_comment_out_followed_by_a_verbatim_block
|
700
1136
|
text = <<TEXT
|
701
1137
|
the first paragraph
|
data/test/test_htmlplugin.rb
CHANGED
@@ -23,4 +23,47 @@ class TC_HtmlPlugin < MiniTest::Unit::TestCase
|
|
23
23
|
tree = InlineParser.new("you can directly embed a snippet of html code like '{{html(<i>italic</i>)}}'.").parse.tree
|
24
24
|
assert_equal("you can directly embed a snippet of html code like '<i>italic</i>'.",tree.accept(formatter).to_s)
|
25
25
|
end
|
26
|
+
|
27
|
+
def test_html
|
28
|
+
expected_html = '<ul>
|
29
|
+
<li>list
|
30
|
+
<li>list
|
31
|
+
</ul>'
|
32
|
+
|
33
|
+
input = "html(
|
34
|
+
<ul>
|
35
|
+
<li>list
|
36
|
+
<li>list
|
37
|
+
</ul>)"
|
38
|
+
|
39
|
+
assert_equal(expected_html, HtmlPlugin.new("div", input).apply)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_inline
|
43
|
+
input = "inline(
|
44
|
+
*list
|
45
|
+
*list
|
46
|
+
)"
|
47
|
+
|
48
|
+
assert_raises(ArgumentError) do
|
49
|
+
HtmlPlugin.new("div", input).apply
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_co2
|
54
|
+
assert_equal("CO<sub>2</sub>", HtmlPlugin.new("div", "co2").apply)
|
55
|
+
assert_equal("carbon dioxide", HtmlPlugin.new("div", "co2 :en").apply)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_cubic
|
59
|
+
assert_equal("3km<sup>3</sup>", HtmlPlugin.new("div", "cb(3km)").apply)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_per
|
63
|
+
assert_equal("m<sup>-1</sup>", HtmlPlugin.new("div", "per m").apply)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_co2_isotope
|
67
|
+
assert_equal("<sup>18</sup>CO<sub>2</sub>", HtmlPlugin.new("div", "iso 18co2").apply)
|
68
|
+
end
|
26
69
|
end
|
data/test/test_markdownformat.rb
CHANGED
@@ -44,11 +44,11 @@ TEXT
|
|
44
44
|
assert_equal(gfm_text, MarkDownFormat.format(tree, :gfm_style => true))
|
45
45
|
end
|
46
46
|
|
47
|
-
def
|
47
|
+
def test_self_convert_into_gfm_id_format
|
48
48
|
heading_with_non_ascii_chars = "class PseudoHiki::BlockParser"
|
49
49
|
heading_with_multiple_spaces = "Development status of features from the original Hiki notation"
|
50
|
-
gfm_id_with_non_ascii_chars = MarkDownFormat.
|
51
|
-
gfm_id_with_multiple_spaces = MarkDownFormat.
|
50
|
+
gfm_id_with_non_ascii_chars = MarkDownFormat.convert_into_gfm_id_format(heading_with_non_ascii_chars)
|
51
|
+
gfm_id_with_multiple_spaces = MarkDownFormat.convert_into_gfm_id_format(heading_with_multiple_spaces)
|
52
52
|
assert_equal("class-pseudohikiblockparser", gfm_id_with_non_ascii_chars)
|
53
53
|
assert_equal("development-status-of-features-from-the-original-hiki-notation", gfm_id_with_multiple_spaces)
|
54
54
|
end
|
@@ -518,6 +518,159 @@ TEXT
|
|
518
518
|
assert_equal(md_text, @formatter.format(tree).to_s)
|
519
519
|
end
|
520
520
|
|
521
|
+
def test_decorator_for_verbatim
|
522
|
+
text = <<TEXT
|
523
|
+
//@code[ruby]
|
524
|
+
def bonjour!
|
525
|
+
puts "Bonjour!"
|
526
|
+
end
|
527
|
+
TEXT
|
528
|
+
|
529
|
+
gfm_text =<<TEXT
|
530
|
+
```ruby
|
531
|
+
def bonjour!
|
532
|
+
puts "Bonjour!"
|
533
|
+
end
|
534
|
+
```
|
535
|
+
|
536
|
+
TEXT
|
537
|
+
|
538
|
+
md_text = <<TEXT
|
539
|
+
def bonjour!
|
540
|
+
puts "Bonjour!"
|
541
|
+
end
|
542
|
+
|
543
|
+
TEXT
|
544
|
+
|
545
|
+
tree = BlockParser.parse(text.lines.to_a)
|
546
|
+
assert_equal(gfm_text, @gfm_formatter.format(tree).to_s)
|
547
|
+
assert_equal(md_text, @formatter.format(tree).to_s)
|
548
|
+
end
|
549
|
+
|
550
|
+
def test_decorator_for_verbatim_block
|
551
|
+
text = <<TEXT
|
552
|
+
//@code[ruby]
|
553
|
+
<<<
|
554
|
+
def bonjour!
|
555
|
+
puts "Bonjour!"
|
556
|
+
end
|
557
|
+
>>>
|
558
|
+
TEXT
|
559
|
+
|
560
|
+
gfm_text =<<TEXT
|
561
|
+
```ruby
|
562
|
+
def bonjour!
|
563
|
+
puts "Bonjour!"
|
564
|
+
end
|
565
|
+
```
|
566
|
+
|
567
|
+
TEXT
|
568
|
+
|
569
|
+
md_text = <<TEXT
|
570
|
+
def bonjour!
|
571
|
+
puts "Bonjour!"
|
572
|
+
end
|
573
|
+
|
574
|
+
TEXT
|
575
|
+
|
576
|
+
tree = BlockParser.parse(text.lines.to_a)
|
577
|
+
assert_equal(gfm_text, @gfm_formatter.format(tree).to_s)
|
578
|
+
assert_equal(md_text, @formatter.format(tree).to_s)
|
579
|
+
end
|
580
|
+
|
581
|
+
def test_without_sectioning_node
|
582
|
+
text = <<TEXT
|
583
|
+
! Main title
|
584
|
+
|
585
|
+
!! first title in header
|
586
|
+
|
587
|
+
paragraph
|
588
|
+
|
589
|
+
!! second title in header
|
590
|
+
|
591
|
+
paragraph2
|
592
|
+
|
593
|
+
!! first subtitle in main part
|
594
|
+
|
595
|
+
paragraph3
|
596
|
+
|
597
|
+
paragraph4
|
598
|
+
|
599
|
+
TEXT
|
600
|
+
|
601
|
+
expected_text = <<HTML
|
602
|
+
# Main title
|
603
|
+
|
604
|
+
## first title in header
|
605
|
+
|
606
|
+
paragraph
|
607
|
+
|
608
|
+
## second title in header
|
609
|
+
|
610
|
+
paragraph2
|
611
|
+
|
612
|
+
## first subtitle in main part
|
613
|
+
|
614
|
+
paragraph3
|
615
|
+
|
616
|
+
paragraph4
|
617
|
+
|
618
|
+
HTML
|
619
|
+
|
620
|
+
tree = BlockParser.parse(text.lines.to_a)
|
621
|
+
assert_equal(expected_text, @gfm_formatter.format(tree).to_s)
|
622
|
+
end
|
623
|
+
|
624
|
+
def test_sectioning_node
|
625
|
+
text = <<TEXT
|
626
|
+
! Main title
|
627
|
+
|
628
|
+
//@begin[header]
|
629
|
+
!! first title in header
|
630
|
+
|
631
|
+
paragraph
|
632
|
+
|
633
|
+
!! second title in header
|
634
|
+
|
635
|
+
paragraph2
|
636
|
+
|
637
|
+
//@end[header]
|
638
|
+
|
639
|
+
!! first subtitle in main part
|
640
|
+
|
641
|
+
paragraph3
|
642
|
+
|
643
|
+
//@begin[#footer]
|
644
|
+
|
645
|
+
paragraph4
|
646
|
+
|
647
|
+
//@end[#footer]
|
648
|
+
|
649
|
+
TEXT
|
650
|
+
|
651
|
+
expected_text = <<HTML
|
652
|
+
# Main title
|
653
|
+
|
654
|
+
## first title in header
|
655
|
+
|
656
|
+
paragraph
|
657
|
+
|
658
|
+
## second title in header
|
659
|
+
|
660
|
+
paragraph2
|
661
|
+
|
662
|
+
## first subtitle in main part
|
663
|
+
|
664
|
+
paragraph3
|
665
|
+
|
666
|
+
paragraph4
|
667
|
+
|
668
|
+
HTML
|
669
|
+
|
670
|
+
tree = BlockParser.parse(text.lines.to_a)
|
671
|
+
assert_equal(expected_text, @gfm_formatter.format(tree).to_s)
|
672
|
+
end
|
673
|
+
|
521
674
|
def test_collect_headings
|
522
675
|
text = <<TEXT
|
523
676
|
!![main-heading] heading
|