pseudohikiparser 0.0.5 → 0.0.6.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.
@@ -311,6 +311,73 @@ TEXT
311
311
  assert_equal([[[["heading"]]]],parsed)
312
312
  end
313
313
 
314
+
315
+ def test_decorator
316
+ text = <<TEXT
317
+ //@class[section_name]
318
+ !!title of section
319
+
320
+ //@summary: Summary of the table
321
+ ||!header 1||! header 2
322
+ ||cell 1||cell 2
323
+
324
+ a paragraph.
325
+
326
+ //@class[class_name]
327
+ //@[id_name]
328
+ another paragraph.
329
+ TEXT
330
+
331
+ tree = PseudoHiki::BlockParser.parse(text.lines.to_a.map {|line| line.chomp })
332
+ assert_equal(PseudoHiki::BlockParser::BlockNode, tree.class)
333
+ assert_equal("section_name", tree[0].decorator["class"].id)
334
+ assert_equal(PseudoHiki::BlockParser::BlockElement::HeadingNode, tree[0].class)
335
+ assert_equal([[["title of section"]], [[[["header 1"]], [[" header 2"]]], [[["cell 1"]], [["cell 2"]]]], [[["a paragraph."]]], [[["another paragraph."]]]], tree[0])
336
+ assert_equal([["Summary of the table"]], tree[0][1].decorator["summary"].value)
337
+ assert_equal(PseudoHiki::BlockParser::BlockElement::TableNode, tree[0][1].class)
338
+ assert_equal(nil, tree[0][2].decorator)
339
+ assert_equal('id_name', tree[0][3].decorator[:id].id)
340
+ assert_equal('class_name', tree[0][3].decorator["class"].id)
341
+ end
342
+
343
+ def test_sectioning_node
344
+ text = <<TEXT
345
+ ! Main title
346
+
347
+ //@begin[header]
348
+ !! first title in header
349
+
350
+ paragraph
351
+
352
+ !! second title in header
353
+
354
+ paragraph2
355
+
356
+ //@end[header]
357
+
358
+ !! first subtitle in main part
359
+
360
+ paragraph3
361
+
362
+ TEXT
363
+
364
+ expected_tree = [[[[" Main title\n"]],
365
+ [
366
+ [[[" first title in header\n"]],
367
+ [[["paragraph\n"]]]],
368
+ [[[" second title in header\n"]],
369
+ [[["paragraph2\n"]]]]
370
+ ],
371
+ [[[" first subtitle in main part\n"]],
372
+ [[["paragraph3\n"]]]]]]
373
+
374
+
375
+ tree = PseudoHiki::BlockParser.parse(text)
376
+ assert_equal(expected_tree, tree)
377
+ assert_kind_of(PseudoHiki::BlockParser::BlockElement::SectioningNode, tree[0][1])
378
+ assert_equal("header", tree[0][1].node_id)
379
+ end
380
+
314
381
  def test_comment_out_followed_by_a_verbatim_block
315
382
  text = <<TEXT
316
383
  the first paragraph
@@ -4,6 +4,40 @@ require 'minitest/autorun'
4
4
  require 'lib/htmlelement'
5
5
 
6
6
  class TC_HtmlElement < MiniTest::Unit::TestCase
7
+ def test_pop
8
+ section = HtmlElement.create("section")
9
+ h1 = HtmlElement.create("h1")
10
+ section.push h1
11
+ assert_equal(section.children[0], h1)
12
+ assert_equal(section, h1.parent)
13
+ section.pop
14
+ assert(section.children.empty?)
15
+ assert_nil(h1.parent)
16
+ end
17
+
18
+ def test_unshift
19
+ section = HtmlElement.create("section")
20
+ paragraph = HtmlElement.create("p", "paragraph")
21
+ h1 = HtmlElement.create("h1", "title")
22
+ section.push paragraph
23
+ assert_equal(1, section.children.length)
24
+ section.unshift h1
25
+ assert_equal(2, section.children.length)
26
+ assert_equal(h1, section.children[0])
27
+ end
28
+
29
+ def test_shift
30
+ section = HtmlElement.create("section")
31
+ paragraph = HtmlElement.create("p", "paragraph")
32
+ h1 = HtmlElement.create("h1", "title")
33
+ section.push h1
34
+ section.push paragraph
35
+ assert_equal(section.children[0], h1)
36
+ assert_equal(section, h1.parent)
37
+ section.shift
38
+ refute(section.children.include?(h1))
39
+ assert_nil(h1.parent)
40
+ end
7
41
 
