review-peg 0.1.0

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.
Files changed (174) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +36 -0
  3. data/.rubocop.yml +47 -0
  4. data/.rubocop_todo.yml +605 -0
  5. data/.travis.yml +18 -0
  6. data/COPYING +515 -0
  7. data/ChangeLog +2449 -0
  8. data/Dockerfile +22 -0
  9. data/Gemfile +6 -0
  10. data/README.rdoc +81 -0
  11. data/Rakefile +51 -0
  12. data/bin/review-catalog-converter-peg +129 -0
  13. data/bin/review-check-peg +169 -0
  14. data/bin/review-checkdep-peg +63 -0
  15. data/bin/review-compile-peg +202 -0
  16. data/bin/review-epubmaker-legacy-peg +1024 -0
  17. data/bin/review-epubmaker-peg +44 -0
  18. data/bin/review-index-peg +110 -0
  19. data/bin/review-init-peg +151 -0
  20. data/bin/review-pdfmaker-peg +18 -0
  21. data/bin/review-preproc-peg +131 -0
  22. data/bin/review-validate-peg +51 -0
  23. data/bin/review-vol-peg +100 -0
  24. data/debian/README.Debian +12 -0
  25. data/debian/README.source +5 -0
  26. data/debian/changelog +5 -0
  27. data/debian/compat +1 -0
  28. data/debian/control +22 -0
  29. data/debian/copyright +62 -0
  30. data/debian/docs +6 -0
  31. data/debian/manpage.1.ex +59 -0
  32. data/debian/patches/path.diff +91 -0
  33. data/debian/patches/series +1 -0
  34. data/debian/review.install +13 -0
  35. data/debian/review.links +4 -0
  36. data/debian/rules +13 -0
  37. data/debian/source/format +1 -0
  38. data/doc/NEWS.ja.md +350 -0
  39. data/doc/NEWS.md +354 -0
  40. data/doc/catalog.ja.md +53 -0
  41. data/doc/catalog.md +52 -0
  42. data/doc/format.ja.md +734 -0
  43. data/doc/format.md +746 -0
  44. data/doc/format_idg.ja.md +203 -0
  45. data/doc/quickstart.ja.md +222 -0
  46. data/doc/quickstart.md +252 -0
  47. data/doc/ruby-uuid/README +11 -0
  48. data/doc/ruby-uuid/README.ja +34 -0
  49. data/doc/sample.css +108 -0
  50. data/doc/sample.yml +238 -0
  51. data/lib/epubmaker.rb +24 -0
  52. data/lib/epubmaker/content.rb +93 -0
  53. data/lib/epubmaker/epubcommon.rb +424 -0
  54. data/lib/epubmaker/epubv2.rb +139 -0
  55. data/lib/epubmaker/epubv3.rb +222 -0
  56. data/lib/epubmaker/producer.rb +330 -0
  57. data/lib/lineinput.rb +107 -0
  58. data/lib/review.rb +3 -0
  59. data/lib/review/book.rb +43 -0
  60. data/lib/review/book/base.rb +401 -0
  61. data/lib/review/book/chapter.rb +100 -0
  62. data/lib/review/book/compilable.rb +184 -0
  63. data/lib/review/book/image_finder.rb +71 -0
  64. data/lib/review/book/index.rb +413 -0
  65. data/lib/review/book/page_metric.rb +47 -0
  66. data/lib/review/book/part.rb +54 -0
  67. data/lib/review/book/volume.rb +67 -0
  68. data/lib/review/builder.rb +452 -0
  69. data/lib/review/catalog.rb +52 -0
  70. data/lib/review/compiler.rb +5183 -0
  71. data/lib/review/compiler/literals_1_9.kpeg +22 -0
  72. data/lib/review/compiler/literals_1_9.rb +435 -0
  73. data/lib/review/configure.rb +64 -0
  74. data/lib/review/epubbuilder.rb +18 -0
  75. data/lib/review/epubmaker.rb +480 -0
  76. data/lib/review/ewbbuilder.rb +381 -0
  77. data/lib/review/exception.rb +21 -0
  78. data/lib/review/extentions.rb +4 -0
  79. data/lib/review/extentions/array.rb +25 -0
  80. data/lib/review/extentions/object.rb +9 -0
  81. data/lib/review/extentions/string.rb +33 -0
  82. data/lib/review/htmlbuilder.rb +1166 -0
  83. data/lib/review/htmllayout.rb +41 -0
  84. data/lib/review/htmltoc.rb +45 -0
  85. data/lib/review/htmlutils.rb +90 -0
  86. data/lib/review/i18n.rb +96 -0
  87. data/lib/review/i18n.yml +169 -0
  88. data/lib/review/idgxmlbuilder.rb +1233 -0
  89. data/lib/review/inaobuilder.rb +357 -0
  90. data/lib/review/latexbuilder.rb +941 -0
  91. data/lib/review/latexindex.rb +35 -0
  92. data/lib/review/latexutils.rb +95 -0
  93. data/lib/review/layout.tex.erb +340 -0
  94. data/lib/review/lineinput.rb +17 -0
  95. data/lib/review/location.rb +24 -0
  96. data/lib/review/makerhelper.rb +67 -0
  97. data/lib/review/markdownbuilder.rb +339 -0
  98. data/lib/review/node.rb +288 -0
  99. data/lib/review/pdfmaker.rb +332 -0
  100. data/lib/review/preprocessor.rb +530 -0
  101. data/lib/review/review.kpeg +745 -0
  102. data/lib/review/sec_counter.rb +69 -0
  103. data/lib/review/template.rb +21 -0
  104. data/lib/review/textbuilder.rb +17 -0
  105. data/lib/review/textutils.rb +16 -0
  106. data/lib/review/tocparser.rb +348 -0
  107. data/lib/review/tocprinter.rb +205 -0
  108. data/lib/review/topbuilder.rb +796 -0
  109. data/lib/review/unfold.rb +138 -0
  110. data/lib/review/version.rb +3 -0
  111. data/lib/uuid.rb +312 -0
  112. data/review.gemspec +32 -0
  113. data/templates/html/layout-html5.html.erb +17 -0
  114. data/templates/html/layout-xhtml1.html.erb +20 -0
  115. data/templates/ncx/epubv2.ncx.erb +11 -0
  116. data/templates/opf/epubv2.opf.erb +21 -0
  117. data/templates/opf/epubv3.opf.erb +18 -0
  118. data/templates/xml/container.xml.erb +6 -0
  119. data/test/CHAPS +2 -0
  120. data/test/assets/test.xml.erb +3 -0
  121. data/test/assets/test_template.tex +255 -0
  122. data/test/assets/test_template_backmatter.tex +32 -0
  123. data/test/bib.re +13 -0
  124. data/test/book_test_helper.rb +35 -0
  125. data/test/sample-book/README.md +7 -0
  126. data/test/sample-book/src/Rakefile +58 -0
  127. data/test/sample-book/src/_cover.html +3 -0
  128. data/test/sample-book/src/catalog.yml +10 -0
  129. data/test/sample-book/src/ch01.re +71 -0
  130. data/test/sample-book/src/ch02.re +3 -0
  131. data/test/sample-book/src/config.yml +186 -0
  132. data/test/sample-book/src/images/ch01-imgsample.jpg +0 -0
  133. data/test/sample-book/src/images/cover.jpg +0 -0
  134. data/test/sample-book/src/preface.re +15 -0
  135. data/test/sample-book/src/sty/jumoline.sty +310 -0
  136. data/test/sample-book/src/sty/reviewmacro.sty +39 -0
  137. data/test/sample-book/src/style.css +251 -0
  138. data/test/sample-book/src/vendor/jumoline/README +29 -0
  139. data/test/sample-book/src/vendor/jumoline/jumoline.dtx +2988 -0
  140. data/test/sample-book/src/vendor/jumoline/jumoline.ins +6 -0
  141. data/test/test.re +43 -0
  142. data/test/test_book.rb +556 -0
  143. data/test/test_book_chapter.rb +280 -0
  144. data/test/test_book_part.rb +54 -0
  145. data/test/test_builder.rb +80 -0
  146. data/test/test_catalog.rb +119 -0
  147. data/test/test_catalog_converter_cmd.rb +73 -0
  148. data/test/test_compiler.rb +92 -0
  149. data/test/test_configure.rb +50 -0
  150. data/test/test_epub3maker.rb +529 -0
  151. data/test/test_epubmaker.rb +569 -0
  152. data/test/test_epubmaker_cmd.rb +40 -0
  153. data/test/test_helper.rb +92 -0
  154. data/test/test_htmlbuilder.rb +1114 -0
  155. data/test/test_htmltoc.rb +32 -0
  156. data/test/test_htmlutils.rb +50 -0
  157. data/test/test_i18n.rb +180 -0
  158. data/test/test_idgxmlbuilder.rb +608 -0
  159. data/test/test_image_finder.rb +82 -0
  160. data/test/test_inaobuilder.rb +245 -0
  161. data/test/test_index.rb +174 -0
  162. data/test/test_latexbuilder.rb +732 -0
  163. data/test/test_lineinput.rb +182 -0
  164. data/test/test_makerhelper.rb +66 -0
  165. data/test/test_markdownbuilder.rb +125 -0
  166. data/test/test_pdfmaker.rb +171 -0
  167. data/test/test_pdfmaker_cmd.rb +40 -0
  168. data/test/test_preprocessor.rb +23 -0
  169. data/test/test_review_ext.rb +31 -0
  170. data/test/test_template.rb +26 -0
  171. data/test/test_textutils.rb +32 -0
  172. data/test/test_topbuilder.rb +291 -0
  173. data/test/test_uuid.rb +157 -0
  174. metadata +357 -0
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test_helper'
4
+ require 'tmpdir'
5
+ require 'fileutils'
6
+ require 'yaml'
7
+ require 'rbconfig'
8
+
9
+ REVIEW_EPUBMAKER = File.expand_path('../bin/review-epubmaker-peg', File.dirname(__FILE__))
10
+
11
+ class EPUBMakerCmdTest < Test::Unit::TestCase
12
+ def setup
13
+ @tmpdir1 = Dir.mktmpdir
14
+ @tmpdir2 = Dir.mktmpdir
15
+
16
+ @old_rubylib = ENV['RUBYLIB']
17
+ ENV['RUBYLIB'] = File.expand_path('../lib', File.dirname(__FILE__))
18
+ end
19
+
20
+ def teardown
21
+ FileUtils.rm_rf @tmpdir1
22
+ FileUtils.rm_rf @tmpdir2
23
+ ENV['RUBYLIB'] = @old_rubylib
24
+ end
25
+
26
+ def test_epubmaker_cmd
27
+ if RUBY_VERSION !~ /^1.8/
28
+ config = prepare_samplebook(@tmpdir1)
29
+ builddir = @tmpdir1 + "/" + config['bookname'] + '-epub'
30
+ assert ! File.exist?(builddir)
31
+
32
+ ruby_cmd = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
33
+ Dir.chdir(@tmpdir1) do
34
+ system("#{ruby_cmd} -S #{REVIEW_EPUBMAKER} config.yml 1>/dev/null 2>/dev/null")
35
+ end
36
+
37
+ assert File.exist?(builddir)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,92 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib/')
2
+ require 'test/unit'
3
+
4
+ def compile_document(str, force_to_s=true)
5
+ @compiler.setup_parser(str)
6
+ @compiler.parse("Document")
7
+ if force_to_s
8
+ @compiler.result.to_doc
9
+ else
10
+ @compiler.result
11
+ end
12
+ end
13
+
14
+ def compile_block(str, force_to_s=true)
15
+ @compiler.setup_parser(str)
16
+ @compiler.parse("Document")
17
+ if force_to_s
18
+ @compiler.result.to_doc
19
+ else
20
+ @compiler.result
21
+ end
22
+ end
23
+
24
+ def compile_inline(str, force_to_s=true)
25
+ @compiler.setup_parser(str)
26
+ @compiler.parse("Paragraph")
27
+ if force_to_s
28
+ ## @compiler.result.map(&:to_doc).join
29
+ @compiler.result.to_doc
30
+ else
31
+ @compiler.result
32
+ end
33
+ end
34
+
35
+ def compile_blockelem(str, force_to_s=true)
36
+ @compiler.setup_parser(str)
37
+ @compiler.parse("BlockElement")
38
+ if force_to_s
39
+ @compiler.result.to_doc
40
+ else
41
+ @compiler.result
42
+ end
43
+ end
44
+
45
+ def compile_headline(str)
46
+ @compiler.setup_parser(str)
47
+ @compiler.parse("Headline")
48
+ @compiler.result.to_doc
49
+ end
50
+
51
+ def touch_file(path)
52
+ File.open(path, "w").close
53
+ path
54
+ end
55
+
56
+ def assets_dir
57
+ File.join(File.dirname(__FILE__), "assets")
58
+ end
59
+
60
+ def prepare_samplebook(srcdir)
61
+ samplebook_dir = File.expand_path("sample-book/src/", File.dirname(__FILE__))
62
+ FileUtils.cp_r(Dir.glob(samplebook_dir + "/*"), srcdir)
63
+ YAML.load(File.open(srcdir + "/config.yml"))
64
+ end
65
+
66
+ def compile_block(text)
67
+ method_name = "compile_block_#{@builder.target_name}"
68
+ if !self.respond_to?(method_name, true)
69
+ method_name = "compile_block_default"
70
+ end
71
+ self.__send__(method_name, text)
72
+ end
73
+
74
+ def compile_block_default(text)
75
+ @chapter.content = text
76
+ @compiler.compile(@chapter)
77
+ end
78
+
79
+ def compile_block_html(text)
80
+ @chapter.content = text
81
+ matched = @compiler.compile(@chapter).match(/<body>\n(.+)<\/body>/m)
82
+ if matched && matched.size > 1
83
+ matched[1]
84
+ else
85
+ ""
86
+ end
87
+ end
88
+
89
+ def compile_block_idgxml(text)
90
+ @chapter.content = text
91
+ @compiler.compile(@chapter).gsub(/.*<doc xmlns:aid="http:\/\/ns.adobe.com\/AdobeInDesign\/4.0\/">/m,"").gsub(/<\/doc>\n/, "")
92
+ end
@@ -0,0 +1,1114 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test_helper'
4
+ require 'review/compiler'
5
+ require 'review/book'
6
+ require 'review/htmlbuilder'
7
+ require 'review/i18n'
8
+
9
+ class HTMLBuidlerTest < Test::Unit::TestCase
10
+ include ReVIEW
11
+
12
+ def setup
13
+ ReVIEW::I18n.setup
14
+ @builder = HTMLBuilder.new()
15
+ @config = ReVIEW::Configure.values
16
+ @config.merge!({
17
+ "secnolevel" => 2, # for IDGXMLBuilder, HTMLBuilder
18
+ "stylesheet" => nil, # for HTMLBuilder
19
+ "htmlext" => "html",
20
+ })
21
+ @book = Book::Base.new(".")
22
+ @book.config = @config
23
+ @compiler = ReVIEW::Compiler.new(@builder)
24
+ @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
25
+ location = Location.new(nil, nil)
26
+ @builder.bind(@compiler, @chapter, location)
27
+ I18n.setup("ja")
28
+ end
29
+
30
+ def test_xmlns_ops_prefix_epub3
31
+ @book.config["epubversion"] = 3
32
+ assert_equal "epub", @builder.xmlns_ops_prefix
33
+ end
34
+
35
+ def test_xmlns_ops_prefix_epub2
36
+ assert_equal "ops", @builder.xmlns_ops_prefix
37
+ end
38
+
39
+ def test_headline_level1
40
+ actual = compile_block("={test} this is test.\n")
41
+ assert_equal %Q|<h1 id="test"><a id="h1"></a><span class="secno">第1章 </span>this is test.</h1>\n|, actual
42
+ end
43
+
44
+ def test_headline_level1_postdef
45
+ @chapter.instance_eval do
46
+ def on_APPENDIX?
47
+ true
48
+ end
49
+ end
50
+ actual = compile_block("={test} this is test.\n")
51
+ assert_equal %Q|<h1 id="test"><a id="h1"></a><span class="secno">付録1 </span>this is test.</h1>\n|, actual
52
+ end
53
+
54
+ def test_headline_level2_postdef
55
+ @chapter.instance_eval do
56
+ def on_APPENDIX?
57
+ true
58
+ end
59
+ end
60
+ actual = compile_block("=={test} this is test.\n")
61
+ assert_equal %Q|<h2 id="test"><a id="h1-1"></a><span class="secno">1.1 </span>this is test.</h2>\n|, actual
62
+ end
63
+
64
+ def test_headline_level1_postdef_roman
65
+ @chapter.book.config["appendix_format"] = "roman"
66
+ @chapter.instance_eval do
67
+ def on_APPENDIX?
68
+ true
69
+ end
70
+ end
71
+ actual = compile_block("={test} this is test.\n")
72
+ assert_equal %Q|<h1 id="test"><a id="hI"></a><span class="secno">付録I </span>this is test.</h1>\n|, actual
73
+ end
74
+
75
+ def test_headline_level2_postdef_roman
76
+ @chapter.book.config["appendix_format"] = "roman"
77
+ @chapter.instance_eval do
78
+ def on_APPENDIX?
79
+ true
80
+ end
81
+ end
82
+ actual = compile_block("=={test} this is test.\n")
83
+ assert_equal %Q|<h2 id="test"><a id="hI-1"></a><span class="secno">I.1 </span>this is test.</h2>\n|, actual
84
+ end
85
+
86
+ def test_headline_level1_postdef_alpha
87
+ @chapter.book.config["appendix_format"] = "alpha"
88
+ @chapter.instance_eval do
89
+ def on_APPENDIX?
90
+ true
91
+ end
92
+ end
93
+ actual = compile_block("={test} this is test.\n")
94
+ assert_equal %Q|<h1 id="test"><a id="hA"></a><span class="secno">付録A </span>this is test.</h1>\n|, actual
95
+ end
96
+
97
+ def test_headline_level2_postdef_alpha
98
+ @chapter.book.config["appendix_format"] = "alpha"
99
+ @chapter.instance_eval do
100
+ def on_APPENDIX?
101
+ true
102
+ end
103
+ end
104
+ actual = compile_block("=={test} this is test.\n")
105
+ assert_equal %Q|<h2 id="test"><a id="hA-1"></a><span class="secno">A.1 </span>this is test.</h2>\n|, actual
106
+ end
107
+
108
+ def test_headline_level1_without_secno
109
+ @book.config["secnolevel"] = 0
110
+ actual = compile_block("={test} this is test.\n")
111
+ assert_equal %Q|<h1 id="test"><a id="h1"></a>this is test.</h1>\n|, actual
112
+ end
113
+
114
+ def test_headline_level1_with_tricky_id
115
+ actual = compile_block("={123 あ_;} this is test.\n")
116
+ assert_equal %Q|<h1 id="id_123-_E3_81_82___3B"><a id="h1"></a><span class="secno">第1章 </span>this is test.</h1>\n|, actual
117
+ end
118
+
119
+ def test_headline_level1_with_inlinetag
120
+ actual = compile_block("={test} this @<b>{is} test.<&\">\n")
121
+ assert_equal %Q|<h1 id="test"><a id="h1"></a><span class="secno">第1章 </span>this <b>is</b> test.&lt;&amp;&quot;&gt;</h1>\n|, actual
122
+ end
123
+
124
+ def test_headline_level2
125
+ actual = compile_block("=={test} this is test.\n")
126
+ assert_equal %Q|<h2 id="test"><a id="h1-1"></a><span class="secno">1.1 </span>this is test.</h2>\n|, actual
127
+ end
128
+
129
+ def test_headline_level3
130
+ actual = compile_block("==={test} this is test.\n")
131
+ assert_equal %Q|<h3 id="test"><a id="h1-0-1"></a>this is test.</h3>\n|, actual
132
+ end
133
+
134
+ def test_headline_level3_with_secno
135
+ @book.config["secnolevel"] = 3
136
+ actual = compile_block("==={test} this is test.\n")
137
+ assert_equal %Q|<h3 id="test"><a id="h1-0-1"></a><span class="secno">1.0.1 </span>this is test.</h3>\n|, actual
138
+ end
139
+
140
+ def test_label
141
+ actual = compile_block("//label[label_test]\n")
142
+ assert_equal %Q|<a id="label_test"></a>\n|, actual
143
+ end
144
+
145
+ def test_label_with_tricky_id
146
+ actual = compile_block("//label[123 あ_;]\n")
147
+ assert_equal %Q|<a id="id_123-_E3_81_82___3B"></a>\n|, actual
148
+ end
149
+
150
+ def test_href
151
+ actual = compile_inline("@<href>{http://github.com,GitHub}")
152
+ assert_equal %Q|<a href="http://github.com" class="link">GitHub</a>|, actual
153
+ end
154
+
155
+ def test_href_without_label
156
+ actual = compile_inline("@<href>{http://github.com}")
157
+ assert_equal %Q|<a href="http://github.com" class="link">http://github.com</a>|, actual
158
+ end
159
+
160
+ def test_inline_href
161
+ actual = compile_inline("@<href>{http://github.com,Git\\,Hub}")
162
+ assert_equal %Q|<a href="http://github.com" class="link">Git,Hub</a>|, actual
163
+ end
164
+
165
+ def test_inline_raw
166
+ actual = compile_inline("@<raw>{@<tt>{inline\\}}")
167
+ assert_equal %Q|@<tt>{inline}|, actual
168
+ end
169
+
170
+ def test_inline_in_table
171
+ actual = compile_block("//table{\n@<b>{1}\t@<i>{2}\n------------\n@<b>{3}\t@<i>{4}<>&\n//}\n")
172
+ assert_equal %Q|<div class="table">\n<table>\n<tr><th><b>1</b></th><th><i>2</i></th></tr>\n<tr><td><b>3</b></td><td><i>4</i>&lt;&gt;&amp;</td></tr>\n</table>\n</div>\n|, actual
173
+ end
174
+
175
+ def test_inline_br
176
+ actual = compile_inline("@<br>{}")
177
+ assert_equal %Q|<br />|, actual
178
+ end
179
+
180
+ def test_inline_i
181
+ actual = compile_inline("test @<i>{inline test} test2")
182
+ assert_equal %Q|test <i>inline test</i> test2|, actual
183
+ end
184
+
185
+ def test_inline_i_and_escape
186
+ actual = compile_inline("test @<i>{inline<&;\\ test} test2")
187
+ assert_equal %Q|test <i>inline&lt;&amp;;\\ test</i> test2|, actual
188
+ end
189
+
190
+ def test_inline_b
191
+ actual = compile_inline("test @<b>{inline test} test2")
192
+ assert_equal %Q|test <b>inline test</b> test2|, actual
193
+ end
194
+
195
+ def test_inline_b_and_escape
196
+ actual = compile_inline("test @<b>{inline<&;\\ test} test2")
197
+ assert_equal %Q|test <b>inline&lt;&amp;;\\ test</b> test2|, actual
198
+ end
199
+
200
+ def test_inline_tt
201
+ actual = compile_inline("test @<tt>{inline test} test2")
202
+ assert_equal %Q|test <tt>inline test</tt> test2|, actual
203
+ end
204
+
205
+ def test_inline_tti
206
+ actual = compile_inline("test @<tti>{inline test} test2")
207
+ assert_equal %Q|test <tt><i>inline test</i></tt> test2|, actual
208
+ end
209
+
210
+ def test_inline_ttb
211
+ actual = compile_inline("test @<ttb>{inline test} test2")
212
+ assert_equal %Q|test <tt><b>inline test</b></tt> test2|, actual
213
+ end
214
+
215
+ def test_inline_hd_chap
216
+ def @chapter.headline_index
217
+ items = [Book::HeadlineIndex::Item.new("chap1|test", [1, 1], "te_st")]
218
+ Book::HeadlineIndex.new(items, self)
219
+ end
220
+
221
+ @config["secnolevel"] = 2
222
+ actual = compile_inline("test @<hd>{chap1|test} test2")
223
+ assert_equal %Q|test 「te_st」 test2|, actual
224
+
225
+ @config["secnolevel"] = 3
226
+ actual = compile_inline("test @<hd>{chap1|test} test2")
227
+ assert_equal %Q|test 「1.1.1 te_st」 test2|, actual
228
+ end
229
+
230
+ def test_inline_hd_chap_postdef_roman
231
+ @chapter.book.config["appendix_format"] = "roman"
232
+ @chapter.instance_eval do
233
+ def on_APPENDIX?
234
+ true
235
+ end
236
+ end
237
+ def @chapter.headline_index
238
+ items = [Book::HeadlineIndex::Item.new("test", [1], "te_st")]
239
+ Book::HeadlineIndex.new(items, self)
240
+ end
241
+
242
+ actual = compile_inline("test @<hd>{test} test2")
243
+ assert_equal %Q|test 「I.1 te_st」 test2|, actual
244
+ end
245
+
246
+ def test_inline_hd_chap_postdef_alpha
247
+ @chapter.book.config["appendix_format"] = "alpha"
248
+ @chapter.instance_eval do
249
+ def on_APPENDIX?
250
+ true
251
+ end
252
+ end
253
+ def @chapter.headline_index
254
+ items = [Book::HeadlineIndex::Item.new("test", [1], "te_st")]
255
+ Book::HeadlineIndex.new(items, self)
256
+ end
257
+
258
+ actual = compile_inline("test @<hd>{test} test2")
259
+ assert_equal %Q|test 「A.1 te_st」 test2|, actual
260
+ end
261
+
262
+ def test_inline_uchar
263
+ actual = compile_inline("test @<uchar>{2460} test2")
264
+ assert_equal %Q|test &#x2460; test2|, actual
265
+ end
266
+
267
+ def test_inline_ruby
268
+ actual = compile_inline("@<ruby>{粗雑,クルード}と思われているなら@<ruby>{繊細,テクニカル}にやり、繊細と思われているなら粗雑にやる。")
269
+ assert_equal "<ruby><rb>粗雑</rb><rp>(</rp><rt>クルード</rt><rp>)</rp></ruby>と思われているなら<ruby><rb>繊細</rb><rp>(</rp><rt>テクニカル</rt><rp>)</rp></ruby>にやり、繊細と思われているなら粗雑にやる。", actual
270
+ end
271
+
272
+ def test_inline_ruby_comma
273
+ actual = compile_inline("@<ruby>{foo\\, bar\\, buz,フー・バー・バズ}")
274
+ assert_equal "<ruby><rb>foo, bar, buz</rb><rp>(</rp><rt>フー・バー・バズ</rt><rp>)</rp></ruby>", actual
275
+ end
276
+
277
+ def test_inline_ref
278
+ actual = compile_inline("@<ref>{外部参照<>&}")
279
+ assert_equal %Q|<a target='外部参照&lt;&gt;&amp;'>「●● 外部参照&lt;&gt;&amp;」</a>|, actual
280
+ end
281
+
282
+ def test_inline_mathml
283
+ begin
284
+ require 'math_ml'
285
+ require "math_ml/symbol/character_reference"
286
+ rescue LoadError
287
+ return true
288
+ end
289
+ @config["mathml"] = true
290
+ actual = compile_inline("@<m>{\\frac{-b \\pm \\sqrt{b^2 - 4ac\\}\\}{2a\\}}")
291
+ @config["mathml"] = nil
292
+ assert_equal "<span class=\"equation\"><math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><mfrac><mrow><mo stretchy='false'>-</mo><mi>b</mi><mo stretchy='false'>&#xb1;</mo><msqrt><mrow><msup><mi>b</mi><mn>2</mn></msup><mo stretchy='false'>-</mo><mn>4</mn><mi>a</mi><mi>c</mi></mrow></msqrt></mrow><mrow><mn>2</mn><mi>a</mi></mrow></mfrac></math></span>", actual
293
+ end
294
+
295
+ def test_inline_imgref
296
+ def @chapter.image(id)
297
+ item = Book::ImageIndex::Item.new("sampleimg", 1, 'sample photo')
298
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
299
+ item
300
+ end
301
+
302
+ actual = compile_block "@<imgref>{sampleimg}\n"
303
+ expected = "<p>図1.1「sample photo」</p>\n"
304
+ assert_equal expected, actual
305
+ end
306
+
307
+ def test_inline_imgref2
308
+ def @chapter.image(id)
309
+ item = Book::NumberlessImageIndex::Item.new("sampleimg", 1)
310
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
311
+ item
312
+ end
313
+
314
+ actual = compile_block "@<imgref>{sampleimg}\n"
315
+ expected = "<p>図1.1</p>\n"
316
+ assert_equal expected, actual
317
+ end
318
+
319
+
320
+ def test_quote
321
+ actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n")
322
+ assert_equal %Q|<blockquote><p>foobar</p>\n<p>buz</p>\n</blockquote>\n|, actual
323
+ end
324
+
325
+ def test_memo
326
+ actual = compile_block("//memo[this is @<b>{test}<&>_]{\ntest1\n\ntest@<i>{2}\n//}\n")
327
+ assert_equal %Q|<div class="memo">\n<p class="caption">this is <b>test</b>&lt;&amp;&gt;_</p>\n<p>test1</p>\n<p>test<i>2</i></p>\n</div>\n|, actual
328
+ end
329
+
330
+ def test_noindent
331
+ @builder.noindent
332
+ actual = compile_block("foo\nbar\n\nfoo2\nbar2\n")
333
+ assert_equal %Q|<p class="noindent">foobar</p>\n<p>foo2bar2</p>\n|, actual
334
+ end
335
+
336
+ def test_flushright
337
+ actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n")
338
+ assert_equal %Q|<p class="flushright">foobar</p>\n<p class="flushright">buz</p>\n|, actual
339
+ end
340
+
341
+ def test_centering
342
+ actual = compile_block("//centering{\nfoo\nbar\n\nbuz\n//}\n")
343
+ assert_equal %Q|<p class="center">foobar</p>\n<p class="center">buz</p>\n|, actual
344
+ end
345
+
346
+ def test_image
347
+ def @chapter.image(id)
348
+ item = Book::ImageIndex::Item.new("sampleimg",1)
349
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
350
+ item
351
+ end
352
+
353
+ actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
354
+ assert_equal %Q|<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" />\n<p class="caption">\n図1.1: sample photo\n</p>\n</div>\n|, actual
355
+ end
356
+
357
+ def test_image_with_metric
358
+ def @chapter.image(id)
359
+ item = Book::ImageIndex::Item.new("sampleimg",1)
360
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
361
+ item
362
+ end
363
+
364
+ actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
365
+ assert_equal %Q|<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" width="120%" />\n<p class="caption">\n図1.1: sample photo\n</p>\n</div>\n|, actual
366
+ end
367
+
368
+ def test_image_with_metric2
369
+ def @chapter.image(id)
370
+ item = Book::ImageIndex::Item.new("sampleimg",1)
371
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
372
+ item
373
+ end
374
+
375
+ actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
376
+ assert_equal %Q|<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" width="120%" class="sample" />\n<p class="caption">\n図1.1: sample photo\n</p>\n</div>\n|, actual
377
+ end
378
+
379
+ def test_image_with_tricky_id
380
+ def @chapter.image(id)
381
+ item = Book::ImageIndex::Item.new("123 あ_;",1)
382
+ item.instance_eval{@path="./images/chap1-123 あ_;.png"}
383
+ item
384
+ end
385
+
386
+ actual = compile_block("//image[123 あ_;][sample photo]{\n//}\n")
387
+ assert_equal %Q|<div id="id_123-_E3_81_82___3B" class="image">\n<img src="images/chap1-123 あ_;.png" alt="sample photo" />\n<p class="caption">\n図1.1: sample photo\n</p>\n</div>\n|, actual
388
+ end
389
+
390
+ def test_indepimage
391
+ def @chapter.image(id)
392
+ item = Book::ImageIndex::Item.new("sampleimg",1)
393
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
394
+ item
395
+ end
396
+
397
+ actual = compile_block("//indepimage[sampleimg][sample photo]\n")
398
+ assert_equal %Q|<div class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" />\n<p class="caption">\n図: sample photo\n</p>\n</div>\n|, actual
399
+ end
400
+
401
+ def test_indepimage_without_caption
402
+ def @chapter.image(id)
403
+ item = Book::ImageIndex::Item.new("sampleimg",1)
404
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
405
+ item
406
+ end
407
+
408
+ actual = compile_block("//indepimage[sampleimg]\n")
409
+ assert_equal %Q|<div class="image">\n<img src="images/chap1-sampleimg.png" alt="" />\n</div>\n|, actual
410
+ end
411
+
412
+ def test_indepimage_with_metric
413
+ def @chapter.image(id)
414
+ item = Book::ImageIndex::Item.new("sampleimg",1)
415
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
416
+ item
417
+ end
418
+
419
+ actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
420
+ assert_equal %Q|<div class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" width="120%" />\n<p class="caption">\n図: sample photo\n</p>\n</div>\n|, actual
421
+ end
422
+
423
+ def test_indepimage_with_metric2
424
+ def @chapter.image(id)
425
+ item = Book::ImageIndex::Item.new("sampleimg",1)
426
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
427
+ item
428
+ end
429
+
430
+ actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2, html::class=\"sample\",latex::ignore=params]\n")
431
+ assert_equal %Q|<div class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" width="120%" class="sample" />\n<p class="caption">\n図: sample photo\n</p>\n</div>\n|, actual
432
+ end
433
+
434
+ def test_indepimage_without_caption_but_with_metric
435
+ def @chapter.image(id)
436
+ item = Book::ImageIndex::Item.new("sampleimg",1)
437
+ item.instance_eval{@path="./images/chap1-sampleimg.png"}
438
+ item
439
+ end
440
+
441
+ actual = compile_block("//indepimage[sampleimg][][scale=1.2]\n")
442
+ assert_equal %Q|<div class="image">\n<img src="images/chap1-sampleimg.png" alt="" width="120%" />\n</div>\n|, actual
443
+ end
444
+
445
+ def test_dlist
446
+ actual = compile_block(": foo\n foo.\n bar.\n")
447
+ assert_equal %Q|<dl>\n<dt>foo</dt>\n<dd>foo.bar.</dd>\n</dl>\n|, actual
448
+ end
449
+
450
+ def test_dlist_with_bracket
451
+ actual = compile_block(": foo[bar]\n foo.\n bar.\n")
452
+ assert_equal %Q|<dl>\n<dt>foo[bar]</dt>\n<dd>foo.bar.</dd>\n</dl>\n|, actual
453
+ end
454
+
455
+ def test_dlist_with_comment
456
+ source = ": title\n body\n\#@ comment\n\#@ comment\n: title2\n body2\n"
457
+ actual = compile_block(source)
458
+ assert_equal %Q|<dl>\n<dt>title</dt>\n<dd>body</dd>\n<dt>title2</dt>\n<dd>body2</dd>\n</dl>\n|, actual
459
+ end
460
+
461
+ def test_list
462
+ def @chapter.list(id)
463
+ Book::ListIndex::Item.new("samplelist",1)
464
+ end
465
+ actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
466
+ assert_equal %Q|<div class="caption-code">\n<p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>\n<pre class="list">test1\ntest1.5\n\ntest<i>2</i>\n</pre>\n</div>\n|, actual
467
+ end
468
+
469
+ def test_list_pygments
470
+ def @chapter.list(id)
471
+ Book::ListIndex::Item.new("samplelist",1)
472
+ end
473
+ begin
474
+ require 'pygments'
475
+ rescue LoadError
476
+ $stderr.puts "skip test_list_pygments_lang (cannot find pygments.rb)"
477
+ return true
478
+ end
479
+ @book.config["pygments"] = true
480
+ actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
481
+
482
+ assert_equal %Q|<div class="caption-code">\n<p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>\n<pre class="list">test1\ntest1.5\n\ntest&lt;i&gt;2&lt;/i&gt;</pre>\n</div>\n|, actual
483
+ end
484
+
485
+ def test_list_pygments_lang
486
+ def @chapter.list(id)
487
+ Book::ListIndex::Item.new("samplelist",1)
488
+ end
489
+ begin
490
+ require 'pygments'
491
+ rescue LoadError
492
+ $stderr.puts "skip test_list_pygments_lang (cannot find pygments.rb)"
493
+ return true
494
+ end
495
+ @book.config["pygments"] = true
496
+ actual = compile_block("//list[samplelist][this is @<b>{test}<&>_][ruby]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n")
497
+
498
+ assert_equal %Q|<div class=\"caption-code\">\n<p class=\"caption\">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>\n| +
499
+ %Q|<pre class=\"list\"><span style=\"color: #008000; font-weight: bold\">def</span> <span style=\"color: #0000FF\">foo</span>(a1, a2<span style=\"color: #666666\">=</span><span style=\"color: #19177C\">:test</span>)\n| +
500
+ %Q| (<span style=\"color: #666666\">1.</span>.<span style=\"color: #666666\">3</span>)<span style=\"color: #666666\">.</span>times{<span style=\"color: #666666\">\|</span>i<span style=\"color: #666666\">\|</span> a<span style=\"color: #666666\">.</span>include?(<span style=\"color: #19177C\">:foo</span>)}\n| +
501
+ %Q| <span style=\"color: #008000; font-weight: bold\">return</span> <span style=\"color: #008000\">true</span>\n| +
502
+ %Q|<span style=\"color: #008000; font-weight: bold\">end</span>| +
503
+ %Q|</pre>\n| +
504
+ %Q|</div>\n|, actual
505
+ end
506
+
507
+ def test_list_pygments_nulllang
508
+ def @chapter.list(id)
509
+ Book::ListIndex::Item.new("samplelist",1)
510
+ end
511
+ begin
512
+ require 'pygments'
513
+ rescue LoadError
514
+ $stderr.puts "skip test_list_pygments_nulllang (cannot find pygments.rb)"
515
+ return true
516
+ end
517
+ @book.config["pygments"] = true
518
+ actual = compile_block("//list[samplelist][this is @<b>{test}<&>_][]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n")
519
+
520
+ assert_equal "<div class=\"caption-code\">\n<p class=\"caption\">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>\n<pre class=\"list\">def foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend</pre>\n</div>\n", actual
521
+ end
522
+
523
+ def test_listnum
524
+ def @chapter.list(id)
525
+ Book::ListIndex::Item.new("samplelist",1)
526
+ end
527
+
528
+ @book.config["highlight"] = false
529
+ actual = compile_block(<<-EOS)
530
+ //listnum[samplelist][this is @<b>{test}<&>_][ruby]{
531
+ def foo(a1, a2=:test)
532
+ (1..3).times{|i| a.include?(:foo)}
533
+ return true
534
+ end
535
+ //}
536
+ EOS
537
+
538
+ expected =<<-EOS
539
+ <div class="code">
540
+ <p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>
541
+ <pre class="list"> 1: def foo(a1, a2=:test)
542
+ 2: (1..3).times{|i| a.include?(:foo)}
543
+ 3: return true
544
+ 4: end
545
+ </pre>
546
+ </div>
547
+ EOS
548
+
549
+ assert_equal expected.chomp, actual
550
+ end
551
+
552
+ def test_listnum_pygments_lang
553
+ def @chapter.list(id)
554
+ Book::ListIndex::Item.new("samplelist",1)
555
+ end
556
+ begin
557
+ require 'pygments'
558
+ rescue LoadError
559
+ $stderr.puts "skip test_listnum_pygments_lang (cannot find pygments.rb)"
560
+ return true
561
+ end
562
+ @book.config["pygments"] = true
563
+ actual = compile_block("//listnum[samplelist][this is @<b>{test}<&>_][ruby]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n")
564
+
565
+ assert_equal "<div class=\"code\">\n<p class=\"caption\">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>\n<div class=\"highlight\" style=\"background: #f8f8f8\"><pre style=\"line-height: 125%\"><span style=\"background-color: #f0f0f0; padding: 0 5px 0 5px\">1</span> <span style=\"color: #008000; font-weight: bold\">def</span> <span style=\"color: #0000FF\">foo</span>(a1, a2<span style=\"color: #666666\">=</span><span style=\"color: #19177C\">:test</span>)\n<span style=\"background-color: #f0f0f0; padding: 0 5px 0 5px\">2</span> (<span style=\"color: #666666\">1.</span>.<span style=\"color: #666666\">3</span>)<span style=\"color: #666666\">.</span>times{<span style=\"color: #666666\">|</span>i<span style=\"color: #666666\">|</span> a<span style=\"color: #666666\">.</span>include?(<span style=\"color: #19177C\">:foo</span>)}\n<span style=\"background-color: #f0f0f0; padding: 0 5px 0 5px\">3</span> <span style=\"color: #008000; font-weight: bold\">return</span> <span style=\"color: #008000\">true</span>\n<span style=\"background-color: #f0f0f0; padding: 0 5px 0 5px\">4</span> <span style=\"color: #008000; font-weight: bold\">end</span>\n</pre></div></div>", actual
566
+ end
567
+
568
+ def test_listnum_pygments_lang_without_lang
569
+ def @chapter.list(id)
570
+ Book::ListIndex::Item.new("samplelist",1)
571
+ end
572
+ begin
573
+ require 'pygments'
574
+ rescue LoadError
575
+ $stderr.puts "skip test_listnum_pygments_lang (cannot find pygments.rb)"
576
+ return true
577
+ end
578
+ @book.config["highlight"] = {}
579
+ @book.config["highlight"]["html"] = "pygments"
580
+ @book.config["highlight"]["lang"] = "ruby"
581
+ actual = compile_block("//listnum[samplelist][this is @<b>{test}<&>_]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n")
582
+
583
+ assert_equal "<div class=\"code\">\n<p class=\"caption\">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>\n<div class=\"highlight\" style=\"background: #f8f8f8\"><pre style=\"line-height: 125%\"><span style=\"background-color: #f0f0f0; padding: 0 5px 0 5px\">1</span> <span style=\"color: #008000; font-weight: bold\">def</span> <span style=\"color: #0000FF\">foo</span>(a1, a2<span style=\"color: #666666\">=</span><span style=\"color: #19177C\">:test</span>)\n<span style=\"background-color: #f0f0f0; padding: 0 5px 0 5px\">2</span> (<span style=\"color: #666666\">1.</span>.<span style=\"color: #666666\">3</span>)<span style=\"color: #666666\">.</span>times{<span style=\"color: #666666\">|</span>i<span style=\"color: #666666\">|</span> a<span style=\"color: #666666\">.</span>include?(<span style=\"color: #19177C\">:foo</span>)}\n<span style=\"background-color: #f0f0f0; padding: 0 5px 0 5px\">3</span> <span style=\"color: #008000; font-weight: bold\">return</span> <span style=\"color: #008000\">true</span>\n<span style=\"background-color: #f0f0f0; padding: 0 5px 0 5px\">4</span> <span style=\"color: #008000; font-weight: bold\">end</span>\n</pre></div></div>", actual
584
+ end
585
+
586
+
587
+ def test_emlist
588
+ actual = compile_block("//emlist{\nlineA\nlineB\n//}\n")
589
+ assert_equal %Q|<div class="emlist-code">\n<pre class="emlist">lineA\nlineB\n</pre>\n</div>\n|, actual
590
+ end
591
+
592
+ def test_emlist_pygments_lang
593
+ begin
594
+ require 'pygments'
595
+ rescue LoadError
596
+ $stderr.puts "skip test_emlist_pygments_lang (cannot find pygments.rb)"
597
+ return true
598
+ end
599
+ @book.config["pygments"] = true
600
+ actual = compile_block("//emlist[][sql]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
601
+ assert_equal "<div class=\"emlist-code\">\n<pre class=\"emlist\"><span style=\"color: #008000; font-weight: bold\">SELECT</span> <span style=\"color: #008000; font-weight: bold\">COUNT</span>(<span style=\"color: #666666\">*</span>) <span style=\"color: #008000; font-weight: bold\">FROM</span> tests <span style=\"color: #008000; font-weight: bold\">WHERE</span> tests.<span style=\"color: #008000; font-weight: bold\">no</span> <span style=\"color: #666666\">&gt;</span> <span style=\"color: #666666\">10</span> <span style=\"color: #008000; font-weight: bold\">AND</span> test.name <span style=\"color: #008000; font-weight: bold\">LIKE</span> <span style=\"color: #BA2121\">&#39;ABC%&#39;</span></pre>\n</div>\n", actual
602
+ end
603
+
604
+ def test_emlist_caption
605
+ actual = compile_block("//emlist[cap1]{\nlineA\nlineB\n//}\n")
606
+ assert_equal %Q|<div class="emlist-code">\n<p class="caption">cap1</p>\n<pre class="emlist">lineA\nlineB\n</pre>\n</div>\n|, actual
607
+ end
608
+
609
+ def test_emlist_with_tab
610
+ actual = compile_block("//emlist{\n\tlineA\n\t\tlineB\n\tlineC\n//}\n")
611
+ assert_equal %Q|<div class="emlist-code">\n<pre class="emlist"> lineA\n lineB\n lineC\n</pre>\n</div>\n|, actual
612
+ end
613
+
614
+ def test_emlistnum
615
+ @book.config["highlight"] = false
616
+ actual = compile_block("//emlistnum{\nlineA\nlineB\n//}\n")
617
+ expected =<<-EOS
618
+ <div class="emlistnum-code">
619
+ <pre class="emlist"> 1: lineA
620
+ 2: lineB
621
+ </pre>
622
+ </div>
623
+ EOS
624
+ assert_equal expected, actual
625
+ end
626
+
627
+ def test_emlist_with_4tab
628
+ @config["tabwidth"] = 4
629
+ actual = compile_block("//emlist{\n\tlineA\n\t\tlineB\n\tlineC\n//}\n")
630
+ assert_equal %Q|<div class="emlist-code">\n<pre class="emlist"> lineA\n lineB\n lineC\n</pre>\n</div>\n|, actual
631
+ end
632
+
633
+ def test_cmd
634
+ actual = compile_block("//cmd{\nlineA\nlineB\n//}\n")
635
+ assert_equal %Q|<div class="cmd-code">\n<pre class="cmd">lineA\nlineB\n</pre>\n</div>\n|, actual
636
+ end
637
+
638
+ def test_cmd_pygments
639
+ begin
640
+ require 'pygments'
641
+ rescue LoadError
642
+ return true
643
+ end
644
+ @book.config["pygments"] = true
645
+ actual = compile_block("//cmd{\nlineA\nlineB\n//}\n")
646
+ assert_equal "<div class=\"cmd-code\">\n<pre class=\"cmd\"><span style=\"color: #888888\">lineA</span>\n<span style=\"color: #888888\">lineB</span></pre>\n</div>\n", actual
647
+ end
648
+
649
+ def test_cmd_caption
650
+ actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n")
651
+ assert_equal %Q|<div class="cmd-code">\n<p class="caption">cap1</p>\n<pre class="cmd">lineA\nlineB\n</pre>\n</div>\n|, actual
652
+ end
653
+
654
+ def test_bib
655
+ def @chapter.bibpaper(id)
656
+ Book::BibpaperIndex::Item.new("samplebib",1,"sample bib")
657
+ end
658
+
659
+ assert_equal %Q|<a href="bib.html#bib-samplebib">[1]</a>|, compile_inline("@<bib>{samplebib}")
660
+ end
661
+
662
+ def test_bib_noramlized
663
+ def @chapter.bibpaper(id)
664
+ Book::BibpaperIndex::Item.new("sampleb=ib",1,"sample bib")
665
+ end
666
+
667
+ assert_equal %Q|<a href="bib.html#bib-id_sample_3Dbib">[1]</a>|, compile_inline("@<bib>{sample=bib}")
668
+ end
669
+
670
+ def test_bib_htmlext
671
+ def @chapter.bibpaper(id)
672
+ Book::BibpaperIndex::Item.new("samplebib",1,"sample bib")
673
+ end
674
+
675
+ @config["htmlext"] = "xhtml"
676
+ assert_equal %Q|<a href="bib.xhtml#bib-samplebib">[1]</a>|, compile_inline("@<bib>{samplebib}")
677
+ end
678
+
679
+ def test_bibpaper
680
+ def @chapter.bibpaper(id)
681
+ Book::BibpaperIndex::Item.new("samplebib",1,"sample bib")
682
+ end
683
+
684
+ actual = compile_block("//bibpaper[samplebib][sample bib @<b>{bold}]{\na\nb\n//}\n")
685
+ assert_equal %Q|<div class=\"bibpaper\">\n<a id=\"bib-samplebib\">[1]</a> sample bib <b>bold</b>\n<p>ab</p>\n</div>\n|, actual
686
+ end
687
+
688
+ def test_bibpaper_normalized
689
+ def @chapter.bibpaper(id)
690
+ Book::BibpaperIndex::Item.new("sample=bib",1,"sample bib")
691
+ end
692
+
693
+ actual = compile_block("//bibpaper[sample=bib][sample bib @<b>{bold}]{\na\nb\n//}\n")
694
+ assert_equal %Q|<div class=\"bibpaper\">\n<a id=\"bib-id_sample_3Dbib\">[1]</a> sample bib <b>bold</b>\n<p>ab</p>\n</div>\n|, actual
695
+ end
696
+
697
+ def test_bibpaper_with_anchor
698
+ def @chapter.bibpaper(id)
699
+ Book::BibpaperIndex::Item.new("samplebib",1,"sample bib")
700
+ end
701
+
702
+ actual = compile_block("//bibpaper[samplebib][sample bib @<href>{http://example.jp}]{\na\nb\n//}\n")
703
+ assert_equal %Q|<div class=\"bibpaper\">\n<a id=\"bib-samplebib\">[1]</a> sample bib <a href=\"http://example.jp\" class=\"link\">http://example.jp</a>\n<p>ab</p>\n</div>\n|, actual
704
+ end
705
+
706
+ def column_helper(review)
707
+ compile_block(review)
708
+ end
709
+
710
+ def test_column_1
711
+ review =<<-EOS
712
+ ===[column] prev column
713
+
714
+ inside prev column
715
+
716
+ ===[column] test
717
+
718
+ inside column
719
+
720
+ ===[/column]
721
+ EOS
722
+ expected =<<-EOS
723
+ <div class="column">
724
+
725
+ <h3><a id="column-1"></a>prev column</h3>
726
+ <p>inside prev column</p>
727
+ </div>
728
+ <div class="column">
729
+
730
+ <h3><a id="column-2"></a>test</h3>
731
+ <p>inside column</p>
732
+ </div>
733
+ EOS
734
+ assert_equal expected, column_helper(review)
735
+ end
736
+
737
+ def test_column_2
738
+ review =<<-EOS
739
+ ===[column] test
740
+
741
+ inside column
742
+
743
+ === next level
744
+ EOS
745
+ expected =<<-EOS
746
+ <div class="column">
747
+
748
+ <h3><a id="column-1"></a>test</h3>
749
+ <p>inside column</p>
750
+ </div>
751
+ <h3><a id="h1-0-1"></a>next level</h3>
752
+ EOS
753
+
754
+ assert_equal expected, column_helper(review)
755
+ end
756
+
757
+ def test_column_3
758
+ review =<<-EOS
759
+ ===[column] test
760
+
761
+ inside column
762
+
763
+ ===[/column_dummy]
764
+ EOS
765
+ assert_raise(ReVIEW::CompileError) do
766
+ column_helper(review)
767
+ end
768
+ end
769
+
770
+ def test_column_ref
771
+ review =<<-EOS
772
+ ===[column]{foo} test
773
+
774
+ inside column
775
+
776
+ === next level
777
+
778
+ this is @<column>{foo}.
779
+ EOS
780
+ expected =<<-EOS
781
+ <div class="column">
782
+
783
+ <h3 id="foo"><a id="column-1"></a>test</h3>
784
+ <p>inside column</p>
785
+ </div>
786
+ <h3><a id="h1-0-1"></a>next level</h3>
787
+ <p>this is コラム「test」.</p>
788
+ EOS
789
+
790
+ assert_equal expected, column_helper(review)
791
+ end
792
+
793
+
794
+ def test_ul
795
+ src =<<-EOS
796
+ * AAA
797
+ * BBB
798
+ EOS
799
+ expected = "<ul>\n<li>AAA</li>\n<li>BBB</li>\n</ul>\n"
800
+ actual = compile_block(src)
801
+ assert_equal expected, actual
802
+ end
803
+
804
+ def test_ul_cont
805
+ src =<<-EOS
806
+ * AAA
807
+ -AA
808
+ * BBB
809
+ -BB
810
+ EOS
811
+ expected = "<ul>\n<li>AAA-AA</li>\n<li>BBB-BB</li>\n</ul>\n"
812
+ actual = compile_block(src)
813
+ assert_equal expected, actual
814
+ end
815
+
816
+ def test_ul_nest1
817
+ src =<<-EOS
818
+ * AAA
819
+ ** AA
820
+ EOS
821
+
822
+ expected =<<-EOS
823
+ <ul>
824
+ <li>AAA<ul>
825
+ <li>AA</li>
826
+ </ul>
827
+ </li>
828
+ </ul>
829
+ EOS
830
+ actual = compile_block(src)
831
+ assert_equal expected, actual
832
+ end
833
+
834
+ def test_ul_nest2
835
+ src =<<-EOS
836
+ * AAA
837
+ ** AA
838
+ * BBB
839
+ ** BB
840
+ EOS
841
+
842
+ expected =<<-EOS
843
+ <ul>
844
+ <li>AAA<ul>
845
+ <li>AA</li>
846
+ </ul>
847
+ </li>
848
+ <li>BBB<ul>
849
+ <li>BB</li>
850
+ </ul>
851
+ </li>
852
+ </ul>
853
+ EOS
854
+ actual = compile_block(src)
855
+ assert_equal expected, actual
856
+ end
857
+
858
+ def test_ul_nest3
859
+ src =<<-EOS
860
+ ** AAA
861
+ * AA
862
+ * BBB
863
+ ** BB
864
+ EOS
865
+
866
+ expected =<<-EOS
867
+ <ul>
868
+ <li><ul>
869
+ <li>AAA</li>
870
+ </ul>
871
+ </li>
872
+ <li>AA</li>
873
+ <li>BBB<ul>
874
+ <li>BB</li>
875
+ </ul>
876
+ </li>
877
+ </ul>
878
+ EOS
879
+ actual = compile_block(src)
880
+ assert_equal expected, actual
881
+ end
882
+
883
+ def test_ul_nest4
884
+ src =<<-EOS
885
+ * A
886
+ ** AA
887
+ *** AAA
888
+ * B
889
+ ** BB
890
+ EOS
891
+
892
+ expected =<<-EOS
893
+ <ul>
894
+ <li>A<ul>
895
+ <li>AA<ul>
896
+ <li>AAA</li>
897
+ </ul>
898
+ </li>
899
+ </ul>
900
+ </li>
901
+ <li>B<ul>
902
+ <li>BB</li>
903
+ </ul>
904
+ </li>
905
+ </ul>
906
+ EOS
907
+ actual = compile_block(src)
908
+ assert_equal expected, actual
909
+ end
910
+
911
+ def test_ul_nest5
912
+ src =<<-EOS
913
+ * A
914
+ ** AA
915
+ **** AAAA
916
+ * B
917
+ ** BB
918
+ EOS
919
+
920
+ expected =<<-EOS
921
+ <ul>
922
+ <li>A<ul>
923
+ <li>AA<ul>
924
+ <li><ul>
925
+ <li>AAAA</li>
926
+ </ul>
927
+ </li>
928
+ </ul>
929
+ </li>
930
+ </ul>
931
+ </li>
932
+ <li>B<ul>
933
+ <li>BB</li>
934
+ </ul>
935
+ </li>
936
+ </ul>
937
+ EOS
938
+ actual = compile_block(src)
939
+ assert_equal expected, actual
940
+ end
941
+
942
+ def test_ul_in_note
943
+ src =<<-EOS
944
+ //note{
945
+
946
+ aaaa
947
+ bbb
948
+
949
+ * A
950
+ * B
951
+ //}
952
+ EOS
953
+
954
+ expected =<<-EOS
955
+ <div class=\"note\">
956
+ <p>aaaabbb</p>
957
+ <ul>
958
+ <li>A</li>
959
+ <li>B</li>
960
+ </ul>
961
+ </div>
962
+ EOS
963
+ actual = compile_block(src)
964
+ assert_equal expected, actual
965
+ end
966
+
967
+ def test_ul_in_note_and_emlist
968
+ src =<<-EOS
969
+ //note{
970
+
971
+ aaaa
972
+ bbb
973
+
974
+ //emlist{
975
+ abc
976
+ ddd
977
+ * A
978
+ * B
979
+ //}
980
+
981
+ * A
982
+ * B
983
+ //}
984
+ EOS
985
+
986
+ expected =<<-EOS
987
+ <div class=\"note\">
988
+ <p>aaaabbb</p>
989
+ <div class="emlist-code">
990
+ <pre class="emlist">abc
991
+ ddd
992
+ * A
993
+ * B
994
+ </pre>
995
+ </div>
996
+ <ul>
997
+ <li>A</li>
998
+ <li>B</li>
999
+ </ul>
1000
+ </div>
1001
+ EOS
1002
+ actual = compile_block(src)
1003
+ assert_equal expected, actual
1004
+ end
1005
+
1006
+ def test_ol
1007
+ src =<<-EOS
1008
+ 3. AAA
1009
+ 3. BBB
1010
+ EOS
1011
+
1012
+ expected =<<-EOS
1013
+ <ol>
1014
+ <li>AAA</li>
1015
+ <li>BBB</li>
1016
+ </ol>
1017
+ EOS
1018
+ actual = compile_block(src)
1019
+ assert_equal expected, actual
1020
+ end
1021
+
1022
+ def test_inline_raw0
1023
+ assert_equal "normal", compile_inline("@<raw>{normal}")
1024
+ end
1025
+
1026
+ def test_inline_raw1
1027
+ assert_equal "body", compile_inline("@<raw>{|html|body}")
1028
+ end
1029
+
1030
+ def test_inline_raw2
1031
+ assert_equal "body", compile_inline("@<raw>{|html, latex|body}")
1032
+ end
1033
+
1034
+ def test_inline_raw3
1035
+ assert_equal "", compile_inline("@<raw>{|idgxml, latex|body}")
1036
+ end
1037
+
1038
+ def test_inline_raw4
1039
+ assert_equal "|html body", compile_inline("@<raw>{|html body}")
1040
+ end
1041
+
1042
+ def test_inline_raw5
1043
+ assert_equal "nor\nmal", compile_inline("@<raw>{|html|nor\\nmal}")
1044
+ end
1045
+
1046
+ def test_block_raw0
1047
+ actual = compile_block("//raw[<>!\"\\n& ]\n")
1048
+ expected = %Q(<>!\"\n& )
1049
+ assert_equal expected, actual
1050
+ end
1051
+
1052
+ def test_block_raw1
1053
+ actual = compile_block("//raw[|html|<>!\"\\n& ]\n")
1054
+ expected = %Q(<>!\"\n& )
1055
+ assert_equal expected, actual
1056
+ end
1057
+
1058
+ def test_block_raw2
1059
+ actual = compile_block("//raw[|html, latex|<>!\"\\n& ]\n")
1060
+ expected = %Q(<>!\"\n& )
1061
+ assert_equal expected, actual
1062
+ end
1063
+
1064
+ def test_block_raw3
1065
+ actual = compile_block("//raw[|latex, idgxml|<>!\"\\n& ]\n")
1066
+ expected = ''
1067
+ assert_equal expected, actual
1068
+ end
1069
+
1070
+ def test_block_raw4
1071
+ actual = compile_block("//raw[|html <>!\"\\n& ]\n")
1072
+ expected = %Q(|html <>!\"\n& )
1073
+ assert_equal expected, actual
1074
+ end
1075
+
1076
+ def test_inline_fn
1077
+ fn = Book::FootnoteIndex.parse(['//footnote[foo][bar\\a\\$buz]'])
1078
+ @chapter.instance_eval{@footnote_index=fn}
1079
+ actual = compile_block("//footnote[foo][bar\\a\\$buz]\n")
1080
+ expected =<<-'EOS'
1081
+ <div class="footnote" id="fn-foo"><p class="footnote">[<a href="#fnb-foo">*1</a>] bar\a\$buz</p></div>
1082
+ EOS
1083
+ assert_equal expected, actual
1084
+ end
1085
+
1086
+ def test_inline_fn_with_tricky_id
1087
+ fn = Book::FootnoteIndex.parse(['//footnote[123 あ_;][bar\\a\\$buz]'])
1088
+ @chapter.instance_eval{@footnote_index=fn}
1089
+ actual = compile_block("//footnote[123 あ_;][bar\\a\\$buz]\n")
1090
+ expected =<<-'EOS'
1091
+ <div class="footnote" id="fn-id_123-_E3_81_82___3B"><p class="footnote">[<a href="#fnb-id_123-_E3_81_82___3B">*1</a>] bar\a\$buz</p></div>
1092
+ EOS
1093
+ assert_equal expected, actual
1094
+ end
1095
+
1096
+
1097
+ ## inline nesting tests
1098
+ def test_href_nest
1099
+ actual = compile_inline("@<href>{http://github.com,@<b>{G}itHub}")
1100
+ assert_equal %Q|<a href="http://github.com" class="link"><b>G</b>itHub</a>|, actual
1101
+ end
1102
+
1103
+ def test_inline_tti_nest
1104
+ actual = compile_inline("test @<tt>{aa@<i>{inline test}bb} test2")
1105
+ assert_equal %Q|test <tt>aa<i>inline test</i>bb</tt> test2|, actual
1106
+ end
1107
+
1108
+ def test_inline_ttib_nest
1109
+ actual = compile_inline("test @<tt>{aa@<i>{inline @<b>{te}st}bb} test2")
1110
+ assert_equal %Q|test <tt>aa<i>inline <b>te</b>st</i>bb</tt> test2|, actual
1111
+ end
1112
+
1113
+
1114
+ end