Class: ReVIEW::MARKDOWNBuilder
Constant Summary
Constants included
from HTMLUtils
HTMLUtils::ESC
Constants inherited
from Builder
Builder::CAPTION_TITLES
Instance Method Summary
collapse
-
#blank ⇒ Object
-
#cmd(lines) ⇒ Object
-
#comment(lines, comment = nil) ⇒ Object
-
#compile_href(url, label) ⇒ Object
-
#compile_ruby(base, ruby) ⇒ Object
-
#dd(lines) ⇒ Object
-
#dl_begin ⇒ Object
-
#dl_end ⇒ Object
-
#dt(line) ⇒ Object
-
#emlist(lines, caption = nil, lang = nil) ⇒ Object
-
#extname ⇒ Object
-
#footnote(id, str) ⇒ Object
-
#headline(level, _label, caption) ⇒ Object
-
#hr ⇒ Object
-
#image_dummy(_id, _caption, lines) ⇒ Object
-
#image_ext ⇒ Object
-
#image_image(id, caption, _metric) ⇒ Object
-
#indepimage(_lines, id, caption = '', _metric = nil) ⇒ Object
-
#inline_b(str) ⇒ Object
-
#inline_br(_str) ⇒ Object
-
#inline_code(str) ⇒ Object
-
#inline_comment(str) ⇒ Object
-
#inline_em(str) ⇒ Object
-
#inline_fn(id) ⇒ Object
-
#inline_i(str) ⇒ Object
-
#inline_img(id) ⇒ Object
-
#inline_strong(str) ⇒ Object
-
#inline_tt(str) ⇒ Object
-
#list_body(_id, lines, _lang) ⇒ Object
-
#list_header(id, caption, lang) ⇒ Object
-
#nofunc_text(str) ⇒ Object
-
#ol_begin ⇒ Object
-
#ol_end ⇒ Object
-
#ol_item(lines, num) ⇒ Object
-
#pagebreak ⇒ Object
-
#paragraph(lines) ⇒ Object
-
#puts(str) ⇒ Object
-
#quote(lines) ⇒ Object
-
#table(lines, id = nil, caption = nil) ⇒ Object
-
#table_begin(ncols) ⇒ Object
-
#table_border(ncols) ⇒ Object
-
#table_end ⇒ Object
-
#table_header(id, caption) ⇒ Object
-
#td(str) ⇒ Object
-
#th(str) ⇒ Object
-
#tr(rows) ⇒ Object
-
#ul_begin ⇒ Object
-
#ul_end ⇒ Object
-
#ul_item_begin(lines) ⇒ Object
-
#ul_item_end ⇒ Object
Methods included from HTMLUtils
#escape_comment, #escape_html, #highlight, #highlight?, #highlight_pygments, #highlight_rouge, #normalize_id, #strip_html, #unescape_html
Methods included from TextUtils
#detab, #split_paragraph
Methods inherited from Builder
#bibpaper, #bind, #captionblock, #compile_inline, #detab, #embed, #emtable, #error, #extract_chapter_id, #firstlinenum, #get_chap, #graph, #handle_metric, #image, #include, #initialize, #inline_bou, #inline_chap, #inline_chapref, #inline_column, #inline_column_chap, #inline_embed, #inline_hd, #inline_href, #inline_imgref, #inline_include, #inline_kw, #inline_list, #inline_pageref, #inline_raw, #inline_ruby, #inline_table, #inline_tcy, #inline_title, #line_num, #list, #listnum, #parse_metric, #post_paragraph, #pre_paragraph, #print, #raw, #result, #result_metric, #source, #target_name, #text, #tsize, #warn
Instance Method Details
30
31
32
33
|
# File 'lib/review/markdownbuilder.rb', line 30
def blank
@output.puts unless @blank_seen
@blank_seen = true
end
|
#cmd(lines) ⇒ Object
194
195
196
197
198
|
# File 'lib/review/markdownbuilder.rb', line 194
def cmd(lines)
puts '```shell-session'
lines.each { |line| puts detab(line) }
puts '```'
end
|
297
298
299
300
301
302
303
|
# File 'lib/review/markdownbuilder.rb', line 297
def (lines, = nil)
return unless @book.config['draft']
lines ||= []
lines.unshift unless .blank?
str = lines.join('<br />')
puts %Q(<div class="red">#{escape_html(str)}</div>)
end
|
#compile_href(url, label) ⇒ Object
134
135
136
137
|
# File 'lib/review/markdownbuilder.rb', line 134
def compile_href(url, label)
label = url if label.blank?
"[#{label}](#{url})"
end
|
#compile_ruby(base, ruby) ⇒ Object
289
290
291
292
293
294
295
|
# File 'lib/review/markdownbuilder.rb', line 289
def compile_ruby(base, ruby)
if @book.htmlversion == 5
%Q(<ruby>#{escape_html(base)}<rp>#{I18n.t('ruby_prefix')}</rp><rt>#{escape_html(ruby)}</rt><rp>#{I18n.t('ruby_postfix')}</rp></ruby>)
else
%Q(<ruby><rb>#{escape_html(base)}</rb><rp>#{I18n.t('ruby_prefix')}</rp><rt>#{ruby}</rt><rp>#{I18n.t('ruby_postfix')}</rp></ruby>)
end
end
|
#dd(lines) ⇒ Object
107
108
109
|
# File 'lib/review/markdownbuilder.rb', line 107
def dd(lines)
puts "<dd>#{lines.join}</dd>"
end
|
99
100
101
|
# File 'lib/review/markdownbuilder.rb', line 99
def dl_begin
puts '<dl>'
end
|
111
112
113
|
# File 'lib/review/markdownbuilder.rb', line 111
def dl_end
puts '</dl>'
end
|
103
104
105
|
# File 'lib/review/markdownbuilder.rb', line 103
def dt(line)
puts "<dt>#{line}</dt>"
end
|
#emlist(lines, caption = nil, lang = nil) ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/review/markdownbuilder.rb', line 115
def emlist(lines, caption = nil, lang = nil)
blank
if caption
puts caption
print "\n"
end
lang ||= ''
puts "```#{lang}"
lines.each do |line|
puts detab(line)
end
puts '```'
blank
end
|
14
15
16
|
# File 'lib/review/markdownbuilder.rb', line 14
def extname
'.md'
end
|
272
273
274
275
|
# File 'lib/review/markdownbuilder.rb', line 272
def (id, str)
puts "[^#{id}]: #{compile_inline(str)}"
blank
end
|
#headline(level, _label, caption) ⇒ Object
35
36
37
38
39
40
|
# File 'lib/review/markdownbuilder.rb', line 35
def headline(level, _label, caption)
blank
prefix = '#' * level
puts "#{prefix} #{caption}"
blank
end
|
130
131
132
|
# File 'lib/review/markdownbuilder.rb', line 130
def hr
puts '----'
end
|
#image_dummy(_id, _caption, lines) ⇒ Object
169
170
171
|
# File 'lib/review/markdownbuilder.rb', line 169
def image_dummy(_id, _caption, lines)
puts lines.join
end
|
#image_ext ⇒ Object
190
191
192
|
# File 'lib/review/markdownbuilder.rb', line 190
def image_ext
'jpg'
end
|
#image_image(id, caption, _metric) ⇒ Object
163
164
165
166
167
|
# File 'lib/review/markdownbuilder.rb', line 163
def image_image(id, caption, _metric)
blank
puts ".path.sub(%r{\A\./}, '')})"
blank
end
|
#indepimage(_lines, id, caption = '', _metric = nil) ⇒ Object
180
181
182
183
184
|
# File 'lib/review/markdownbuilder.rb', line 180
def indepimage(_lines, id, caption = '', _metric = nil)
blank
puts ".path.sub(%r{\A\./}, '')})"
blank
end
|
#inline_b(str) ⇒ Object
147
148
149
|
# File 'lib/review/markdownbuilder.rb', line 147
def inline_b(str)
"**#{str.gsub(/\*/, '\*')}**"
end
|
#inline_br(_str) ⇒ Object
281
282
283
|
# File 'lib/review/markdownbuilder.rb', line 281
def inline_br(_str)
"\n"
end
|
#inline_code(str) ⇒ Object
155
156
157
|
# File 'lib/review/markdownbuilder.rb', line 155
def inline_code(str)
"`#{str}`"
end
|
305
306
307
308
309
310
311
|
# File 'lib/review/markdownbuilder.rb', line 305
def (str)
if @book.config['draft']
%Q(<span class="red">#{escape_html(str)}</span>)
else
''
end
end
|
#inline_em(str) ⇒ Object
143
144
145
|
# File 'lib/review/markdownbuilder.rb', line 143
def inline_em(str)
"*#{str.gsub(/\*/, '\*')}*"
end
|
#inline_fn(id) ⇒ Object
277
278
279
|
# File 'lib/review/markdownbuilder.rb', line 277
def inline_fn(id)
"[^#{id}]"
end
|
#inline_i(str) ⇒ Object
139
140
141
|
# File 'lib/review/markdownbuilder.rb', line 139
def inline_i(str)
"*#{str.gsub(/\*/, '\*')}*"
end
|
#inline_img(id) ⇒ Object
173
174
175
176
177
178
|
# File 'lib/review/markdownbuilder.rb', line 173
def inline_img(id)
"#{I18n.t('image')}#{@chapter.image(id).number}"
rescue KeyError
error "unknown image: #{id}"
nofunc_text("[UnknownImage:#{id}]")
end
|
#inline_strong(str) ⇒ Object
151
152
153
|
# File 'lib/review/markdownbuilder.rb', line 151
def inline_strong(str)
"**#{str.gsub(/\*/, '\*')}**"
end
|
#inline_tt(str) ⇒ Object
159
160
161
|
# File 'lib/review/markdownbuilder.rb', line 159
def inline_tt(str)
"`#{str}`"
end
|
#list_body(_id, lines, _lang) ⇒ Object
63
64
65
66
67
68
|
# File 'lib/review/markdownbuilder.rb', line 63
def list_body(_id, lines, _lang)
lines.each do |line|
puts detab(line)
end
puts '```'
end
|
53
54
55
56
57
58
59
60
61
|
# File 'lib/review/markdownbuilder.rb', line 53
def (id, caption, lang)
if get_chap.nil?
print %Q(リスト#{@chapter.list(id).number} #{compile_inline(caption)}\n\n)
else
print %Q(リスト#{get_chap}.#{@chapter.list(id).number} #{compile_inline(caption)}\n\n)
end
lang ||= ''
puts "```#{lang}"
end
|
#nofunc_text(str) ⇒ Object
285
286
287
|
# File 'lib/review/markdownbuilder.rb', line 285
def nofunc_text(str)
str
end
|
87
88
89
|
# File 'lib/review/markdownbuilder.rb', line 87
def ol_begin
blank
end
|
95
96
97
|
# File 'lib/review/markdownbuilder.rb', line 95
def ol_end
blank
end
|
#ol_item(lines, num) ⇒ Object
91
92
93
|
# File 'lib/review/markdownbuilder.rb', line 91
def ol_item(lines, num)
puts "#{num}. #{lines.join}"
end
|
#pagebreak ⇒ Object
186
187
188
|
# File 'lib/review/markdownbuilder.rb', line 186
def pagebreak
puts '{pagebreak}'
end
|
#paragraph(lines) ⇒ Object
48
49
50
51
|
# File 'lib/review/markdownbuilder.rb', line 48
def paragraph(lines)
puts lines.join
puts "\n"
end
|
#puts(str) ⇒ Object
25
26
27
28
|
# File 'lib/review/markdownbuilder.rb', line 25
def puts(str)
@blank_seen = false
super
end
|
#quote(lines) ⇒ Object
42
43
44
45
46
|
# File 'lib/review/markdownbuilder.rb', line 42
def quote(lines)
blank
puts split_paragraph(lines).map { |line| "> #{line}" }.join("\n> \n")
blank
end
|
#table(lines, id = nil, caption = nil) ⇒ Object
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
# File 'lib/review/markdownbuilder.rb', line 200
def table(lines, id = nil, caption = nil)
rows = []
sepidx = nil
lines.each_with_index do |line, idx|
if /\A[\=\-]{12}/ =~ line
sepidx ||= idx
next
end
rows.push(line.strip.split(/\t+/).map { |s| s.sub(/\A\./, '') })
end
rows = adjust_n_cols(rows)
begin
id, caption unless caption.nil?
rescue KeyError
error "no such table: #{id}"
end
table_begin rows.first.size
return if rows.empty?
if sepidx
sepidx.times do
tr(rows.shift.map { |s| th(s) })
end
table_border rows.first.size
rows.each do |cols|
tr(cols.map { |s| td(s) })
end
else
rows.each do |cols|
h, *cs = *cols
tr([th(h)] + cs.map { |s| td(s) })
end
end
table_end
end
|
#table_begin(ncols) ⇒ Object
249
250
|
# File 'lib/review/markdownbuilder.rb', line 249
def table_begin(ncols)
end
|
#table_border(ncols) ⇒ Object
256
257
258
|
# File 'lib/review/markdownbuilder.rb', line 256
def table_border(ncols)
puts((0..ncols).map { '|' }.join(':--'))
end
|
#table_end ⇒ Object
268
269
270
|
# File 'lib/review/markdownbuilder.rb', line 268
def table_end
blank
end
|
238
239
240
241
242
243
244
245
246
247
|
# File 'lib/review/markdownbuilder.rb', line 238
def (id, caption)
if id.nil?
puts compile_inline(caption)
elsif get_chap
puts %Q(#{I18n.t('table')}#{I18n.t('format_number_header', [get_chap, @chapter.table(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)})
else
puts %Q(#{I18n.t('table')}#{I18n.t('format_number_header_without_chapter', [@chapter.table(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)})
end
blank
end
|
264
265
266
|
# File 'lib/review/markdownbuilder.rb', line 264
def td(str)
str
end
|
260
261
262
|
# File 'lib/review/markdownbuilder.rb', line 260
def th(str)
str
end
|
252
253
254
|
# File 'lib/review/markdownbuilder.rb', line 252
def tr(rows)
puts "|#{rows.join('|')}|"
end
|
70
71
72
73
|
# File 'lib/review/markdownbuilder.rb', line 70
def ul_begin
blank if @ul_indent == 0
@ul_indent += 1
end
|
82
83
84
85
|
# File 'lib/review/markdownbuilder.rb', line 82
def ul_end
@ul_indent -= 1
blank if @ul_indent == 0
end
|
#ul_item_begin(lines) ⇒ Object
75
76
77
|
# File 'lib/review/markdownbuilder.rb', line 75
def ul_item_begin(lines)
puts ' ' * (@ul_indent - 1) + '* ' + lines.join
end
|
#ul_item_end ⇒ Object
79
80
|
# File 'lib/review/markdownbuilder.rb', line 79
def ul_item_end
end
|