8
42
  def test_format_attributes
9
43
  a = HtmlElement.create("a")
@@ -135,11 +135,19 @@ table_with_col_header_text = <<TABLE
135
135
  ||!header1||col1-1||col2-1
136
136
  ||!header2||col1-2||col2-2
137
137
  ||!header3||col1-3||col2-3
138
+ TABLE
139
+
140
+ table_with_row_header_and_caption_text = <<TABLE
141
+ //@caption: Caption
142
+ ||!header1||!header2||!header3
143
+ ||row1-1||row1-2||row1-3
144
+ ||row2-1||row2-2||row2-3
138
145
  TABLE
139
146
 
140
147
  @table_manager = HtmlElement::Utils::TableManager.new
141
148
  @table_with_row_header = PseudoHiki::BlockParser.parse(table_with_row_header_text)
142
149
  @table_with_col_header = PseudoHiki::BlockParser.parse(table_with_col_header_text)
150
+ @table_with_row_header_and_caption = PseudoHiki::BlockParser.parse(table_with_row_header_and_caption_text)
143
151
 
144
152
  end
145
153
 
@@ -149,6 +157,9 @@ TABLE
149
157
 
150
158
  html_table = PseudoHiki::HtmlFormat.format(@table_with_col_header)[0]
151
159
  assert_equal("row", @table_manager.guess_header_scope(html_table))
160
+
161
+ html_table = PseudoHiki::HtmlFormat.format(@table_with_row_header_and_caption)[0]
162
+ assert_equal("col", @table_manager.guess_header_scope(html_table))
152
163
  end
153
164
 
154
165
  def test_assign_scope
@@ -775,6 +775,419 @@ HTML
775
775
  assert_equal(xhtml, HtmlFormat.format(tree, {:auto_link_in_verbatim => false }).to_s)
776
776
  end
777
777
 
