review-retrovert 0.9.11 → 0.11.3

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 (148) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/README.md +1 -1
  4. data/Rakefile +15 -0
  5. data/lib/review/retrovert/cli.rb +6 -0
  6. data/lib/review/retrovert/converter.rb +38 -0
  7. data/lib/review/retrovert/version.rb +1 -1
  8. data/lib/review/retrovert/yamlconfig.rb +38 -1
  9. metadata +49 -146
  10. data/.dockerignore +0 -9
  11. data/.editorconfig +0 -16
  12. data/.gitattributes +0 -5
  13. data/.github/FUNDING.yml +0 -4
  14. data/.github/workflows/docker-build.yml +0 -26
  15. data/.github/workflows/release.yml +0 -26
  16. data/.github/workflows/retrovert.yml +0 -91
  17. data/.gitignore +0 -15
  18. data/.rspec +0 -3
  19. data/.ruby-version +0 -1
  20. data/.vscode/launch.json +0 -48
  21. data/Dockerfile +0 -5
  22. data/Gemfile +0 -8
  23. data/Gemfile.lock +0 -118
  24. data/Makefile +0 -31
  25. data/bin/console +0 -14
  26. data/bin/setup +0 -8
  27. data/docker/review.Dockerfile +0 -10
  28. data/hooks/post_push +0 -8
  29. data/package-lock.json +0 -6
  30. data/package.json +0 -1
  31. data/review-retrovert.code-workspace +0 -8
  32. data/review-retrovert.gemspec +0 -37
  33. data/testdata/mybook/.gitignore +0 -13
  34. data/testdata/mybook/.textlintrc +0 -11
  35. data/testdata/mybook/README.md +0 -43
  36. data/testdata/mybook/Rakefile +0 -24
  37. data/testdata/mybook/catalog.yml +0 -60
  38. data/testdata/mybook/config-noretrovert.yml +0 -404
  39. data/testdata/mybook/config-retrovert.yml +0 -16
  40. data/testdata/mybook/config-starter.yml +0 -264
  41. data/testdata/mybook/config.yml +0 -404
  42. data/testdata/mybook/contents/00-preface.re +0 -129
  43. data/testdata/mybook/contents/01-install.re +0 -305
  44. data/testdata/mybook/contents/02-tutorial.re +0 -1228
  45. data/testdata/mybook/contents/03-syntax.re +0 -4610
  46. data/testdata/mybook/contents/04-customize.re +0 -1064
  47. data/testdata/mybook/contents/05-faq.re +0 -606
  48. data/testdata/mybook/contents/06-bestpractice.re +0 -1343
  49. data/testdata/mybook/contents/91-compare.re +0 -418
  50. data/testdata/mybook/contents/92-filelist.re +0 -125
  51. data/testdata/mybook/contents/93-background.re +0 -267
  52. data/testdata/mybook/contents/99-postface.re +0 -39
  53. data/testdata/mybook/contents/r0-inner.re +0 -2
  54. data/testdata/mybook/contents/r0-root.re +0 -49
  55. data/testdata/mybook/contents/table.csv +0 -4
  56. data/testdata/mybook/contents/test.txt +0 -1
  57. data/testdata/mybook/contents/ut.re +0 -5
  58. data/testdata/mybook/css/normalize.css +0 -349
  59. data/testdata/mybook/css/webstyle.css +0 -692
  60. data/testdata/mybook/data/terms.txt +0 -3
  61. data/testdata/mybook/data/words.txt +0 -15
  62. data/testdata/mybook/images/03-syntax/favicon-16x16.png +0 -0
  63. data/testdata/mybook/images/03-syntax/figure_heretop.png +0 -0
  64. data/testdata/mybook/images/03-syntax/index-page.png +0 -0
  65. data/testdata/mybook/images/03-syntax/order-detail.png +0 -0
  66. data/testdata/mybook/images/03-syntax/tw-icon1.jpg +0 -0
  67. data/testdata/mybook/images/03-syntax/tw-icon2.jpg +0 -0
  68. data/testdata/mybook/images/03-syntax/tw-icon3.jpg +0 -0
  69. data/testdata/mybook/images/03-syntax/tw-icon4.jpg +0 -0
  70. data/testdata/mybook/images/04-customize/caption_pagebreak.png +0 -0
  71. data/testdata/mybook/images/04-customize/chaptitlepage_sample.png +0 -0
  72. data/testdata/mybook/images/04-customize/section_decoration_samples.png +0 -0
  73. data/testdata/mybook/images/05-faq/codeblock_rpadding1.png +0 -0
  74. data/testdata/mybook/images/05-faq/codeblock_rpadding2.png +0 -0
  75. data/testdata/mybook/images/05-faq/dummy-image.png +0 -0
  76. data/testdata/mybook/images/06-bestpractice/figure_heretop.png +0 -0
  77. data/testdata/mybook/images/06-bestpractice/font_beramono.png +0 -0
  78. data/testdata/mybook/images/06-bestpractice/heading_design1.png +0 -0
  79. data/testdata/mybook/images/06-bestpractice/heading_design2.png +0 -0
  80. data/testdata/mybook/images/06-bestpractice/margin_book.png +0 -0
  81. data/testdata/mybook/images/06-bestpractice/multiline-title.png +0 -0
  82. data/testdata/mybook/images/06-bestpractice/preface_numbered.png +0 -0
  83. data/testdata/mybook/images/06-bestpractice/program_border.png +0 -0
  84. data/testdata/mybook/images/06-bestpractice/sechead_design_4.png +0 -0
  85. data/testdata/mybook/images/06-bestpractice/section_title_wlines.png +0 -0
  86. data/testdata/mybook/images/06-bestpractice/titlepage-samples.png +0 -0
  87. data/testdata/mybook/images/93-background/bug913.png +0 -0
  88. data/testdata/mybook/images/93-background/slide2.png +0 -0
  89. data/testdata/mybook/images/avatar-b.png +0 -0
  90. data/testdata/mybook/images/avatar-g.png +0 -0
  91. data/testdata/mybook/images/avatar-r.png +0 -0
  92. data/testdata/mybook/images/caution-icon.png +0 -0
  93. data/testdata/mybook/images/cover_a5.pdf +0 -0
  94. data/testdata/mybook/images/cover_b5.pdf +0 -0
  95. data/testdata/mybook/images/info-icon.png +0 -0
  96. data/testdata/mybook/images/tw-icon.jpg +0 -0
  97. data/testdata/mybook/images/warning-icon.png +0 -0
  98. data/testdata/mybook/layouts/layout.epub.erb +0 -29
  99. data/testdata/mybook/layouts/layout.html5.erb +0 -108
  100. data/testdata/mybook/layouts/layout.tex.erb +0 -432
  101. data/testdata/mybook/layouts/layout.tex.erb.orig +0 -386
  102. data/testdata/mybook/lib/hooks/beforetexcompile.rb +0 -55
  103. data/testdata/mybook/lib/ruby/review-book.rb +0 -64
  104. data/testdata/mybook/lib/ruby/review-builder.rb +0 -1342
  105. data/testdata/mybook/lib/ruby/review-cli.rb +0 -58
  106. data/testdata/mybook/lib/ruby/review-compiler.rb +0 -1176
  107. data/testdata/mybook/lib/ruby/review-epubbuilder.rb +0 -33
  108. data/testdata/mybook/lib/ruby/review-epubmaker.rb +0 -609
  109. data/testdata/mybook/lib/ruby/review-htmlbuilder.rb +0 -949
  110. data/testdata/mybook/lib/ruby/review-latexbuilder.rb +0 -1065
  111. data/testdata/mybook/lib/ruby/review-maker.rb +0 -346
  112. data/testdata/mybook/lib/ruby/review-markdownbuilder.rb +0 -945
  113. data/testdata/mybook/lib/ruby/review-markdownmaker.rb +0 -91
  114. data/testdata/mybook/lib/ruby/review-monkeypatch.rb +0 -93
  115. data/testdata/mybook/lib/ruby/review-pdfmaker.rb +0 -546
  116. data/testdata/mybook/lib/ruby/review-textbuilder.rb +0 -36
  117. data/testdata/mybook/lib/ruby/review-tocparser.rb +0 -285
  118. data/testdata/mybook/lib/ruby/review-webmaker.rb +0 -448
  119. data/testdata/mybook/lib/tasks/mytasks.rake +0 -31
  120. data/testdata/mybook/lib/tasks/review.rake +0 -156
  121. data/testdata/mybook/lib/tasks/review.rake.orig +0 -72
  122. data/testdata/mybook/lib/tasks/starter.rake +0 -470
  123. data/testdata/mybook/locale.yml +0 -6
  124. data/testdata/mybook/review-ext.rb +0 -206
  125. data/testdata/mybook/sty/indexstyle.ist +0 -25
  126. data/testdata/mybook/sty/jumoline.sty +0 -310
  127. data/testdata/mybook/sty/mycolophon.sty +0 -81
  128. data/testdata/mybook/sty/mystyle.sty +0 -8
  129. data/testdata/mybook/sty/mytextsize.sty +0 -94
  130. data/testdata/mybook/sty/mytitlepage.sty +0 -126
  131. data/testdata/mybook/sty/review-base.sty +0 -276
  132. data/testdata/mybook/sty/reviewmacro.sty +0 -60
  133. data/testdata/mybook/sty/starter-codeblock.sty +0 -463
  134. data/testdata/mybook/sty/starter-color.sty +0 -134
  135. data/testdata/mybook/sty/starter-font.sty +0 -112
  136. data/testdata/mybook/sty/starter-heading.sty +0 -561
  137. data/testdata/mybook/sty/starter-misc.sty +0 -894
  138. data/testdata/mybook/sty/starter-note.sty +0 -180
  139. data/testdata/mybook/sty/starter-section.sty +0 -262
  140. data/testdata/mybook/sty/starter-talklist.sty +0 -105
  141. data/testdata/mybook/sty/starter-toc.sty +0 -72
  142. data/testdata/mybook/sty/starter-util.sty +0 -39
  143. data/testdata/mybook/sty/starter.sty +0 -36
  144. data/testdata/mybook/sty/ut.sty +0 -26
  145. data/testdata/mybook/style.css +0 -597
  146. data/testdata/mybook/ut-catalog.yml +0 -61
  147. data/testdata/mybook/ut-config-starter.yml +0 -3
  148. data/testdata/mybook/ut-config.yml +0 -404
