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,205 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # $Id: tocprinter.rb 4309 2009-07-19 04:15:02Z aamine $
4
+ #
5
+ # Copyright (c) 2002-2007 Minero Aoki
6
+ # 2008-2009 Minero Aoki, Kenshi Muto
7
+ #
8
+ # This program is free software.
9
+ # You can distribute or modify this program under the terms of
10
+ # the GNU LGPL, Lesser General Public License version 2.1.
11
+ # For details of LGPL, see the file "COPYING".
12
+ #
13
+
14
+ require 'review/htmlutils'
15
+ require 'review/htmllayout'
16
+
17
+ module ReVIEW
18
+
19
+ class TOCPrinter
20
+
21
+ def TOCPrinter.default_upper_level
22
+ 99 # no one use 99 level nest
23
+ end
24
+
25
+ def initialize(print_upper, param)
26
+ @print_upper = print_upper
27
+ @config = param
28
+ end
29
+
30
+ def print?(level)
31
+ level <= @print_upper
32
+ end
33
+ end
34
+
35
+
36
+ class TextTOCPrinter < TOCPrinter
37
+ def print_book(book)
38
+ print_children book
39
+ end
40
+
41
+ private
42
+
43
+ def print_children(node)
44
+ return unless print?(node.level + 1)
45
+ node.each_section_with_index do |section, idx|
46
+ unless section.blank?
47
+ print_node idx+1, section
48
+ print_children section
49
+ end
50
+ end
51
+ end
52
+
53
+ def print_node(number, node)
54
+ if node.chapter?
55
+ vol = node.volume
56
+ printf "%3s %3dKB %6dC %5dL %s (%s)\n",
57
+ chapnumstr(node.number),
58
+ vol.kbytes, vol.chars, vol.lines,
59
+ node.label, node.chapter_id
60
+ else
61
+ printf "%17s %5dL %s\n",
62
+ '', node.estimated_lines,
63
+ " #{' ' * (node.level - 1)}#{number} #{node.label}"
64
+ end
65
+ end
66
+
67
+ def chapnumstr(n)
68
+ n ? sprintf('%2d.', n) : ' '
69
+ end
70
+
71
+ def volume_columns(level, volstr)
72
+ cols = ["", "", "", nil]
73
+ cols[level - 1] = volstr
74
+ cols[0, 3] # does not display volume of level-4 section
75
+ end
76
+
77
+ end
78
+
79
+
80
+ class HTMLTOCPrinter < TOCPrinter
81
+
82
+ include HTMLUtils
83
+
84
+ def print_book(book)
85
+ return unless print?(1)
86
+ html = ""
87
+ book.each_part do |part|
88
+ html << h1(part.name) if part.name
89
+ part.each_section do |chap|
90
+ if chap.number
91
+ name = "chap#{chap.number}"
92
+ label = "第#{chap.number}章 #{chap.label}"
93
+ html << h2(a_name(escape_html(name), escape_html(label)))
94
+ else
95
+ label = "#{chap.label}"
96
+ html << h2(escape_html(label))
97
+ end
98
+ return unless print?(2)
99
+ if print?(3)
100
+ html << chap_sections_to_s(chap)
101
+ else
102
+ html << chapter_to_s(chap)
103
+ end
104
+ end
105
+ end
106
+ layout_file = File.join(book.basedir, "layouts", "layout.html.erb")
107
+ unless File.exist?(layout_file) # backward compatibility
108
+ layout_file = File.join(book.basedir, "layouts", "layout.erb")
109
+ end
110
+ puts HTMLLayout.new(
111
+ {'body' => html, 'title' => "目次"}, layout_file).result
112
+ end
113
+
114
+ private
115
+
116
+ def chap_sections_to_s(chap)
117
+ res = []
118
+ res << "<ol>"
119
+ chap.each_section do |sec|
120
+ res << li(escape_html(sec.label))
121
+ end
122
+ res << "</ol>"
123
+ return res.join("\n")
124
+ end
125
+
126
+ def print_chapter_to_s(chap)
127
+ res = []
128
+ chap.each_section do |sec|
129
+ res << h3(escape_html(sec.label))
130
+ next unless print?(4)
131
+ next if sec.n_sections == 0
132
+ res << "<ul>"
133
+ sec.each_section do |node|
134
+ res << li(escape_html(node.label))
135
+ end
136
+ res << "</ul>"
137
+ end
138
+ return res.join("\n")
139
+ end
140
+
141
+ def h1(label)
142
+ "<h1>#{label}</h1>"
143
+ end
144
+
145
+ def h2(label)
146
+ "<h2>#{label}</h2>"
147
+ end
148
+
149
+ def h3(label)
150
+ "<h3>#{label}</h3>"
151
+ end
152
+
153
+ def li(content)
154
+ "<li>#{content}</li>"
155
+ end
156
+
157
+ def a_name(name, label)
158
+ %Q(<a name="#{name}">#{label}</a>)
159
+ end
160
+
161
+ end
162
+
163
+ class IDGTOCPrinter < TOCPrinter
164
+ def print_book(book)
165
+ puts %Q(<?xml version="1.0" encoding="UTF-8"?>)
166
+ puts %Q(<doc xmlns:aid='http://ns.adobe.com/AdobeInDesign/4.0/'><title aid:pstyle="h0">1 パート1</title><?dtp level="0" section="第1部 パート1"?>) # FIXME: 部タイトルを取るには? & 部ごとに結果を分けるには?
167
+ puts %Q(<ul aid:pstyle='ul-partblock'>)
168
+ print_children book
169
+ puts %Q(</ul></doc>)
170
+ end
171
+
172
+ private
173
+
174
+ def print_children(node)
175
+ return unless print?(node.level + 1)
176
+ node.each_section_with_index do |sec, idx|
177
+ print_node idx+1, sec
178
+ print_children sec
179
+ end
180
+ end
181
+
182
+ LABEL_LEN = 54
183
+
184
+ def print_node(seq, node)
185
+ if node.chapter?
186
+ vol = node.volume
187
+ printf "<li aid:pstyle='ul-part'>%s</li>\n",
188
+ "#{chapnumstr(node.number)}#{node.label}"
189
+ else
190
+ printf "<li>%-#{LABEL_LEN}s\n",
191
+ " #{' ' * (node.level - 1)}#{seq} #{node.label}</li>"
192
+ end
193
+ end
194
+
195
+ def chapnumstr(n)
196
+ n ? sprintf('第%d章 ', n) : ''
197
+ end
198
+
199
+ def volume_columns(level, volstr)
200
+ cols = ["", "", "", nil]
201
+ cols[level - 1] = volstr
202
+ cols[0, 3]
203
+ end
204
+ end
205
+ end
@@ -0,0 +1,796 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2002-2006 Minero Aoki
4
+ # 2008-2010 Minero Aoki, Kenshi Muto
5
+ #
6
+ # This program is free software.
7
+ # You can distribute or modify this program under the terms of
8
+ # the GNU LGPL, Lesser General Public License version 2.1.
9
+ #
10
+
11
+ require 'review/builder'
12
+ require 'review/textutils'
13
+
14
+ module ReVIEW
15
+
16
+ class TOPBuilder < Builder
17
+
18
+ include TextUtils
19
+
20
+ [:ttbold, :hint, :maru, :keytop, :labelref, :ref, :pageref, :balloon, :strong].each {|e|
21
+ Compiler.definline(e)
22
+ }
23
+ Compiler.defsingle(:dtp, 1)
24
+
25
+ Compiler.defcodeblock(:insn, 1)
26
+ Compiler.defblock(:memo, 0..1)
27
+ Compiler.defblock(:tip, 0..1)
28
+ Compiler.defblock(:info, 0..1)
29
+ Compiler.defblock(:planning, 0..1)
30
+ Compiler.defblock(:best, 0..1)
31
+ Compiler.defblock(:important, 0..1)
32
+ Compiler.defblock(:securty, 0..1)
33
+ Compiler.defblock(:caution, 0..1)
34
+ Compiler.defblock(:notice, 0..1)
35
+ Compiler.defblock(:point, 0..1)
36
+ Compiler.defblock(:reference, 0)
37
+ Compiler.defblock(:term, 0)
38
+ Compiler.defblock(:practice, 0)
39
+ Compiler.defblock(:expert, 0)
40
+
41
+ def pre_paragraph
42
+ ''
43
+ end
44
+
45
+ def post_paragraph
46
+ ''
47
+ end
48
+
49
+ def extname
50
+ '.txt'
51
+ end
52
+
53
+ def builder_init_file
54
+ @section = 0
55
+ @subsection = 0
56
+ @subsubsection = 0
57
+ @subsubsubsection = 0
58
+
59
+ @titles = {
60
+ "emlist" => "インラインリスト",
61
+ "cmd" => "コマンド",
62
+ "quote" => "引用",
63
+ "centering" => "中央揃え",
64
+ "flushright" => "右寄せ",
65
+ "note" => "ノート",
66
+ "memo" => "メモ",
67
+ "important" => "重要",
68
+ "info" => "情報",
69
+ "planning" => "プランニング",
70
+ "shoot" => "トラブルシュート",
71
+ "term" => "用語解説",
72
+ "notice" => "注意",
73
+ "caution" => "警告",
74
+ "point" => "ここがポイント",
75
+ "reference" => "参考",
76
+ "link" => "リンク",
77
+ "best" => "ベストプラクティス",
78
+ "practice" => "練習問題",
79
+ "security" => "セキュリティ",
80
+ "expert" => "エキスパートに訊け",
81
+ "tip" => "TIP",
82
+ "box" => "書式",
83
+ "insn" => "書式",
84
+ "column" => "コラム",
85
+ "xcolumn" => "コラムパターン2",
86
+ "world" => "Worldコラム",
87
+ "hood" => "Under The Hoodコラム",
88
+ "edition" => "Editionコラム",
89
+ "insideout" => "InSideOutコラム",
90
+ "ref" => "参照",
91
+ "sup" => "補足",
92
+ "read" => "リード",
93
+ "lead" => "リード",
94
+ "list" => "リスト",
95
+ "image" => "図",
96
+ "texequation" => "TeX式",
97
+ "table" => "表",
98
+ "bpo" => "bpo",
99
+ "source" => "ソースコードリスト",
100
+ }
101
+ end
102
+ private :builder_init_file
103
+
104
+ def warn(msg)
105
+ $stderr.puts "#{@location.filename}:#{@location.lineno}: warning: #{msg}"
106
+ end
107
+
108
+ def error(msg)
109
+ $stderr.puts "#{@location.filename}:#{@location.lineno}: error: #{msg}"
110
+ end
111
+
112
+ def messages
113
+ error_messages() + warning_messages()
114
+ end
115
+
116
+ def headline(level, label, caption)
117
+ buf = ""
118
+ prefix = ""
119
+ case level
120
+ when 1
121
+ if @chapter.number.to_s =~ /\A\d+\Z/
122
+ prefix = "第#{@chapter.number}章 "
123
+ elsif @chapter.number.present?
124
+ prefix = "#{@chapter.number} "
125
+ end
126
+ @section = 0
127
+ @subsection = 0
128
+ @subsubsection = 0
129
+ @subsubsubsection = 0
130
+ when 2
131
+ @section += 1
132
+ prefix = @chapter.number.present? ? "#{@chapter.number}.#{@section} " : ""
133
+ @subsection = 0
134
+ @subsubsection = 0
135
+ @subsubsubsection = 0
136
+ when 3
137
+ @subsection += 1
138
+ prefix = @chapter.number.present? ? "#{@chapter.number}.#{@section}.#{@subsection} " : ""
139
+ @subsubsection = 0
140
+ @subsubsubsection = 0
141
+ when 4
142
+ @subsubsection += 1
143
+ prefix = @chapter.number.present? ? "#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection} " : ""
144
+ @subsubsubsection = 0
145
+ when 5
146
+ @subsubsubsection += 1
147
+ prefix = @chapter.number.present? ? "#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}.#{@subsubsubsection} " : ""
148
+ else
149
+ raise "caption level too deep or unsupported: #{level}"
150
+ end
151
+ prefix = "" if (level.to_i > @book.config["secnolevel"])
152
+ buf << "■H#{level}■#{prefix}#{caption}\n"
153
+ buf
154
+ end
155
+
156
+ def ul_begin
157
+ "\n"
158
+ end
159
+
160
+ def ul_item(lines)
161
+ "●\t#{lines.join}\n"
162
+ end
163
+
164
+ def ul_end
165
+ "\n"
166
+ end
167
+
168
+ def ol_begin
169
+ @olitem = 0
170
+ "\n"
171
+ end
172
+
173
+ def ol_item(lines, num)
174
+ "#{num}\t#{lines.join}\n"
175
+ end
176
+
177
+ def ol_end
178
+ @olitem = nil
179
+ "\n"
180
+ end
181
+
182
+ def dl_begin
183
+ "\n"
184
+ end
185
+
186
+ def dt(line)
187
+ "★#{line}☆\n"
188
+ end
189
+
190
+ def dd(lines)
191
+ buf = ""
192
+ lines.each do |paragraph|
193
+ buf << "\t#{paragraph.gsub(/\n/, '')}\n"
194
+ end
195
+ buf
196
+ end
197
+
198
+ def dl_end
199
+ "\n"
200
+ end
201
+
202
+ def paragraph(lines)
203
+ lines.join+"\n"
204
+ end
205
+
206
+ def read(lines)
207
+ buf = ""
208
+ buf << "◆→開始:#{@titles["lead"]}←◆\n"
209
+ buf << lines.join("\n") << "\n"
210
+ buf << "◆→終了:#{@titles["lead"]}←◆\n"
211
+ buf << "\n"
212
+ buf
213
+ end
214
+
215
+ alias_method :lead, :read
216
+
217
+ def inline_list(id)
218
+ chapter, id = extract_chapter_id(id)
219
+ if get_chap(chapter).nil?
220
+ %Q[#{I18n.t("list")}#{I18n.t("format_number_without_chapter", [@chapter.list(id).number])}]
221
+ else
222
+ %Q[#{I18n.t("list")}#{I18n.t("format_number", [get_chap(chapter), @chapter.list(id).number])}]
223
+ end
224
+ end
225
+
226
+ def list_header(id, caption, lang)
227
+ buf = ""
228
+ #buf << "\n"
229
+ buf << "◆→開始:#{@titles["list"]}←◆\n"
230
+ if get_chap.nil?
231
+ buf << %Q[#{I18n.t("list")}#{I18n.t("format_number_without_chapter", [@chapter.list(id).number])}#{I18n.t("caption_prefix_idgxml")}#{caption}] << "\n"
232
+ else
233
+ buf << %Q[#{I18n.t("list")}#{I18n.t("format_number", [get_chap, @chapter.list(id).number])}#{I18n.t("caption_prefix_idgxml")}#{caption}] << "\n"
234
+ end
235
+ buf << "\n"
236
+ buf
237
+ end
238
+
239
+ def list_body(id, lines, lang)
240
+ buf = ""
241
+ lines.each do |line|
242
+ buf << detab(line) << "\n"
243
+ end
244
+ buf << "◆→終了:#{@titles["list"]}←◆\n"
245
+ buf << "\n"
246
+ buf
247
+ end
248
+
249
+ def base_block(type, lines, caption = nil)
250
+ buf = ""
251
+ buf << "\n"
252
+ buf << "◆→開始:#{@titles[type]}←◆\n"
253
+ buf << "■#{caption}\n" unless caption.nil?
254
+ buf << lines.join("")
255
+ buf << "◆→終了:#{@titles[type]}←◆\n"
256
+ buf << "\n"
257
+ buf
258
+ end
259
+
260
+ def base_parablock(type, lines, caption = nil)
261
+ buf = ""
262
+ buf << "◆→開始:#{@titles[type]}←◆\n"
263
+ buf << "■#{caption}\n" unless caption.nil?
264
+ buf << lines.join("")
265
+ buf << "◆→終了:#{@titles[type]}←◆\n"
266
+ buf << "\n"
267
+ buf
268
+ end
269
+
270
+ def emlist(lines, caption = nil, lang = nil)
271
+ base_block "emlist", lines, caption
272
+ end
273
+
274
+ def emlistnum(lines, caption = nil, lang = nil)
275
+ buf = ""
276
+ buf << "◆→開始:#{@titles["emlist"]}←◆\n"
277
+ buf << "■#{caption}\n" unless caption.nil?
278
+ _lines = []
279
+ lines.each_with_index do |line, i|
280
+ buf << (i + 1).to_s.rjust(2) + ": #{line}\n"
281
+ end
282
+ buf << "◆→終了:#{@titles["emlist"]}←◆\n"
283
+ buf << "\n"
284
+ buf
285
+ end
286
+
287
+ def listnum_body(lines, lang)
288
+ buf = ""
289
+ lines.each_with_index do |line, i|
290
+ buf << (i + 1).to_s.rjust(2) + ": #{line}\n"
291
+ end
292
+ buf << "◆→終了:#{@titles["list"]}←◆\n"
293
+ buf << "\n"
294
+ buf
295
+ end
296
+
297
+ def cmd(lines, caption = nil)
298
+ base_block "cmd", lines, caption
299
+ end
300
+
301
+ def quote(lines)
302
+ base_parablock "quote", lines, nil
303
+ end
304
+
305
+ def inline_table(id)
306
+ chapter, id = extract_chapter_id(id)
307
+ if get_chap(chapter).nil?
308
+ "#{I18n.t("table")}#{I18n.t("format_number_without_chapter", [chapter.table(id).number])}"
309
+ else
310
+ "#{I18n.t("table")}#{I18n.t("format_number", [get_chap(chapter), chapter.table(id).number])}"
311
+ end
312
+ end
313
+
314
+ def inline_img(id)
315
+ chapter, id = extract_chapter_id(id)
316
+ if get_chap(chapter).nil?
317
+ "#{I18n.t("image")}#{I18n.t("format_number_without_chapter", [chapter.image(id).number])}"
318
+ else
319
+ "#{I18n.t("image")}#{I18n.t("format_number", [get_chap(chapter), chapter.image(id).number])}"
320
+ end
321
+ end
322
+
323
+ def image(lines, id, caption, metric=nil)
324
+ buf = ""
325
+ #buf << "\n"
326
+ buf << "◆→開始:#{@titles["image"]}←◆\n"
327
+ if get_chap.nil?
328
+ buf << "#{I18n.t("image")}#{I18n.t("format_number_without_chapter", [@chapter.image(id).number])}#{I18n.t("caption_prefix_idgxml")}#{caption}\n"
329
+ else
330
+ buf << "#{I18n.t("image")}#{I18n.t("format_number", [get_chap, @chapter.image(id).number])}#{I18n.t("caption_prefix_idgxml")}#{caption}\n"
331
+ end
332
+ buf << "\n"
333
+ if @chapter.image(id).bound?
334
+ buf << "◆→#{@chapter.image(id).path}←◆\n"
335
+ else
336
+ lines.each do |line|
337
+ buf << line << "\n"
338
+ end
339
+ end
340
+ buf << "◆→終了:#{@titles["image"]}←◆\n"
341
+ buf << "\n"
342
+ buf
343
+ end
344
+
345
+ def texequation(lines)
346
+ buf = ""
347
+ buf << "◆→開始:#{@titles["texequation"]}←◆\n"
348
+ buf << "#{lines.join("\n")}\n"
349
+ buf << "◆→終了:#{@titles["texequation"]}←◆\n"
350
+ buf << "\n"
351
+ buf
352
+ end
353
+
354
+ def table_header(id, caption)
355
+ buf = ""
356
+ buf << "\n"
357
+ buf << "◆→開始:#{@titles["table"]}←◆\n"
358
+ if get_chap.nil?
359
+ buf << "#{I18n.t("table")}#{I18n.t("format_number_without_chapter", [@chapter.table(id).number])}#{I18n.t("caption_prefix_idgxml")}#{caption}\n"
360
+ else
361
+ buf << "#{I18n.t("table")}#{I18n.t("format_number", [get_chap, @chapter.table(id).number])}#{I18n.t("caption_prefix_idgxml")}#{caption}\n"
362
+ end
363
+ buf << "\n"
364
+ buf
365
+ end
366
+
367
+ def table_begin(ncols)
368
+ ""
369
+ end
370
+
371
+ def tr(rows)
372
+ buf = ""
373
+ buf << rows.join("\t") << "\n"
374
+ buf
375
+ end
376
+
377
+ def th(str)
378
+ "★#{str}☆"
379
+ end
380
+
381
+ def td(str)
382
+ str
383
+ end
384
+
385
+ def table_end
386
+ buf = ""
387
+ buf << "◆→終了:#{@titles["table"]}←◆\n"
388
+ buf << "\n"
389
+ buf
390
+ end
391
+
392
+ def comment(lines, comment = nil)
393
+ lines ||= []
394
+ lines.unshift comment unless comment.blank?
395
+ str = lines.join("")
396
+ "◆→DTP連絡:#{str}←◆\n"
397
+ end
398
+
399
+ def footnote(id, str)
400
+ "【注#{@chapter.footnote(id).number}】#{str}\n"
401
+ end
402
+
403
+ def inline_fn(id)
404
+ "【注#{@chapter.footnote(id).number}】"
405
+ end
406
+
407
+ def compile_ruby(base, ruby)
408
+ "#{base}◆→DTP連絡:「#{base}」に「#{ruby}」とルビ←◆"
409
+ end
410
+
411
+ def compile_kw(word, alt)
412
+ if alt
413
+ then "★#{word}☆(#{alt.strip})"
414
+ else "★#{word}☆"
415
+ end
416
+ end
417
+
418
+ def compile_href(url, label)
419
+ if label.nil?
420
+ %Q[△#{url}☆]
421
+ else
422
+ %Q[#{label}(△#{url}☆)]
423
+ end
424
+ end
425
+
426
+ def inline_sup(str)
427
+ "#{str}◆→DTP連絡:「#{str}」は上付き←◆"
428
+ end
429
+
430
+ def inline_sub(str)
431
+ "#{str}◆→DTP連絡:「#{str}」は下付き←◆"
432
+ end
433
+
434
+ def inline_raw(str)
435
+ %Q[#{super(str).gsub("\\n", "\n")}]
436
+ end
437
+
438
+ def inline_hint(str)
439
+ "◆→ヒントスタイルここから←◆#{str}◆→ヒントスタイルここまで←◆"
440
+ end
441
+
442
+ def inline_maru(str)
443
+ "#{str}◆→丸数字#{str}←◆"
444
+ end
445
+
446
+ def inline_idx(str)
447
+ "#{str}◆→索引項目:#{str}←◆"
448
+ end
449
+
450
+ def inline_hidx(str)
451
+ "◆→索引項目:#{str}←◆"
452
+ end
453
+
454
+ def inline_ami(str)
455
+ "#{str}◆→DTP連絡:「#{str}」に網カケ←◆"
456
+ end
457
+
458
+ def inline_i(str)
459
+ "▲#{str}☆"
460
+ end
461
+
462
+ def inline_b(str)
463
+ "★#{str}☆"
464
+ end
465
+
466
+ alias_method :inline_strong, :inline_b
467
+
468
+ def inline_tt(str)
469
+ "△#{str}☆"
470
+ end
471
+
472
+ def inline_ttb(str)
473
+ "★#{str}☆◆→等幅フォント太字←◆"
474
+ end
475
+
476
+ alias_method :inline_ttbold, :inline_ttb
477
+
478
+ def inline_tti(str)
479
+ "▲#{str}☆◆→等幅フォントイタ←◆"
480
+ end
481
+
482
+ def inline_u(str)
483
+ "@#{str}@◆→@〜@部分に下線←◆"
484
+ end
485
+
486
+ def inline_icon(id)
487
+ begin
488
+ return "◆→画像 #{@chapter.image(id).path.sub(/\A\.\//, "")}←◆"
489
+ rescue
490
+ warn "no such icon image: #{id}"
491
+ return "◆→画像 #{id}←◆"
492
+ end
493
+ end
494
+
495
+ def inline_bou(str)
496
+ "#{str}◆→DTP連絡:「#{str}」に傍点←◆"
497
+ end
498
+
499
+ def inline_keytop(str)
500
+ "#{str}◆→キートップ#{str}←◆"
501
+ end
502
+
503
+ def inline_balloon(str)
504
+ %Q(\t←#{str.gsub(/@maru\[(\d+)\]/, inline_maru('\1'))})
505
+ end
506
+
507
+ def inline_uchar(str)
508
+ [str.to_i(16)].pack("U")
509
+ end
510
+
511
+ def inline_m(str)
512
+ %Q[◆→TeX式ここから←◆#{str}◆→TeX式ここまで←◆]
513
+ end
514
+
515
+ def noindent
516
+ "◆→DTP連絡:次の1行インデントなし←◆\n"
517
+ end
518
+
519
+ def nonum_begin(level, label, caption)
520
+ "■H#{level}■#{caption}\n"
521
+ end
522
+
523
+ def nonum_end(level)
524
+ end
525
+
526
+ def common_column_begin(type, caption)
527
+ buf = ""
528
+ buf << "◆→開始:#{@titles[type]}←◆\n"
529
+ buf << %Q[■#{caption}\n]
530
+ buf
531
+ end
532
+
533
+ def common_column_end(type)
534
+ buf = ""
535
+ buf << %Q[◆→終了:#{@titles[type]}←◆\n]
536
+ buf << "\n"
537
+ buf
538
+ end
539
+
540
+ def column_begin(level, label, caption)
541
+ common_column_begin("column", caption)
542
+ end
543
+
544
+ def column_end(level)
545
+ common_column_end("column")
546
+ end
547
+
548
+ def xcolumn_begin(level, label, caption)
549
+ common_column_begin("xcolumn", caption)
550
+ end
551
+
552
+ def xcolumn_end(level)
553
+ common_column_end("xcolumn")
554
+ end
555
+
556
+ def world_begin(level, label, caption)
557
+ common_column_begin("world", caption)
558
+ end
559
+
560
+ def world_end(level)
561
+ common_column_end("world")
562
+ end
563
+
564
+ def hood_begin(level, label, caption)
565
+ common_column_begin("hood", caption)
566
+ end
567
+
568
+ def hood_end(level)
569
+ common_column_end("hood")
570
+ end
571
+
572
+ def edition_begin(level, label, caption)
573
+ common_column_begin("edition", caption)
574
+ end
575
+
576
+ def edition_end(level)
577
+ common_column_end("edition")
578
+ end
579
+
580
+ def insideout_begin(level, label, caption)
581
+ common_column_begin("insideout", caption)
582
+ end
583
+
584
+ def insideout_end(level)
585
+ common_column_end("insideout")
586
+ end
587
+
588
+ def ref_begin(level, label, caption)
589
+ common_column_begin("ref", caption)
590
+ end
591
+
592
+ def ref_end(level)
593
+ common_column_end("ref")
594
+ end
595
+
596
+ def sup_begin(level, label, caption)
597
+ common_column_begin("sup", caption)
598
+ end
599
+
600
+ def sup_end(level)
601
+ common_column_end("sup")
602
+ end
603
+
604
+ def flushright(lines)
605
+ base_parablock "flushright", lines, nil
606
+ end
607
+
608
+ def centering(lines)
609
+ base_parablock "centering", lines, nil
610
+ end
611
+
612
+ def note(lines, caption = nil)
613
+ base_parablock "note", lines, caption
614
+ end
615
+
616
+ def memo(lines, caption = nil)
617
+ base_parablock "memo", lines, caption
618
+ end
619
+
620
+ def tip(lines, caption = nil)
621
+ base_parablock "tip", lines, caption
622
+ end
623
+
624
+ def info(lines, caption = nil)
625
+ base_parablock "info", lines, caption
626
+ end
627
+
628
+ def planning(lines, caption = nil)
629
+ base_parablock "planning", lines, caption
630
+ end
631
+
632
+ def best(lines, caption = nil)
633
+ base_parablock "best", lines, caption
634
+ end
635
+
636
+ def important(lines, caption = nil)
637
+ base_parablock "important", lines, caption
638
+ end
639
+
640
+ def security(lines, caption = nil)
641
+ base_parablock "security", lines, caption
642
+ end
643
+
644
+ def caution(lines, caption = nil)
645
+ base_parablock "caution", lines, caption
646
+ end
647
+
648
+ def term(lines)
649
+ base_parablock "term", lines, nil
650
+ end
651
+
652
+ def link(lines, caption = nil)
653
+ base_parablock "link", lines, caption
654
+ end
655
+
656
+ def notice(lines, caption = nil)
657
+ base_parablock "notice", lines, caption
658
+ end
659
+
660
+ def point(lines, caption = nil)
661
+ base_parablock "point", lines, caption
662
+ end
663
+
664
+ def shoot(lines, caption = nil)
665
+ base_parablock "shoot", lines, caption
666
+ end
667
+
668
+ def reference(lines)
669
+ base_parablock "reference", lines, nil
670
+ end
671
+
672
+ def practice(lines)
673
+ base_parablock "practice", lines, nil
674
+ end
675
+
676
+ def expert(lines)
677
+ base_parablock "expert", lines, nil
678
+ end
679
+
680
+ def insn(lines, caption = nil)
681
+ base_block "insn", lines, caption
682
+ end
683
+
684
+ alias_method :box, :insn
685
+
686
+ def indepimage(id, caption=nil, metric=nil)
687
+ buf = ""
688
+ buf << "\n"
689
+ begin
690
+ buf << "◆→画像 #{@chapter.image(id).path.sub(/\A\.\//, "")} #{metric.join(" ")}←◆\n"
691
+ rescue
692
+ warn "no such image: #{id}"
693
+ buf << "◆→画像 #{id}←◆\n"
694
+ end
695
+ buf << "図 #{caption}\n" if caption.present?
696
+ buf << "\n"
697
+ buf
698
+ end
699
+
700
+ alias_method :numberlessimage, :indepimage
701
+
702
+ def label(id)
703
+ # FIXME
704
+ ""
705
+ end
706
+
707
+ def tsize(id)
708
+ # FIXME
709
+ ""
710
+ end
711
+
712
+ def dtp(str)
713
+ # FIXME
714
+ end
715
+
716
+ def bpo(lines)
717
+ base_block "bpo", lines, nil
718
+ end
719
+
720
+ def inline_dtp(str)
721
+ # FIXME
722
+ ""
723
+ end
724
+
725
+ def inline_del(str)
726
+ # FIXME
727
+ ""
728
+ end
729
+
730
+ def inline_code(str)
731
+ %Q[△#{str}☆]
732
+ end
733
+
734
+ def inline_br(str)
735
+ %Q(\n)
736
+ end
737
+
738
+ def text(str)
739
+ str
740
+ end
741
+
742
+ def inline_chap(id)
743
+ #"「第#{super}章 #{inline_title(id)}」"
744
+ # "第#{super}章"
745
+ super
746
+ end
747
+
748
+ def inline_chapref(id)
749
+ chs = ["", "「", "」"]
750
+ unless @book.config["chapref"].nil?
751
+ _chs = @book.config["chapref"].split(",")
752
+ if _chs.size != 3
753
+ error "--chapsplitter must have exactly 3 parameters with comma."
754
+ else
755
+ chs = _chs
756
+ end
757
+ else
758
+ end
759
+ "#{chs[0]}#{@book.chapter_index.number(id)}#{chs[1]}#{@book.chapter_index.title(id)}#{chs[2]}"
760
+ rescue KeyError
761
+ error "unknown chapter: #{id}"
762
+ nofunc_text("[UnknownChapter:#{id}]")
763
+ end
764
+
765
+ def source(lines, caption = nil, lang = nil)
766
+ base_block "source", lines, caption
767
+ end
768
+
769
+ def inline_ttibold(str)
770
+ "▲#{str}☆◆→等幅フォント太字イタ←◆"
771
+ end
772
+
773
+ def inline_labelref(idref)
774
+ %Q(「◆→#{idref}←◆」) # 節、項を参照
775
+ end
776
+
777
+ alias_method :inline_ref, :inline_labelref
778
+
779
+ def inline_pageref(idref)
780
+ %Q(●ページ◆→#{idref}←◆) # ページ番号を参照
781
+ end
782
+
783
+ def circle_begin(level, label, caption)
784
+ "・\t#{caption}\n"
785
+ end
786
+
787
+ def circle_end(level)
788
+ end
789
+
790
+ def nofunc_text(str)
791
+ str
792
+ end
793
+
794
+ end
795
+
796
+ end # module ReVIEW