778
+ def test_decorator
779
+ text = <<TEXT
780
+ //@class[section_type]
781
+ !!title of section
782
+
783
+ a paragraph.
784
+
785
+ //@class[class_name]
786
+ //@id[id_name]
787
+ another paragraph.
788
+ TEXT
789
+
790
+ xhtml = <<HTML
791
+ <div class="section_type">
792
+ <h2>title of section</h2>
793
+ <p>
794
+ a paragraph.</p>
795
+ <p class="class_name" id="ID_NAME">
796
+ another paragraph.</p>
797
+ <!-- end of section_type -->
798
+ </div>
799
+ HTML
800
+ tree = BlockParser.parse(text.lines.to_a.map {|line| line.chomp })
801
+ assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
802
+ end
803
+
804
+ def test_decorator_for_table
805
+ text = <<TEXT
806
+ //@summary: Summary of the table
807
+ ||!header 1||! header 2
808
+ ||cell 1||cell 2
809
+ TEXT
810
+
811
+ xhtml = <<HTML
812
+ <table summary="Summary of the table">
813
+ <tr><th>header 1</th><th> header 2</th></tr>
814
+ <tr><td>cell 1</td><td>cell 2</td></tr>
815
+ </table>
816
+ HTML
817
+ tree = BlockParser.parse(text.lines.to_a.map {|line| line.chomp })
818
+ assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
819
+ end
820
+
821
+ def test_decorator_for_table_summary
822
+ text = <<TEXT
823
+ //@summary: Summary of the table
824
+ ||!header 1||! header 2
825
+ TEXT
826
+
827
+ xhtml = <<HTML
828
+ <table summary="Summary of the table">
829
+ <tr><th>header 1</th><th> header 2
830
+ </th></tr>
831
+ </table>
832
+ HTML
833
+ tree = BlockParser.parse(text.lines.to_a.map {|line| line })
834
+ assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
835
+ end
836
+
837
+ def test_decorator_for_table_caption
838
+ text = <<TEXT
839
+ //@caption: Caption of ''the table''
840
+ ||!header 1||! header 2
841
+ ||cell 1||cell 2
842
+ TEXT
843
+
844
+ xhtml = <<HTML
845
+ <table>
846
+ <caption>Caption of <em>the table</em></caption>
847
+ <tr><th>header 1</th><th> header 2</th></tr>
848
+ <tr><td>cell 1</td><td>cell 2</td></tr>
849
+ </table>
850
+ HTML
851
+ tree = BlockParser.parse(text.lines.to_a.map {|line| line.chomp })
852
+ assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
853
+ end
854
+
855
+ def test_decorator_for_table_caption_with_tags
856
+ text = <<TEXT
857
+ //@caption: [[''Table caption''that begins with a link|http://www.example.org/]] and contains other strings
858
+ ||!header 1||! header 2
859
+ TEXT
860
+
861
+ xhtml = <<HTML
862
+ <table>
863
+ <caption><a href="http://www.example.org/"><em>Table caption</em>that begins with a link</a> and contains other strings</caption>
864
+ <tr><th>header 1</th><th> header 2</th></tr>
865
+ </table>
866
+ HTML
867
+ tree = BlockParser.parse(text.lines.to_a.map {|line| line.chomp })
868
+ assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
869
+ end
870
+
871
+ def test_decorator_for_verbatim
872
+ text = <<TEXT
873
+ //@code[ruby]
874
+ def bonjour!
875
+ puts "Bonjour!"
876
+ end
877
+ TEXT
878
+
879
+ xhtml = <<HTML
880
+ <pre>
881
+ def bonjour!
882
+ puts &quot;Bonjour!&quot;
883
+ end
884
+ </pre>
885
+ HTML
886
+
887
+ tree = BlockParser.parse(text.lines.to_a)
888
+ assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
889
+ end
890
+
891
+ def test_sectioning_node
892
+ text = <<TEXT
893
+ ! Main title
894
+
895
+ //@begin[header]
896
+ !! first title in header
897
+
898
+ paragraph
899
+
900
+ !! second title in header
901
+
902
+ paragraph2
903
+
904
+ //@end[header]
905
+
906
+ !! first subtitle in main part
907
+
908
+ paragraph3
909
+
910
+ //@begin[#footer]
911
+
912
+ paragraph4
913
+
914
+ //@end[#footer]
915
+
916
+ TEXT
917
+
918
+ expected_html = <<HTML
919
+ <div class="section h1">
920
+ <h1> Main title
921
+ </h1>
922
+ <div class="header">
923
+ <div class="section h2">
924
+ <h2> first title in header
925
+ </h2>
926
+ <p>
927
+ paragraph
928
+ </p>
929
+ <!-- end of section h2 -->
930
+ </div>
931
+ <div class="section h2">
932
+ <h2> second title in header
933
+ </h2>
934
+ <p>
935
+ paragraph2
936
+ </p>
937
+ <!-- end of section h2 -->
938
+ </div>
939
+ <!-- end of header -->
940
+ </div>
941
+ <div class="section h2">
942
+ <h2> first subtitle in main part
943
+ </h2>
944
+ <p>
945
+ paragraph3
946
+ </p>
947
+ <div class="section" id="footer">
948
+ <p>
949
+ paragraph4
950
+ </p>
951
+ <!-- end of footer -->
952
+ </div>
953
+ <!-- end of section h2 -->
954
+ </div>
955
+ <!-- end of section h1 -->
956
+ </div>
957
+ HTML
958
+
959
+ tree = BlockParser.parse(text.lines.to_a)
960
+ assert_equal(expected_html, XhtmlFormat.format(tree).to_s)
961
+ end
962
+
963
+ def test_sectioning_node_for_html5
964
+ text = <<TEXT
965
+ ! Main title
966
+
967
+ //@begin[header]
968
+ !! first title in header
969
+
970
+ paragraph
971
+
972
+ !! second title in header
973
+
974
+ paragraph2
975
+
976
+ //@end[header]
977
+
978
+ !! first subtitle in main part
979
+
980
+ paragraph3
981
+
982
+ //@begin[#footer]
983
+
984
+ paragraph4
985
+
986
+ //@end[#footer]
987
+
988
+ TEXT
989
+
990
+ expected_html = <<HTML
991
+ <section class="h1">
992
+ <h1> Main title
993
+ </h1>
994
+ <header>
995
+ <section class="h2">
996
+ <h2> first title in header
997
+ </h2>
998
+ <p>
999
+ paragraph
1000
+ </p>
1001
+ <!-- end of h2 -->
1002
+ </section>
1003
+ <section class="h2">
1004
+ <h2> second title in header
1005
+ </h2>
1006
+ <p>
1007
+ paragraph2
1008
+ </p>
1009
+ <!-- end of h2 -->
1010
+ </section>
1011
+ </header>
1012
+ <section class="h2">
1013
+ <h2> first subtitle in main part
1014
+ </h2>
1015
+ <p>
1016
+ paragraph3
1017
+ </p>
1018
+ <section id="footer">
1019
+ <p>
1020
+ paragraph4
1021
+ </p>
1022
+ <!-- end of footer -->
1023
+ </section>
1024
+ <!-- end of h2 -->
1025
+ </section>
1026
+ <!-- end of h1 -->
1027
+ </section>
1028
+ HTML
1029
+
1030
+ tree = BlockParser.parse(text.lines.to_a)
1031
+ assert_equal(expected_html, Xhtml5Format.format(tree).to_s)
1032
+ end
1033
+
1034
+ def test_sectioning_node_when_end_tag_is_omitted
1035
+ text = <<TEXT
1036
+ !! First part
1037
+
1038
+ paragraph1
1039
+
1040
+ //@begin[first_sub_part]
1041
+ !!! first title in first sub-part
1042
+
1043
+ paragraph2
1044
+
1045
+ !!! second title in first sub-part
1046
+
1047
+ paragraph3
1048
+
1049
+ //you should put //@end[first_sub_part] here.
1050
+
1051
+ !! Second part
1052
+
1053
+ paragraph4
1054
+
1055
+ //@begin[#footer]
1056
+
1057
+ paragraph5
1058
+
1059
+ //@end[#footer]
1060
+
1061
+ TEXT
1062
+
1063
+ expected_html = <<HTML
1064
+ <div class=\"section h2\">
1065
+ <h2> First part
1066
+ </h2>
1067
+ <p>
1068
+ paragraph1
1069
+ </p>
1070
+ <div class=\"section first_sub_part\">
1071
+ <div class=\"section h3\">
1072
+ <h3> first title in first sub-part
1073
+ </h3>
1074
+ <p>
1075
+ paragraph2
1076
+ </p>
1077
+ <!-- end of section h3 -->
1078
+ </div>
1079
+ <div class=\"section h3\">
1080
+ <h3> second title in first sub-part
1081
+ </h3>
1082
+ <p>
1083
+ paragraph3
1084
+ </p>
1085
+ <!-- end of section h3 -->
1086
+ </div>
1087
+ <!-- end of section first_sub_part -->
1088
+ </div>
1089
+ <!-- end of section h2 -->
1090
+ </div>
1091
+ <div class=\"section h2\">
1092
+ <h2> Second part
1093
+ </h2>
1094
+ <p>
1095
+ paragraph4
1096
+ </p>
1097
+ <div class=\"section\" id=\"footer\">
1098
+ <p>
1099
+ paragraph5
1100
+ </p>
1101
+ <!-- end of footer -->
1102
+ </div>
1103
+ <!-- end of section h2 -->
1104
+ </div>
1105
+ HTML
1106
+
1107
+ tree = BlockParser.parse(text.lines.to_a)
1108
+ assert_equal(expected_html, XhtmlFormat.format(tree).to_s)
1109
+ end
1110
+
1111
+ def test_sectioning_node_when_end_tag_is_wrongly_placed
1112
+ text = <<TEXT
1113
+ !! First part
1114
+
1115
+ paragraph1
1116
+
1117
+ //@begin[first_sub_part]
1118
+ !!! first title in first sub-part
1119
+
1120
+ paragraph2
1121
+
1122
+ !!! second title in first sub-part
1123
+
1124
+ paragraph3
1125
+
1126
+ //you should put //@end[first_sub_part] here.
1127
+
1128
+ !! Second part
1129
+
1130
+ paragraph4
1131
+
1132
+
1133
+ //@end[first_sub_part] this end tag is wrongly placed.
1134
+
1135
+ //@begin[#footer]
1136
+
1137
+ paragraph5
1138
+
1139
+ //@end[#footer]
1140
+
1141
+ TEXT
1142
+
1143
+ expected_html = <<HTML
1144
+ <div class=\"section h2\">
1145
+ <h2> First part
1146
+ </h2>
1147
+ <p>
1148
+ paragraph1
1149
+ </p>
1150
+ <div class=\"section first_sub_part\">
1151
+ <div class=\"section h3\">
1152
+ <h3> first title in first sub-part
1153
+ </h3>
1154
+ <p>
1155
+ paragraph2
1156
+ </p>
1157
+ <!-- end of section h3 -->
1158
+ </div>
1159
+ <div class=\"section h3\">
1160
+ <h3> second title in first sub-part
1161
+ </h3>
1162
+ <p>
1163
+ paragraph3
1164
+ </p>
1165
+ <!-- end of section h3 -->
1166
+ </div>
1167
+ <!-- end of section first_sub_part -->
1168
+ </div>
1169
+ <!-- end of section h2 -->
1170
+ </div>
1171
+ <div class=\"section h2\">
1172
+ <h2> Second part
1173
+ </h2>
1174
+ <p>
1175
+ paragraph4
1176
+ </p>
1177
+ <div class=\"section\" id=\"footer\">
1178
+ <p>
1179
+ paragraph5
1180
+ </p>
1181
+ <!-- end of footer -->
1182
+ </div>
1183
+ <!-- end of section h2 -->
1184
+ </div>
1185
+ HTML
1186
+
1187
+ tree = BlockParser.parse(text.lines.to_a)
1188
+ assert_equal(expected_html, XhtmlFormat.format(tree).to_s)
1189
+ end
1190
+
778
1191
  def test_comment_out_followed_by_a_verbatim_block