@@ -1,949 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- ###
4
- ### ReVIEW::HTMLBuilderクラスを拡張する
5
- ###
6
-
7
- require 'review/htmlbuilder'
8
-
9
-
10
- module ReVIEW
11
-
12
- defined?(HTMLBuilder) or raise "internal error: HTMLBuilder not found."
13
-
14
-
15
- class HTMLBuilder
16
-
17
- attr_accessor :starter_config
18
-
19
- def target_name
20
- "html"
21
- end
22
-
23
- def layoutfile
24
- ## 'rake web' のときに使うレイアウトファイルを 'layout.html5.erb' へ変更
25
- if @book.config.maker == 'webmaker'
26
- htmldir = 'web/html'
27
- #localfilename = 'layout-web.html.erb'
28
- localfilename = 'layout.html5.erb'
29
- else
30
- htmldir = 'html'
31
- localfilename = 'layout.html.erb'
32
- end
33
- ## 以下はリファクタリングした結果
34
- basename = @book.htmlversion == 5 ? 'layout-html5.html.erb' : 'layout-xhtml1.html.erb'
35
- htmlfilename = File.join(htmldir, basename)
36
- #
37
- layout_file = File.join(@book.basedir, 'layouts', localfilename)
38
- if ! File.exist?(layout_file)
39
- ! File.exist?(File.join(@book.basedir, 'layouts', 'layout.erb')) or
40
- raise ReVIEW::ConfigError, 'layout.erb is obsoleted. Please use layout.html.erb.'
41
- layout_file = nil
42
- elsif ENV['REVIEW_SAFE_MODE'].to_i & 4 > 0
43
- warn "user's layout is prohibited in safe mode. ignored."
44
- layout_file = nil
45
- end
46
- layout_file ||= File.expand_path(htmlfilename, ReVIEW::Template::TEMPLATE_DIR)
47
- return layout_file
48
- end
49
-
50
- def result
51
- # default XHTML header/footer
52
- @title = strip_html(compile_inline(@chapter.title))
53
- @body = @output.string
54
- @language = @book.config['language']
55
- @stylesheets = @book.config['stylesheet']
56
- @next = @chapter.next_chapter
57
- @prev = @chapter.prev_chapter
58
- @next_title = @next ? compile_inline(@next.title) : ''
59
- @prev_title = @prev ? compile_inline(@prev.title) : ''
60
-
61
- if @book.config.maker == 'webmaker'
62
- #@toc = ReVIEW::WEBTOCPrinter.book_to_string(@book) #-
63
- @toc = ReVIEW::WEBTOCPrinter.book_to_html(@book, @chapter) #+
64
- end
65
-
66
- ReVIEW::Template.load(layoutfile()).result(binding())
67
- end
68
-
69
- def headline(level, label, caption)
70
- prefix, anchor = headline_prefix(level)
71
- prefix = "<span class=\"secno\">#{prefix}</span> " if prefix
72
- puts "" if level > 1
73
- a_id = ""
74
- a_id = "<a id=\"h#{anchor}\"></a>" if anchor
75
- #
76
- if caption.empty?
77
- puts a_id if label
78
- else
79
- br = ""
80
- attr = label ? " id=\"#{normalize_id(label)}\"" : ""
81
- conf = @starter_config
82
- case level
83
- when 1 ; attr << " class=\"#{conf['chapter_decoration']} #{conf['chapter_align']} #{conf['chapter_oneline'] ? 'oneline' : 'twolines'}\"" if prefix
84
- attr << " class=\"none #{conf['chapter_align']}\"" unless prefix
85
- br = "<br/>" unless conf['chapter_oneline']
86
- when 2 ; attr << " class=\"#{conf['section_decoration']}\""
87
- when 3 ; attr << " class=\"#{conf['subsection_decoration']}\""
88
- end
89
- puts "<h#{level}#{attr}>#{a_id}#{prefix}#{br}#{compile_inline(caption)}</h#{level}>"
90
- end
91
- end
92
-
93
- def result_metric(array)
94
- attrs = {}
95
- array.each do |item|
96
- k = item.keys[0]
97
- v = item[k]
98
- if k == 'border' && v == 'on'
99
- k = 'class'; v = 'border-on'
100
- end
101
- (attrs[k] ||= []) << v
102
- end
103
- attrs.map {|k, arr| " #{k}=\"#{arr.join(' ')}\"" }.join()
104
- end
105
-
106
- ## 画像
107
-
108
- def _render_image(id, image_filepath, caption, opts)
109
- src = image_filepath.sub(/\A\.\//, '')
110
- alt = escape_html(compile_inline(caption))
111
- #
112
- classes = ["img"]
113
- styles = []
114
- #
115
- if opts[:scale]
116
- case (scale = opts[:scale])
117
- when /\A\d+\z/, /\A\d\.\d*\z/, /\A\.\d+\z/
118
- per = (scale.to_f * 100).round()
119
- when /\A\d+(\.\d+)?%\z/
120
- per = scale.sub(/%\z/, '').to_f.round()
121
- else
122
- error "scale=#{scale}: invalid scale value."
123
- end
124
- found = PERCENT_THRESHOLDS.find {|x| x == per }
125
- if found
126
- classes << 'width-%03dper' % per
127
- else
128
- styles << "max-width:#{per}%"
129
- end
130
- end
131
- #
132
- classes << opts[:class] if opts[:class]
133
- classes << "border" if opts[:border]
134
- classes << "draft" if opts[:draft]
135
- styles << opts[:style] if opts[:style]
136
- styles << "width:#{opts[:width]}" if opts[:width]
137
- #
138
- puts "<div id=\"#{normalize_id(id)}\" class=\"image\">"
139
- print "<img src=\"#{src}\" alt=\"#{alt}\""
140
- print " class=\"#{classes.join(' ')}\"" unless classes.empty?
141
- print " style=\"#{styles.join(' ')}\"" unless styles.empty?
142
- puts " />"
143
- image_header(id, caption)
144
- puts "</div>"
145
- end
146
-
147
- PERCENT_THRESHOLDS = [
148
- 10, 20, 25, 30, 33, 40, 50, 60, 67, 70, 75, 80, 90, 100,
149
- ]
150
-
151
- protected
152
-
153
- ## コードブロック(//program, //terminal, //output)
154
-
155
- CLASSNAMES = {
156
- "program" => "code",
157
- "terminal" => "cmd-code",
158
- "list" => "caption-code",
159
- "listnum" => "code",
160
- "emlist" => "emlist-code",
161
- "emlistnum" => "emlistnum-code",
162
- "source" => "source-code",
163
- "cmd" => "cmd-code",
164
- "output" => "output",
165
- }
166
-
167
- def _codeblock_eolmark()
168
- "<small class=\"startereolmark\"></small>"
169
- end
170
-
171
- def _codeblock_indentmark()
172
- '<span class="indentbar"> </span>'
173
- end
174
-
175
- def _render_codeblock(blockname, lines, id, caption_str, opts)
176
- caption = caption_str
177
- #
178
- if opts['eolmark']
179
- eolmark = _codeblock_eolmark() # ex: '{\startereolmark}'
180
- else
181
- eolmark = nil
182
- end
183
- #
184
- eol = eolmark ? "#{eolmark}\n" : "\n"
185
- lines = lines.map {|line|
186
- line = _parse_inline(line) {|text| escape(text) }
187
- }
188
- #
189
- indent_width = opts['indent']
190
- if indent_width && indent_width > 0
191
- lines = _add_indent_mark(lines, indent_width)
192
- end
193
- #
194
- classname = CLASSNAMES[blockname] || "code"
195
- classname += " #{opts['classname']}" if opts['classname']
196
- puts "<div id=\"#{normalize_id(id)}\" class=\"#{classname}\">" if id.present?
197
- puts "<div class=\"#{classname}\">" unless id.present?
198
- #
199
- classattr = nil
200
- if id.present? || caption.present?
201
- str = _build_caption_str(id, caption)
202
- print "<span class=\"caption\">#{str}</span>\n"
203
- classattr = "list"
204
- end
205
- if blockname == "output"
206
- classattr = blockname
207
- else
208
- classattr ||= "emlist"
209
- end
210
- #
211
- lang = opts['lang']
212
- lang = File.extname(id || "").gsub(".", "") if lang.blank?
213
- classattr << " language-#{lang}" unless lang.blank?
214
- classattr << " highlight" if highlight?
215
- print "<pre class=\"#{classattr}\">"
216
- #
217
- gen = opts['lineno'] ? LineNumberGenerator.new(opts['lineno']).each : nil
218
- if gen
219
- width = opts['linenowidth'] || -1
220
- if width < 0
221
- format = "%s"
222
- elsif width == 0
223
- last_lineno = gen.each.take(lines.length).compact.last
224
- width = last_lineno.to_s.length
225
- format = "%#{width}s"
226
- else
227
- format = "%#{width}s"
228
- end
229
- end
230
- buf = []
231
- start_tag = (opts['linenowidth'] || -1) >= 0 ? "<em class=\"linenowidth\">" : "<em class=\"lineno\">"
232
- lines.each_with_index do |line, i|
233
- buf << start_tag << (format % gen.next) << ": </em>" if gen
234
- buf << line #<< "\n"
235
- end
236
- puts highlight(body: buf.join(), lexer: lang,
237
- format: "html", linenum: !!gen,
238
- #options: {linenostart: start}
239
- )
240
- #
241
- print "</pre>\n"
242
- print "</div>\n"
243
- end
244
-
245
- def _add_indent_mark(lines, indent_width)
246
- space = " "
247
- rexp = /\A( +)/
248
- #
249
- width = indent_width
250
- mark = _codeblock_indentmark() # ex: '{\starterindentmark}'
251
- indent = space * (width - 1) + mark
252
- nchar = space.length
253
- return lines.map {|line|
254
- line.sub(rexp) {
255
- m, n = ($1.length / nchar - 1).divmod width
256
- "#{space}#{indent * m}#{space * n}"
257
- }
258
- }
259
- end
260
-
261
- public
262
-
263
- ## コードリスト(//list, //emlist, //listnum, //emlistnum, //cmd, //source)
264
- def list(lines, id=nil, caption=nil, lang=nil)
265
- _codeblock("list", lines, id, caption, _codeblock_optstr(lang, false))
266
- end
267
- def listnum(lines, id=nil, caption=nil, lang=nil)
268
- _codeblock("listnum", lines, id, caption, _codeblock_optstr(lang, true))
269
- end
270
- def emlist(lines, caption=nil, lang=nil)
271
- _codeblock("emlist", lines, nil, caption, _codeblock_optstr(lang, false))
272
- end
273
- def emlistnum(lines, caption=nil, lang=nil)
274
- _codeblock("emlistnum", lines, nil, caption, _codeblock_optstr(lang, true))
275
- end
276
- def source(lines, caption=nil, lang=nil)
277
- _codeblock("source", lines, nil, caption, _codeblock_optstr(lang, false))
278
- end
279
- def cmd(lines, caption=nil, lang=nil)
280
- lang ||= "shell-session"
281
- _codeblock("cmd", lines, nil, caption, _codeblock_optstr(lang, false))
282
- end
283
- def _codeblock_optstr(lang, lineno_flag)
284
- arr = []
285
- arr << lang if lang
286
- if lineno_flag
287
- first_line_num = line_num()
288
- arr << "lineno=#{first_line_num}"
289
- arr << "linenowidth=0"
290
- end
291
- return arr.join(",")
292
- end
293
- private :_codeblock_optstr
294
-
295
- protected
296
-
297
- ## @<secref>{}
298
-
299
- def _build_secref(chap, num, title, parent_title)
300
- s = ""
301
- ## 親セクションのタイトルがあれば使う
302
- if parent_title
303
- s << "「%s」内の" % parent_title # TODO: I18n化
304
- end
305
- ## 対象セクションへのリンクを作成する
306
- if @book.config['chapterlink']
307
- filename = "#{chap.id}#{extname()}"
308
- dom_id = 'h' + num.gsub('.', '-')
309
- s << "「<a href=\"#{filename}##{dom_id}\">#{title}</a>」"
310
- else
311
- s << "「#{title}」"
312
- end
313
- return s
314
- end
315
-
316
- public
317
-
318
- ## 順序つきリスト
319
-
320
- def ol_begin(start_num=nil)
321
- @_ol_types ||= [] # stack
322
- case start_num
323
- when nil
324
- type = "1"; start = 1
325
- when /\A(\d+)\.\z/
326
- type = "1"; start = $1.to_i
327
- when /\A([A-Z])\.\z/
328
- type = "A"; start = $1.ord - 'A'.ord + 1
329
- when /\A([a-z])\.\z/
330
- type = "a"; start = $1.ord - 'a'.ord + 1
331
- else
332
- type = nil; start = nil
333
- end
334
- if type
335
- puts "<ol start=\"#{start}\" type=\"#{type}\">"
336
- else
337
- puts "<ol class=\"ol-none\">"
338
- end
339
- @_ol_types.push(type)
340
- end
341
-
342
- def ol_end()
343
- ol = !! @_ol_types.pop()
344
- if ol
345
- puts "</ol>"
346
- else
347
- puts "</ol>"
348
- end
349
- end
350
-
351
- def ol_item_begin(lines, num)
352
- ol = !! @_ol_types[-1]
353
- if ol
354
- print "<li>#{lines.join}"
355
- else
356
- n = escape_html(num)
357
- print "<li data-mark=\"#{n}\"><span class=\"li-mark\">#{n} </span>#{lines.join}"
358
- end
359
- end
360
-
361
- def ol_item_end()
362
- puts "</li>"
363
- end
364
-
365
- def dl_dd_begin()
366
- puts "<dd>"
367
- end
368
-
369
- def dl_dd_end()
370
- puts "</dd>"
371
- end
372
-
373
- ## 画像横に文章
374
- def _render_sideimage(filepath, imagewidth, opts, &b)
375
- side = (opts['side'] || 'L') == 'L' ? 'left' : 'right'
376
- imgclass = opts['border'] ? "image-bordered" : nil
377
- normalize = proc {|s| s =~ /^\A(\d+(\.\d+))%\z/ ? "#{$1.to_f/100.0}\\textwidth" : s }
378
- imgwidth = normalize.call(imagewidth)
379
- boxwidth = normalize.call(opts['boxwidth']) || imgwidth
380
- sepwidth = normalize.call(opts['sep'] || "0pt")
381
- #
382
- puts "<div class=\"sideimage\">\n"
383
- puts " <div class=\"sideimage-image\" style=\"float:#{side};text-align:center;width:#{boxwidth}\">\n"
384
- puts " <img src=\"#{filepath}\" class=\"#{imgclass}\" style=\"width:#{imgwidth}\"/>\n"
385
- puts " </div>\n"
386
- puts " <div class=\"sideimage-text\" style=\"margin-#{side}:#{boxwidth}\">\n"
387
- puts " <div style=\"padding-#{side}:#{sepwidth}\">\n"
388
- yield
389
- puts " </div>\n"
390
- puts " </div>\n"
391
- puts "</div>\n"
392
- end
393
-
394
- ## 入れ子可能なブロック命令
395
-
396
- def on_minicolumn(type, caption=nil, &b)
397
- with_context(:minicolumn) do
398
- puts "<div class=\"miniblock miniblock-#{type}\">"
399
- puts "<p class=\"miniblock-caption\">#{compile_inline(caption)}</p>" if caption.present?
400
- yield
401
- puts '</div>'
402
- end
403
- end
404
- protected :on_minicolumn
405
-
406
- #### ブロック命令
407
-
408
- def footnote(id, str)
409
- id_val = "fn-#{normalize_id(id)}"
410
- href = "#fnb-#{normalize_id(id)}"
411
- text = compile_inline(str)
412
- chap_num = @chapter.footnote(id).number
413
- if @book.config['epubversion'].to_i == 3
414
- attr = " epub:type=\"footnote\""
415
- mark = "[*#{chap_num}]"
416
- else
417
- attr = ""
418
- mark = "[<a href=\"#{href}\">*#{chap_num}</a>]"
419
- end
420
- #
421
- if truncate_if_endwith?("</div><!--/.footnote-list-->\n")
422
- else
423
- puts "<div class=\"footnote-list\">"
424
- end
425
- print "<div class=\"footnote\" id=\"#{id_val}\"#{attr}>"
426
- print "<p class=\"footnote\">"
427
- print "<span class=\"footnote-mark\">#{mark} </span>"
428
- print text
429
- print "</p>"
430
- puts "</div>"
431
- puts "</div><!--/.footnote-list-->\n"
432
- end
433
-
434
- alias __original_texequation texequation
435
- def texequation(lines, label=nil, caption=nil)
436
- if label.present?
437
- chap = get_chap()
438
- if chap.nil?
439
- key = "format_number_header_without_chapter"
440
- args = [@chapter.equation(label).number]
441
- else
442
- key = "format_number_header"
443
- args = [chap, @chapter.equation(label).number]
444
- end
445
- s1 = I18n.t("equation")
446
- s2 = I18n.t(key, args)
447
- s3 = I18n.t("caption_prefix")
448
- s4 = compile_inline(caption)
449
- puts "<span class=\"caption\">#{s1}#{s2}#{s3}#{s4}</span>"
450
- has_caption_line = true
451
- elsif caption.present?
452
- s3 = I18n.t("caption_prefix")
453
- s4 = compile_inline(caption)
454
- puts "<span class=\"caption\">#{s3}#{s4}</span>"
455
- has_caption_line = true
456
- else
457
- has_caption_line = false
458
- end
459
- #
460
- __original_texequation(lines)
461
- end
462
-
463
- ## 章 (Chapter) の概要
464
- def on_abstract_block()
465
- puts '<div class="abstract">'
466
- yield
467
- puts '</div>'
468
- end
469
-
470
- ## 章 (Chapter) の著者
471
- def on_chapterauthor_block(name)
472
- puts "<div class=\"chapterauthor\">#{escape(name)}</div>"
473
- end
474
-
475
- ## 会話リスト
476
- def _render_talklist(opts, &b)
477
- c = opts[:classname]
478
- s = c ? " #{c}" : nil
479
- puts "<div class=\"talk-outer#{s}\">"
480
- puts " <ul class=\"talk-list#{s}\">"
481
- yield
482
- puts " </ul>"
483
- puts "</div>"
484
- end
485
-
486
- ## 会話項目
487
- def _render_talk(image_filepath=nil, name=nil, &b)
488
- puts "<li class=\"talk-item\">"
489
- print " <span class=\"talk-chara\">"
490
- if image_filepath.present?
491
- print "<img class=\"talk-image\" src=\"#{image_filepath}\"/>"
492
- else
493
- s = compile_inline(name || '')
494
- print "<b class=\"talk-name\">#{s}</b>"
495
- end
496
- puts "</span>"
497
- print " <div class=\"talk-text\">"
498
- yield
499
- if @output.string.end_with?("\n")
500
- @output.seek(-1, IO::SEEK_CUR) # 改行文字を取り除く
501
- #@output.string.chomp! # これだとヌル文字が入ってしまう
502
- end
503
- puts "</div>"
504
- puts "</li>"
505
- end
506
-
507
- ## キーと説明文のリスト
508
- def _render_desclist(opts, &b)
509
- bkup = @_desclist_opts
510
- @_desclist_opts = opts
511
- classnames = ['desc-list']
512
- classnames << 'compact' if opts[:compact]
513
- classnames << 'item-bold' if opts[:bold]
514
- classnames << opts[:classname] if opts[:classname]
515
- puts "<dl class=\"#{classnames.join(' ')}\">"
516
- yield
517
- puts "</dl>"
518
- @_desclist_opts = bkup
519
- end
520
-
521
- ## キーと説明文
522
- def _render_desc(key, &b)
523
- opts = @_desclist_opts
524
- s = compile_inline(key)
525
- s = "<b>#{s}</b>" if opts[:bold]
526
- puts " <dt class=\"desc\">#{s}</dt>"
527
- puts " <dd class=\"desc\">"
528
- yield
529
- puts " </dd>"
530
- end
531
-
532
- ## 縦方向の空きを入れる
533
- def _render_vspace(size)
534
- puts "<div class=\"vspace\" style=\"height:#{size}\"></div>"
535
- end
536
-
537
- def _render_addvspace(size)
538
- puts "<div class=\"addvspace\" style=\"height:#{size}\"></div>"
539
- end
540
-
541
- ## 章タイトルを独立したページに
542
- def makechaptitlepage(option=nil)
543
- puts '' # HTMLでは特に何もしない
544
- end
545
-
546
- ## 縦方向のスペースがなければ改ページ
547
- def _render_needvspace(height)
548
- puts "<div style=\"height:#{height}\"></div>"
549
- end
550
-
551
- ## 段(Paragraph)の終わりにスペースを入れる
552
- def paragraphend()
553
- puts '' # HTMLでは特に何もしない
554
- end
555
-
556
- ## 小段(Subparagraph)の終わりにスペースを入れる(あれば)
557
- def subparagraphend()
558
- puts '' # HTMLでは特に何もしない
559
- end
560
-
561
- ## 引用(複数段落に対応)
562
- def blockquote(lines)
563
- puts '<blockquote class="blockquote">'
564
- puts lines
565
- puts '</blockquote>'
566
- end
567
-
568
- ## 引用(//quote{ ... //})
569
- ## (入れ子対応なので、中に箇条書きや別のブロックを入れられる)
570
- def on_quote_block()
571
- puts '<blockquote class="blockquote">'
572
- yield
573
- puts '</blockquote>'
574
- end
575
- def quote(lines)
576
- on_quote_block() do
577
- puts lines
578
- end
579
- end
580
-
581
- ## 引用 (====[quote] ... ====[/quote])
582
- ## (ブロック構文ではないので、中に別のブロックや箇条書きを入れられる)
583
- def quote_begin(level, label, caption)
584
- puts '<blockquote class="blockquote">'
585
- end
586
- def quote_end(level)
587
- puts '</blockquote>'
588
- end
589
-
590
- ## ノート(//note{ ... //})
591
- ## (入れ子対応なので、中に箇条書きや別のブロックを入れられる)
592
- def on_note_block(label=nil, caption=nil)
593
- with_context(:minicolumn) do
594
- caption, label = label, nil if caption.nil?
595
- if label
596
- puts "<div class=\"note\" id=\"#{label}\">"
597
- else
598
- puts "<div class=\"note\">"
599
- end
600
- puts "<h5>#{compile_inline(caption)}</h5>" if caption.present?
601
- yield
602
- puts "</div>"
603
- end
604
- end
605
- def note(lines, label=nil, caption=nil)
606
- on_quote_block(label, caption) do
607
- puts lines
608
- end
609
- end
610
-
611
- ## ノート (====[note] ... ====[/note])
612
- ## (ブロック構文ではないので、中に別のブロックや箇条書きを入れられる)
613
- def note_begin(level, label, caption)
614
- s = compile_inline(caption || "")
615
- puts "<div class=\"note\">"
616
- puts "<h5>#{s}</h5>" if s.present?
617
- end
618
- def note_end(level)
619
- puts "</div>"
620
- end
621
-
622
- ## テーブル
623
- def table(lines, id=nil, caption=nil, option=nil)
624
- super
625
- end
626
-
627
- def table_header(id, caption, options)
628
- if id.present?
629
- begin
630
- num = @chapter.table(id).number
631
- rescue KeyError
632
- error "no such table: #{id}"
633
- end
634
- s1 = I18n.t('table')
635
- s2 = get_chap() \
636
- ? I18n.t('format_number_header', [get_chap(), num]) \
637
- : I18n.t('format_number_header_without_chapter', [num])
638
- s3 = I18n.t('caption_prefix')
639
- puts "<p class=\"caption\">#{s1}#{s2}#{s3}#{compile_inline(caption||'')}</p>"
640
- elsif caption.present?
641
- puts "<p class=\"caption\">#{compile_inline(caption||'')}</p>"
642
- end
643
- end
644
-
645
- def table_begin(_ncols, fontsize: nil)
646
- if fontsize
647
- puts "<table style=\"font-size:#{fontsize}\">"
648
- else
649
- puts "<table>"
650
- end
651
- end
652
-
653
- protected
654
-
655
- def _table_before(id, caption, opts)
656
- class_ = opts[:csv] ? "table table-nohline" : "table"
657
- if id.present?
658
- puts "<div id=\"#{normalize_id(id)}\" class=\"#{class_}\">"
659
- else
660
- puts "<div class=\"#{class_}\">"
661
- end
662
- end
663
-
664
- def _table_after(id, caption, opts)
665
- puts "</div>"
666
- end
667
-
668
- def _table_bottom(hline: false)
669
- end
670
-
671
- def _table_tr(cells, hline: false)
672
- if hline
673
- "<tr class=\"hline\">#{cells.join}</tr>"
674
- else
675
- "<tr>#{cells.join}</tr>"
676
- end
677
- end
678
-
679
- public
680
-
681
- ## //imgtable
682
- def imgtable(lines, id, caption=nil, option=nil)
683
- super
684
- end
685
-
686
- protected
687
-
688
- def _render_imgtable(id, caption, opts)
689
- puts "<div id=\"#{normalize_id(id)}\" class=\"imgtable image\">"
690
- table_header(id, caption, opts)
691
- puts " <div>"
692
- yield
693
- puts " </div>"
694
- puts "</div>"
695
- end
696
-
697
- def _render_imgtable_caption(caption)
698
- end
699
-
700
- def _render_imgtable_label(id)
701
- end
702
-
703
- public
704
-
705
- #### インライン命令
706
-
707
- def inline_fn(id)
708
- if @book.config['epubversion'].to_i == 3
709
- type = " epub:type=\"noteref\""
710
- else
711
- type = ""
712
- end
713
- return "<sup><a id=\"fnb-#{normalize_id(id)}\" href=\"#fn-#{normalize_id(id)}\" class=\"noteref\"#{type}>*#{@chapter.footnote(id).number}</a></sup>"
714
- rescue KeyError
715
- error "unknown footnote: #{id}"
716
- end
717
-
718
- ## 改段落(箇条書き内では空行を入れられないため)
719
- def inline_par(arg)
720
- case arg
721
- when 'i'
722
- "<p class=\"indent\">"
723
- else
724
- "<p>"
725
- end
726
- end
727
-
728
- ## ファイル名
729
- def inline_file(str)
730
- on_inline_file { escape(str) }
731
- end
732
- def on_inline_file
733
- "<span class=\"file\">#{yield}</span>"
734
- end
735
-
736
- ## ユーザ入力
737
- def inline_userinput(str)
738
- on_inline_input { escape(str) }
739
- end
740
- def on_inline_userinput
741
- "<span class=\"userinput\">#{yield}</span>"
742
- end
743
-
744
- ## 引数をそのまま表示 (No Operation)
745
- def inline_nop(str)
746
- escape_html(str || "")
747
- end
748
- alias inline_letitgo inline_nop
749
-
750
- ## 目立たせない(@<strong>{} の反対)
751
- def inline_weak(str)
752
- on_inline_weak { escape(str) }
753
- end
754
- def on_inline_weak
755
- "<span class=\"weak\">#{yield}</span>"
756
- end
757
-
758
- ## 文字を小さくする
759
- def inline_small(str) ; on_inline_small { escape(str) } ; end
760
- def inline_xsmall(str) ; on_inline_xsmall { escape(str) } ; end
761
- def inline_xxsmall(str) ; on_inline_xxsmall { escape(str) } ; end
762
-
763
- def on_inline_small ; "<small style=\"font-size:small\">#{yield}</small>" ; end
764
- def on_inline_xsmall ; "<small style=\"font-size:x-small\">#{yield}</small>" ; end
765
- def on_inline_xxsmall ; "<small style=\"font-size:xx-small\">#{yield}</small>"; end
766
-
767
- ## 文字を大きくする
768
- def inline_large(str) ; on_inline_large { escape(str) } ; end
769
- def inline_xlarge(str) ; on_inline_xlarge { escape(str) } ; end
770
- def inline_xxlarge(str) ; on_inline_xxlarge { escape(str) } ; end
771
- def on_inline_large ; "<span style=\"font-size:large\">#{yield}</span>" ; end
772
- def on_inline_xlarge ; "<span style=\"font-size:x-large\">#{yield}</span>" ; end
773
- def on_inline_xxlarge ; "<span style=\"font-size:xx-large\">#{yield}</span>"; end
774
-
775
- ## 文字を大きくした@<strong>{}
776
- def inline_xstrong(str) ; on_inline_xstrong { escape(str) }; end
777
- def inline_xxstrong(str); on_inline_xxstrong { escape(str) }; end
778
- def on_inline_xstrong ; "<span style=\"font-size:x-large\">#{yield}</span>"; end
779
- def on_inline_xxstrong; "<span style=\"font-size:xx-large\">#{yield}</span>"; end
780
-
781
- ## コードブロック中で折り返し箇所を手動で指定する
782
- def inline_foldhere(arg)
783
- '<br>'
784
- end
785
-
786
- ## ターミナルでのカーソル(背景が白、文字が黒)
787
- def inline_cursor(str)
788
- "<span class=\"cursor\">#{escape_html(str)}</span>"
789
- end
790
-
791
- ## nestable inline commands
792
-
793
- def on_inline_i() ; "<i>#{yield}</i>" ; end
794
- def on_inline_b() ; "<b>#{yield}</b>" ; end
795
- #def on_inline_code() ; "<code>#{yield}</code>" ; end
796
- def on_inline_tt() ; "<tt>#{yield}</tt>" ; end
797
- def on_inline_del() ; "<s>#{yield}</s>" ; end
798
- def on_inline_sub() ; "<sub>#{yield}</sub>" ; end
799
- def on_inline_sup() ; "<sup>#{yield}</sup>" ; end
800
- def on_inline_em() ; "<em>#{yield}</em>" ; end
801
- def on_inline_strong(); "<strong>#{yield}</strong>" ; end
802
- def on_inline_u() ; "<u>#{yield}</u>" ; end
803
- def on_inline_ami() ; "<span class=\"ami\">#{yield}</span>"; end
804
- def on_inline_balloon(); "<span class=\"balloon\">← #{yield}</span>"; end
805
-
806
- def on_inline_code()
807
- return "<code class=\"inline-code\">#{yield}</code>"
808
- end
809
-
810
- ## 「“」と「”」で囲む
811
- def on_inline_qq()
812
- "“#{yield}”"
813
- end
814
-
815
- def build_inline_href(url, escaped_label) # compile_href()をベースに改造
816
- flag_link = @book.config['externallink']
817
- return _inline_hyperlink(url, escaped_label, flag_link)
818
- end
819
-
820
- def inline_hlink(str)
821
- url, label = str.split(/, /, 2)
822
- flag_link = @book.config['externallink']
823
- label_ = label.present? ? escape(label) : nil
824
- return _inline_hyperlink(url, label_, flag_link)
825
- end
826
-
827
- def _inline_hyperlink(url, escaped_label, flag_link)
828
- if flag_link
829
- label = escaped_label || escape_html(url)
830
- "<a href=\"#{escape_html(url)}\" class=\"link\">#{label}</a>"
831
- elsif escaped_label
832
- I18n.t('external_link', [escaped_label, escape_html(url)])
833
- else
834
- escape_html(url)
835
- end
836
- end
837
- private :_inline_hyperlink
838
-
839
- def build_inline_ruby(escaped_word, escaped_yomi) # compile_ruby()をベースに改造
840
- pre = I18n.t('ruby_prefix'); post = I18n.t('ruby_postfix')
841
- if @book.htmlversion == 5
842
- "<ruby>#{escaped_word}<rp>#{pre}</rp><rt>#{escaped_yomi}</rt><rp>#{post}</rp></ruby>"
843
- else
844
- "<ruby><rb>#{escaped_word}</rb><rp>#{pre}</rp><rt>#{escaped_yomi}</rt><rp>#{post}</rp></ruby>"
845
- end
846
- end
847
-
848
- protected
849
-
850
- ## ノートを参照する
851
- def build_noteref(chapter, label, caption)
852
- href = chapter ? "#{chapter.id}#{extname()}##{label}" : "##{label}"
853
- %Q`ノート「<a href="#{href}">#{escape(caption)}</a>」`
854
- end
855
-
856
- ## 数式を参照する
857
- def build_eq(chapter, label, number)
858
- s = "#{I18n.t('equation')}#{chapter.number}.#{number}"
859
- "<a>#{escape(s)}</a>"
860
- end
861
-
862
- ## 索引に載せる語句 (@<idx>{}, @<term>{})
863
- public
864
- def inline_idx(str)
865
- s1, s2 = _compile_term(str)
866
- %Q`<span class="index" title="#{s2}">#{s1}</span>`
867
- end
868
- def inline_hidx(str)
869
- _, s2 = _compile_term(str)
870
- %Q`<span class="index" title="#{s2}"></span>`
871
- end
872
- def inline_term(str)
873
- s1, s2 = _compile_term(str)
874
- %Q`<span class="index term" title="#{s2}">#{s1}</span>`
875
- end
876
- def on_inline_termnoidx(str)
877
- %Q`<span class="term">#{yield}</span>`
878
- end
879
-
880
- def _compile_term(str)
881
- arr = []
882
- placeholder = "---"
883
- display_str, see = parse_term(str, placeholder) do |term, term_e, yomi|
884
- if yomi
885
- arr << escape(yomi)
886
- else
887
- arr << term_e
888
- end
889
- end
890
- title_attr = arr.join()
891
- title_attr += " → see: #{escape(see)}" if see
892
- return display_str, title_attr
893
- end
894
- private :_compile_term
895
-
896
- end
897
-
898
-
899
- class TEXTBuilder
900
-
901
- def target_name
902
- "text"
903
- end
904
-
905
- ## nestable inline commands
906
-
907
- def on_inline_i() ; "<i>#{yield}</i>" ; end
908
- def on_inline_b() ; "<b>#{yield}</b>" ; end
909
- def on_inline_code() ; "<code>#{yield}</code>" ; end
910
- def on_inline_tt() ; "<tt>#{yield}</tt>" ; end
911
- def on_inline_del() ; "<s>#{yield}</s>" ; end
912
- def on_inline_sub() ; "<sub>#{yield}</sub>" ; end
913
- def on_inline_sup() ; "<sup>#{yield}</sup>" ; end
914
- def on_inline_em() ; "<em>#{yield}</em>" ; end
915
- def on_inline_strong(); "<strong>#{yield}</strong>" ; end
916
- def on_inline_u() ; "<u>#{yield}</u>" ; end
917
- def on_inline_ami() ; "<span class=\"ami\">#{yield}</span>"; end
918
-
919
- def build_inline_href(url, escaped_label) # compile_href()をベースに改造
920
- if @book.config['externallink']
921
- label = escaped_label || escape_html(url)
922
- "<a href=\"#{escape_html(url)}\" class=\"link\">#{label}</a>"
923
- elsif escaped_label
924
- I18n.t('external_link', [escaped_label, escape_html(url)])
925
- else
926
- escape_html(url)
927
- end
928
- end
929
-
930
- def build_inline_ruby(escaped_word, escaped_yomi) # compile_ruby()をベースに改造
931
- pre = I18n.t('ruby_prefix'); post = I18n.t('ruby_postfix')
932
- if @book.htmlversion == 5
933
- "<ruby>#{escaped_word}<rp>#{pre}</rp><rt>#{escaped_yomi}</rt><rp>#{post}</rp></ruby>"
934
- else
935
- "<ruby><rb>#{escaped_word}</rb><rp>#{pre}</rp><rt>#{escaped_yomi}</rt><rp>#{post}</rp></ruby>"
936
- end
937
- end
938
-
939
- ## その他
940
-
941
- def inline_nop(str)
942
- str || ''
943
- end
944
- alias inline_letitgo inline_nop
945
-
946
- end
947
-
948
-
949
- end