779
1192
  text = <<TEXT
780
1193
  the first paragraph
@@ -187,4 +187,88 @@ HTML
187
187
  html.base = '/base/path'
188
188
  assert_equal(html_result, html.to_s)
189
189
  end
190
+
191
+ def test_embed_style
192
+ expected_html = <<HTML
193
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
194
+ "http://www.w3.org/TR/html4/loose.dtd">
195
+ <html lang="en">
196
+ <head>
197
+ <meta content="en" http-equiv="Content-Language">
198
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
199
+ <meta content="text/javascript" http-equiv="Content-Script-Type">
200
+ <title></title>
201
+ <link href="default.css" rel="stylesheet" type="text/css">
202
+ <style type="text/css">
203
+ <!--
204
+ p {
205
+ font-size: 120%;
206
+ }
207
+ -->
208
+ </style>
209
+ </head>
210
+ <body>
211
+ </body>
212
+ </html>
213
+ HTML
214
+
215
+ css = <<CSS
216
+ p {
217
+ font-size: 120%;
218
+ }
219
+ CSS
220
+
221
+ html = HtmlTemplate.new
222
+ html.embed_style(css)
223
+
224
+ assert_equal(expected_html, html.to_s)
225
+ end
226
+
227
+ def test_add_skip_link
228
+ html = HtmlTemplate.new
229
+ html.body.push html.create_element("p").push("content")
230
+ html.add_skip_link
231
+ assert_equal("a", html.body.children[0].children[0].tagname)
232
+ assert_equal("#contents", html.body.children[0].children[0]["href"])
233
+ html = HtmlTemplate.new
234
+ skip_link_container = html.create_element("div")
235
+ html.add_skip_link("contents", skip_link_container)
236
+ assert_equal("a", skip_link_container.children[0].tagname)
237
+ assert_equal("#contents", skip_link_container.children[0]["href"])
238
+ end
239
+
240
+ def test_xhtmltemplate_embed_style
241
+ expected_html = <<HTML
242
+ <?xml version=\"1.0\" encoding=\"UTF-8\"?>
243
+ <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
244
+ \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
245
+ <html lang=\"en\" xml:lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\">
246
+ <head>
247
+ <meta content=\"en\" http-equiv=\"Content-Language\" />
248
+ <meta content=\"text/html; charset=UTF-8\" http-equiv=\"Content-Type\" />
249
+ <meta content=\"text/javascript\" http-equiv=\"Content-Script-Type\" />
250
+ <title></title>
251
+ <link href=\"default.css\" rel=\"stylesheet\" type=\"text/css\" />
252
+ <style type=\"text/css\">
253
+ p {
254
+ font-size: 120%;
255
+ }
256
+ </style>
257
+ </head>
258
+ <body>
259
+ </body>
260
+ </html>
261
+ HTML
262
+
263
+ css = <<CSS
264
+ p {
265
+ font-size: 120%;
266
+ }
267
+ CSS
268
+
269
+ html = XhtmlTemplate.new
270
+ html.embed_style(css)
271
+
272
+ assert_equal(expected_html, html.to_s)
273
+ end
190
274
  end
@@ -10,19 +10,19 @@ class TC_InlineParser < MiniTest::Unit::TestCase
10
10
 
11
11
  def test_inlineparser_compile_token_pat
12
12
  parser = InlineParser.new("")
13
- assert_equal(/'''|\}\}|\|\||\{\{|``|\]\]|\[\[|==|''|\||:/, InlineParser::TokenPat[parser.class])
13
+ assert_equal(/'''|\}\}|\|\||\{\{|``|\]\]|\[\[|==|''|\||:/, parser.class.token_pat)
14
14
  end
15
15
 
16
16
  def test_inlineparser_split_into_tokens
17
17
  parser = InlineParser.new("")
18
18
  tokens = PseudoHiki.split_into_tokens("As a test case, '''this part''' must be in <strong>.",
19
- InlineParser::TokenPat[parser.class])
19
+ InlineParser.token_pat)
20
20
  assert_equal(["As a test case, ","'''","this part","'''"," must be in <strong>."],tokens)
21
21
  tokens = PseudoHiki.split_into_tokens("As another {{test case}}, '''this part''' must be in <strong>.",
22
- InlineParser::TokenPat[parser.class])
22
+ InlineParser.token_pat)
23
23
  assert_equal(["As another ","{{","test case","}}", ", ","'''","this part","'''"," must be in <strong>."],tokens)
24
24
  tokens = PseudoHiki.split_into_tokens("As another ''test case'', '''this part''' must be in <strong>.",
25
- InlineParser::TokenPat[parser.class])
25
+ InlineParser.token_pat)
26
26
  assert_equal(["As another ","''","test case","''", ", ","'''","this part","'''"," must be in <strong>."],tokens)
27
27
  end
28
28