class ReVIEW::HTMLBuilder
Public Instance Methods
best(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 257 def best(lines, caption = nil) captionblock('best', lines, caption) end
bibpaper(lines, id, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 979 def bibpaper(lines, id, caption) puts %Q(<div class="bibpaper">) bibpaper_header id, caption bibpaper_bibpaper id, caption, lines unless lines.empty? puts '</div>' end
bibpaper_bibpaper(_id, _caption, lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 993 def bibpaper_bibpaper(_id, _caption, lines) print split_paragraph(lines).join end
bibpaper_header(id, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 986 def bibpaper_header(id, caption) print %Q(<a id="bib-#{normalize_id(id)}">) print "[#{@chapter.bibpaper(id).number}]" print '</a>' puts " #{compile_inline(caption)}" end
blankline()
click to toggle source
# File lib/review/htmlbuilder.rb, line 806 def blankline puts '<p><br /></p>' end
box(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 289 def box(lines, caption = nil) puts %Q(<div class="syntax">) if caption.present? puts %Q(<p class="caption">#{compile_inline(caption)}</p>) end print %Q(<pre class="syntax">) lines.each do |line| puts detab(line) end puts '</pre>' puts '</div>' end
bpo(lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 814 def bpo(lines) puts '<bpo>' lines.each do |line| puts detab(line) end puts '</bpo>' end
captionblock(type, lines, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 231 def captionblock(type, lines, caption) puts %Q(<div class="#{type}">) if caption.present? puts %Q(<p class="caption">#{compile_inline(caption)}</p>) end blocked_lines = split_paragraph(lines) puts blocked_lines.join("\n") puts '</div>' end
caution(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 269 def caution(lines, caption = nil) captionblock('caution', lines, caption) end
centering(lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1210 def centering(lines) puts split_paragraph(lines).join("\n").gsub('<p>', %Q(<p class="center">)) end
cmd(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 500 def cmd(lines, caption = nil) puts %Q(<div class="cmd-code">) if caption.present? puts %Q(<p class="caption">#{compile_inline(caption)}</p>) end print %Q(<pre class="cmd">) body = lines.inject('') { |i, j| i + detab(j) + "\n" } lexer = 'shell-session' puts highlight(body: body, lexer: lexer, format: 'html') puts '</pre>' puts '</div>' end
column_begin(level, label, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 184 def column_begin(level, label, caption) puts %Q(<div class="column">) @column += 1 puts if level > 1 a_id = %Q(<a id="column-#{@column}"></a>) if caption.empty? puts a_id if label elsif label puts %Q(<h#{level} id="#{normalize_id(label)}">#{a_id}#{compile_inline(caption)}</h#{level}>) else puts %Q(<h#{level}>#{a_id}#{compile_inline(caption)}</h#{level}>) end end
column_end(_level)
click to toggle source
# File lib/review/htmlbuilder.rb, line 200 def column_end(_level) puts '</div>' end
comment(lines, comment = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 750 def comment(lines, comment = nil) return unless @book.config['draft'] lines ||= [] lines.unshift escape(comment) unless comment.blank? str = lines.join('<br />') puts %Q(<div class="draft-comment">#{str}</div>) end
compile_href(url, label)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1198 def compile_href(url, label) if @book.config['externallink'] %Q(<a href="#{escape(url)}" class="link">#{label.nil? ? escape(url) : escape(label)}</a>) else label.nil? ? escape(url) : I18n.t('external_link', [escape(label), escape(url)]) end end
compile_kw(word, alt)
click to toggle source
# File lib/review/htmlbuilder.rb, line 886 def compile_kw(word, alt) %Q(<b class="kw">) + if alt then escape(word + " (#{alt.strip})") else escape(word) end + "</b><!-- IDX:#{escape_comment(escape(word))} -->" end
compile_ruby(base, ruby)
click to toggle source
# File lib/review/htmlbuilder.rb, line 878 def compile_ruby(base, ruby) if @book.htmlversion == 5 %Q(<ruby>#{escape(base)}<rp>#{I18n.t('ruby_prefix')}</rp><rt>#{escape(ruby)}</rt><rp>#{I18n.t('ruby_postfix')}</rp></ruby>) else %Q(<ruby><rb>#{escape(base)}</rb><rp>#{I18n.t('ruby_prefix')}</rp><rt>#{ruby}</rt><rp>#{I18n.t('ruby_postfix')}</rp></ruby>) end end
dd(lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 347 def dd(lines) puts "<dd>#{lines.join}</dd>" end
defer_math_image(str, path, key)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1222 def defer_math_image(str, path, key) # for Re:VIEW >3 File.open(File.join(File.dirname(path), '__IMGMATH_BODY__.tex'), 'a+') do |f| f.puts str f.puts '\\clearpage' end File.open(File.join(File.dirname(path), '__IMGMATH_BODY__.map'), 'a+') do |f| f.puts key end end
dl_begin()
click to toggle source
# File lib/review/htmlbuilder.rb, line 339 def dl_begin puts '<dl>' end
dl_end()
click to toggle source
# File lib/review/htmlbuilder.rb, line 351 def dl_end puts '</dl>' end
doorquote(lines, ref)
click to toggle source
# File lib/review/htmlbuilder.rb, line 527 def doorquote(lines, ref) blocked_lines = split_paragraph(lines) puts %Q(<blockquote style="text-align:right;">) puts blocked_lines.join("\n") puts %Q(<p>#{ref}より</p>) puts '</blockquote>' end
dt(line)
click to toggle source
# File lib/review/htmlbuilder.rb, line 343 def dt(line) puts "<dt>#{line}</dt>" end
emlist(lines, caption = nil, lang = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 457 def emlist(lines, caption = nil, lang = nil) puts %Q(<div class="emlist-code">) if caption.present? puts %Q(<p class="caption">#{compile_inline(caption)}</p>) end class_names = ['emlist'] class_names.push("language-#{lang}") unless lang.blank? class_names.push('highlight') if highlight? print %Q(<pre class="#{class_names.join(' ')}">) body = lines.inject('') { |i, j| i + detab(j) + "\n" } lexer = lang puts highlight(body: body, lexer: lexer, format: 'html') puts '</pre>' puts '</div>' end
emlistnum(lines, caption = nil, lang = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 473 def emlistnum(lines, caption = nil, lang = nil) puts %Q(<div class="emlistnum-code">) if caption.present? puts %Q(<p class="caption">#{compile_inline(caption)}</p>) end body = lines.inject('') { |i, j| i + detab(j) + "\n" } lexer = lang first_line_number = line_num hs = highlight(body: body, lexer: lexer, format: 'html', linenum: true, options: { linenostart: first_line_number }) if highlight? puts hs else class_names = ['emlist'] class_names.push("language-#{lang}") unless lang.blank? class_names.push('highlight') if highlight? print %Q(<pre class="#{class_names.join(' ')}">) hs.split("\n").each_with_index do |line, i| puts detab((i + first_line_number).to_s.rjust(2) + ': ' + line) end puts '</pre>' end puts '</div>' end
emtable(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 746 def emtable(lines, caption = nil) table(lines, nil, caption) end
extname()
click to toggle source
# File lib/review/htmlbuilder.rb, line 41 def extname ".#{@book.config['htmlext']}" end
flushright(lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1206 def flushright(lines) puts split_paragraph(lines).join("\n").gsub('<p>', %Q(<p class="flushright">)) end
footnote(id, str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 758 def footnote(id, str) if @book.config['epubversion'].to_i == 3 back = '' if @book.config['epubmaker'] && @book.config['epubmaker']['back_footnote'] back = %Q(<a href="#fnb-#{normalize_id(id)}">#{I18n.t('html_footnote_backmark')}</a>) end # XXX: back link must be located at first of p for Kindle. puts %Q(<div class="footnote" epub:type="footnote" id="fn-#{normalize_id(id)}"><p class="footnote">#{back}#{I18n.t('html_footnote_textmark', @chapter.footnote(id).number)}#{compile_inline(str)}</p></div>) else puts %Q(<div class="footnote" id="fn-#{normalize_id(id)}"><p class="footnote">[<a href="#fnb-#{normalize_id(id)}">*#{@chapter.footnote(id).number}</a>] #{compile_inline(str)}</p></div>) end end
handle_metric(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 593 def handle_metric(str) if str =~ /\Ascale=([\d.]+)\Z/ return { 'class' => sprintf('width-%03dper', ($1.to_f * 100).round) } end k, v = str.split('=', 2) { k => v.sub(/\A["']/, '').sub(/["']\Z/, '') } end
headline(level, label, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 119 def headline(level, label, caption) prefix, anchor = headline_prefix(level) if prefix prefix = %Q(<span class="secno">#{prefix}</span>) end puts '' if level > 1 a_id = '' if anchor a_id = %Q(<a id="h#{anchor}"></a>) end if caption.empty? puts a_id if label elsif label puts %Q(<h#{level} id="#{normalize_id(label)}">#{a_id}#{prefix}#{compile_inline(caption)}</h#{level}>) else puts %Q(<h#{level}>#{a_id}#{prefix}#{compile_inline(caption)}</h#{level}>) end end
hr()
click to toggle source
# File lib/review/htmlbuilder.rb, line 798 def hr puts '<hr />' end
image_dummy(id, caption, lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 623 def image_dummy(id, caption, lines) warn "image not bound: #{id}" puts %Q(<div id="#{normalize_id(id)}" class="image">) puts %Q(<pre class="dummyimage">) lines.each do |line| puts detab(line) end puts '</pre>' image_header id, caption puts '</div>' end
image_ext()
click to toggle source
# File lib/review/htmlbuilder.rb, line 1214 def image_ext 'png' end
image_header(id, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 635 def image_header(id, caption) puts %Q(<p class="caption">) if get_chap puts %Q(#{I18n.t('image')}#{I18n.t('format_number_header', [get_chap, @chapter.image(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}) else puts %Q(#{I18n.t('image')}#{I18n.t('format_number_header_without_chapter', [@chapter.image(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}) end puts '</p>' end
image_image(id, caption, metric)
click to toggle source
# File lib/review/htmlbuilder.rb, line 615 def image_image(id, caption, metric) metrics = parse_metric('html', metric) puts %Q(<div id="#{normalize_id(id)}" class="image">) puts %Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="#{escape(compile_inline(caption))}"#{metrics} />) image_header id, caption puts '</div>' end
imgtable(lines, id, caption = nil, metric = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 720 def imgtable(lines, id, caption = nil, metric = nil) unless @chapter.image(id).bound? warn "image not bound: #{id}" image_dummy id, caption, lines return end puts %Q(<div id="#{normalize_id(id)}" class="imgtable image">) begin if caption.present? table_header id, caption end rescue KeyError error "no such table: #{id}" end imgtable_image(id, caption, metric) puts '</div>' end
imgtable_image(id, caption, metric)
click to toggle source
# File lib/review/htmlbuilder.rb, line 741 def imgtable_image(id, caption, metric) metrics = parse_metric('html', metric) puts %Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="#{escape(compile_inline(caption))}"#{metrics} />) end
important(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 261 def important(lines, caption = nil) captionblock('important', lines, caption) end
indepimage(lines, id, caption = '', metric = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 771 def indepimage(lines, id, caption = '', metric = nil) metrics = parse_metric('html', metric) caption = '' unless caption.present? puts %Q(<div id="#{normalize_id(id)}" class="image">) begin puts %Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="#{escape(compile_inline(caption))}"#{metrics} />) rescue warn "image not bound: #{id}" if lines puts %Q(<pre class="dummyimage">) lines.each do |line| puts detab(line) end puts '</pre>' end end if caption.present? puts %Q(<p class="caption">) puts %Q(#{I18n.t('numberless_image')}#{I18n.t('caption_prefix')}#{compile_inline(caption)}) puts '</p>' end puts '</div>' end
Also aliased as: numberlessimage
info(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 249 def info(lines, caption = nil) captionblock('info', lines, caption) end
inline_abbr(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1080 def inline_abbr(str) inline_asis(str, 'abbr') end
inline_acronym(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1084 def inline_acronym(str) inline_asis(str, 'acronym') end
inline_ami(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 903 def inline_ami(str) %Q(<span class="ami">#{escape(str)}</span>) end
inline_asis(str, tag)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1076 def inline_asis(str, tag) %Q(<#{tag}>#{escape(str)}</#{tag}>) end
inline_b(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 899 def inline_b(str) %Q(<b>#{escape(str)}</b>) end
inline_balloon(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1186 def inline_balloon(str) %Q(<span class="balloon">#{escape_html(str)}</span>) end
inline_bib(id)
click to toggle source
# File lib/review/htmlbuilder.rb, line 997 def inline_bib(id) %Q(<a href="#{@book.bib_file.gsub(/\.re\Z/, ".#{@book.config['htmlext']}")}#bib-#{normalize_id(id)}">[#{@chapter.bibpaper(id).number}]</a>) rescue KeyError error "unknown bib: #{id}" end
inline_big(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1116 def inline_big(str) inline_asis(str, 'big') end
inline_bou(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 907 def inline_bou(str) %Q(<span class="bou">#{escape(str)}</span>) end
inline_br(_str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 947 def inline_br(_str) '<br />' end
inline_chap(id)
click to toggle source
# File lib/review/htmlbuilder.rb, line 847 def inline_chap(id) if @book.config['chapterlink'] %Q(<a href="./#{id}#{extname}">#{@book.chapter_index.number(id)}</a>) else @book.chapter_index.number(id) end rescue KeyError error "unknown chapter: #{id}" end
inline_chapref(id)
click to toggle source
Calls superclass method
ReVIEW::Builder#inline_chapref
# File lib/review/htmlbuilder.rb, line 836 def inline_chapref(id) title = super if @book.config['chapterlink'] %Q(<a href="./#{id}#{extname}">#{title}</a>) else title end rescue KeyError error "unknown chapter: #{id}" end
inline_cite(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1088 def inline_cite(str) inline_asis(str, 'cite') end
inline_code(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 931 def inline_code(str) if @book.htmlversion == 5 %Q(<code class="inline-code tt">#{escape(str)}</code>) else %Q(<tt class="inline-code">#{escape(str)}</tt>) end end
inline_column_chap(chapter, id)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1026 def inline_column_chap(chapter, id) if @book.config['chapterlink'] %Q(<a href="\##{column_label(id, chapter)}" class="columnref">#{I18n.t('column', compile_inline(chapter.column(id).caption))}</a>) else I18n.t('column', compile_inline(chapter.column(id).caption)) end rescue KeyError error "unknown column: #{id}" end
inline_comment(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1169 def inline_comment(str) if @book.config['draft'] %Q(<span class="draft-comment">#{escape(str)}</span>) else '' end end
inline_del(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1140 def inline_del(str) inline_asis(str, 'del') end
inline_dfn(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1092 def inline_dfn(str) inline_asis(str, 'dfn') end
inline_dtp(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 927 def inline_dtp(str) "<?dtp #{str} ?>" end
inline_em(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1096 def inline_em(str) inline_asis(str, 'em') end
inline_eq(id)
click to toggle source
Calls superclass method
ReVIEW::Builder#inline_eq
# File lib/review/htmlbuilder.rb, line 1066 def inline_eq(id) str = super(id) chapter, id = extract_chapter_id(id) if @book.config['chapterlink'] %Q(<span class="eqref"><a href="./#{chapter.id}#{extname}##{normalize_id(id)}">#{str}</a></span>) else %Q(<span class="eqref">#{str}</span>) end end
inline_fn(id)
click to toggle source
# File lib/review/htmlbuilder.rb, line 868 def inline_fn(id) if @book.config['epubversion'].to_i == 3 %Q(<a id="fnb-#{normalize_id(id)}" href="#fn-#{normalize_id(id)}" class="noteref" epub:type="noteref">#{I18n.t('html_footnote_refmark', @chapter.footnote(id).number)}</a>) else %Q(<a id="fnb-#{normalize_id(id)}" href="#fn-#{normalize_id(id)}" class="noteref">*#{@chapter.footnote(id).number}</a>) end rescue KeyError error "unknown footnote: #{id}" end
inline_hd_chap(chap, id)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1003 def inline_hd_chap(chap, id) n = chap.headline_index.number(id) if n.present? && chap.number && over_secnolevel?(n) str = I18n.t('hd_quote', [n, compile_inline(chap.headline(id).caption)]) else str = I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption)) end if @book.config['chapterlink'] anchor = 'h' + n.gsub('.', '-') %Q(<a href="#{chap.id}#{extname}##{anchor}">#{str}</a>) else str end rescue KeyError error "unknown headline: #{id}" end
inline_hidx(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 943 def inline_hidx(str) %Q(<!-- IDX:#{escape_comment(escape(str))} -->) end
inline_i(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 895 def inline_i(str) %Q(<i>#{escape(str)}</i>) end
inline_icon(id)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1156 def inline_icon(id) begin %Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="[#{id}]" />) rescue warn "image not bound: #{id}" %Q(<pre>missing image: #{id}</pre>) end end
inline_idx(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 939 def inline_idx(str) %Q(#{escape(str)}<!-- IDX:#{escape_comment(escape(str))} -->) end
inline_img(id)
click to toggle source
Calls superclass method
ReVIEW::Builder#inline_img
# File lib/review/htmlbuilder.rb, line 1056 def inline_img(id) str = super(id) chapter, id = extract_chapter_id(id) if @book.config['chapterlink'] %Q(<span class="imgref"><a href="./#{chapter.id}#{extname}##{normalize_id(id)}">#{str}</a></span>) else %Q(<span class="imgref">#{str}</span>) end end
inline_ins(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1144 def inline_ins(str) inline_asis(str, 'ins') end
inline_kbd(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1100 def inline_kbd(str) inline_asis(str, 'kbd') end
inline_labelref(idref)
click to toggle source
# File lib/review/htmlbuilder.rb, line 826 def inline_labelref(idref) %Q(<a target='#{escape(idref)}'>「#{I18n.t('label_marker')}#{escape(idref)}」</a>) end
Also aliased as: inline_ref
inline_list(id)
click to toggle source
Calls superclass method
ReVIEW::Builder#inline_list
# File lib/review/htmlbuilder.rb, line 1036 def inline_list(id) str = super(id) chapter, id = extract_chapter_id(id) if @book.config['chapterlink'] %Q(<span class="listref"><a href="./#{chapter.id}#{extname}##{normalize_id(id)}">#{str}</a></span>) else %Q(<span class="listref">#{str}</span>) end end
inline_m(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 951 def inline_m(str) if @book.config['mathml'] require 'math_ml' require 'math_ml/symbol/character_reference' parser = MathML::LaTeX::Parser.new(symbol: MathML::Symbol::CharacterReference) %Q(<span class="equation">#{parser.parse(str, nil)}</span>) elsif @book.config['imgmath'] math_str = '$' + str + '$' key = Digest::SHA256.hexdigest(str) math_dir = File.join(@book.config['imagedir'], '_review_math') Dir.mkdir(math_dir) unless Dir.exist?(math_dir) img_path = File.join(math_dir, "_gen_#{key}.#{@book.config['imgmath_options']['format']}") if @book.config.check_version('2', exception: false) make_math_image(math_str, img_path) %Q(<span class="equation"><img src="#{img_path}" /></span>) else defer_math_image(math_str, img_path, key) %Q(<span class="equation"><img src="#{img_path}" class="math_gen_#{key}" alt="#{escape(str)}" /></span>) end else %Q(<span class="equation">#{escape(str)}</span>) end end
inline_pageref(id)
click to toggle source
# File lib/review/htmlbuilder.rb, line 832 def inline_pageref(id) error "pageref op is unsupported on this builder: #{id}" end
inline_raw(str)
click to toggle source
Calls superclass method
ReVIEW::Builder#inline_raw
# File lib/review/htmlbuilder.rb, line 1190 def inline_raw(str) super(str) end
inline_recipe(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1152 def inline_recipe(str) %Q(<span class="recipe">「#{escape(str)}」</span>) end
inline_samp(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1104 def inline_samp(str) inline_asis(str, 'samp') end
inline_small(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1120 def inline_small(str) inline_asis(str, 'small') end
inline_strong(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1108 def inline_strong(str) inline_asis(str, 'strong') end
inline_sub(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1124 def inline_sub(str) inline_asis(str, 'sub') end
inline_sup(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1128 def inline_sup(str) inline_asis(str, 'sup') end
inline_table(id)
click to toggle source
Calls superclass method
ReVIEW::Builder#inline_table
# File lib/review/htmlbuilder.rb, line 1046 def inline_table(id) str = super(id) chapter, id = extract_chapter_id(id) if @book.config['chapterlink'] %Q(<span class="tableref"><a href="./#{chapter.id}#{extname}##{normalize_id(id)}">#{str}</a></span>) else %Q(<span class="tableref">#{str}</span>) end end
inline_tcy(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1177 def inline_tcy(str) # 縦中横用のtcy、uprightのCSSスタイルについては電書協ガイドラインを参照 style = 'tcy' if str.size == 1 && str.match(/[[:ascii:]]/) style = 'upright' end %Q(<span class="#{style}">#{escape(str)}</span>) end
inline_title(id)
click to toggle source
Calls superclass method
ReVIEW::Builder#inline_title
# File lib/review/htmlbuilder.rb, line 857 def inline_title(id) title = super if @book.config['chapterlink'] %Q(<a href="./#{id}#{extname}">#{title}</a>) else title end rescue KeyError error "unknown chapter: #{id}" end
inline_tt(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1132 def inline_tt(str) if @book.htmlversion == 5 %Q(<code class="tt">#{escape(str)}</code>) else %Q(<tt>#{escape(str)}</tt>) end end
inline_ttb(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 919 def inline_ttb(str) if @book.htmlversion == 5 %Q(<code class="tt"><b>#{escape(str)}</b></code>) else %Q(<tt><b>#{escape(str)}</b></tt>) end end
inline_tti(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 911 def inline_tti(str) if @book.htmlversion == 5 %Q(<code class="tt"><i>#{escape(str)}</i></code>) else %Q(<tt><i>#{escape(str)}</i></tt>) end end
inline_u(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1148 def inline_u(str) %Q(<u>#{escape(str)}</u>) end
inline_uchar(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1165 def inline_uchar(str) %Q(&#x#{str};) end
inline_var(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1112 def inline_var(str) inline_asis(str, 'var') end
label(id)
click to toggle source
# File lib/review/htmlbuilder.rb, line 802 def label(id) puts %Q(<a id="#{normalize_id(id)}"></a>) end
layoutfile()
click to toggle source
# File lib/review/htmlbuilder.rb, line 64 def layoutfile if @book.config.maker == 'webmaker' htmldir = 'web/html' localfilename = 'layout-web.html.erb' else htmldir = 'html' localfilename = 'layout.html.erb' end if @book.htmlversion == 5 htmlfilename = File.join(htmldir, 'layout-html5.html.erb') else htmlfilename = File.join(htmldir, 'layout-xhtml1.html.erb') end layout_file = File.join(@book.basedir, 'layouts', localfilename) if !File.exist?(layout_file) && File.exist?(File.join(@book.basedir, 'layouts', 'layout.erb')) raise ReVIEW::ConfigError, 'layout.erb is obsoleted. Please use layout.html.erb.' end if File.exist?(layout_file) if ENV['REVIEW_SAFE_MODE'].to_i & 4 > 0 warn %Q(user's layout is prohibited in safe mode. ignored.) layout_file = File.expand_path(htmlfilename, ReVIEW::Template::TEMPLATE_DIR) end else layout_file = File.expand_path(htmlfilename, ReVIEW::Template::TEMPLATE_DIR) end layout_file end
list(lines, id, caption, lang = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 375 def list(lines, id, caption, lang = nil) puts %Q(<div id="#{normalize_id(id)}" class="caption-code">) begin list_header id, caption, lang rescue KeyError error "no such list: #{id}" end list_body id, lines, lang puts '</div>' end
list_body(_id, lines, lang)
click to toggle source
# File lib/review/htmlbuilder.rb, line 394 def list_body(_id, lines, lang) class_names = ['list'] lexer = lang class_names.push("language-#{lexer}") unless lexer.blank? class_names.push('highlight') if highlight? print %Q(<pre class="#{class_names.join(' ')}">) body = lines.inject('') { |i, j| i + detab(j) + "\n" } puts highlight(body: body, lexer: lexer, format: 'html') puts '</pre>' end
list_header(id, caption, _lang)
click to toggle source
# File lib/review/htmlbuilder.rb, line 386 def list_header(id, caption, _lang) if get_chap puts %Q(<p class="caption">#{I18n.t('list')}#{I18n.t('format_number_header', [get_chap, @chapter.list(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}</p>) else puts %Q(<p class="caption">#{I18n.t('list')}#{I18n.t('format_number_header_without_chapter', [@chapter.list(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}</p>) end end
listnum(lines, id, caption, lang = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 426 def listnum(lines, id, caption, lang = nil) puts %Q(<div id="#{normalize_id(id)}" class="code">) begin list_header id, caption, lang rescue KeyError error "no such list: #{id}" end listnum_body lines, lang puts '</div>' end
listnum_body(lines, lang)
click to toggle source
# File lib/review/htmlbuilder.rb, line 437 def listnum_body(lines, lang) body = lines.inject('') { |i, j| i + detab(j) + "\n" } lexer = lang first_line_number = line_num hs = highlight(body: body, lexer: lexer, format: 'html', linenum: true, options: { linenostart: first_line_number }) if highlight? puts hs else class_names = ['list'] class_names.push("language-#{lang}") unless lang.blank? print %Q(<pre class="#{class_names.join(' ')}">) hs.split("\n").each_with_index do |line, i| puts detab((i + first_line_number).to_s.rjust(2) + ': ' + line) end puts '</pre>' end end
make_math_image(str, path, fontsize = 12)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1233 def make_math_image(str, path, fontsize = 12) # Re:VIEW 2 compatibility fontsize2 = (fontsize * 1.2).round.to_i texsrc = <<-EOB \\documentclass[12pt]{article} \\usepackage[utf8]{inputenc} \\usepackage{amsmath} \\usepackage{amsthm} \\usepackage{amssymb} \\usepackage{amsfonts} \\usepackage{anyfontsize} \\usepackage{bm} \\pagestyle{empty} \\begin{document} \\fontsize{#{fontsize}}{#{fontsize2}}\\selectfont #{str} \\end{document} EOB Dir.mktmpdir do |tmpdir| tex_path = File.join(tmpdir, 'tmpmath.tex') dvi_path = File.join(tmpdir, 'tmpmath.dvi') File.write(tex_path, texsrc) cmd = "latex --interaction=nonstopmode --output-directory=#{tmpdir} #{tex_path} && dvipng -T tight -z9 -o #{path} #{dvi_path}" out, status = Open3.capture2e(cmd) unless status.success? error "latex compile error\n\nError log:\n" + out end end end
memo(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 241 def memo(lines, caption = nil) captionblock('memo', lines, caption) end
nodisp_begin(level, label, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 169 def nodisp_begin(level, label, caption) @nonum_counter += 1 puts '' if level > 1 return unless caption.present? if label puts %Q(<a id="#{normalize_id(label)}" /><h#{level} id="#{normalize_id(label)}" hidden="true">#{compile_inline(caption)}</h#{level}>) else id = normalize_id("#{@chapter.name}_nonum#{@nonum_counter}") puts %Q(<a id="#{id}" /><h#{level} id="#{id}" hidden="true">#{compile_inline(caption)}</h#{level}>) end end
nodisp_end(level)
click to toggle source
# File lib/review/htmlbuilder.rb, line 181 def nodisp_end(level) end
nofunc_text(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1194 def nofunc_text(str) escape(str) end
noindent()
click to toggle source
# File lib/review/htmlbuilder.rb, line 822 def noindent @noindent = true end
nonum_begin(level, label, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 139 def nonum_begin(level, label, caption) @nonum_counter += 1 puts if level > 1 return unless caption.present? if label puts %Q(<h#{level} id="#{normalize_id(label)}">#{compile_inline(caption)}</h#{level}>) else id = normalize_id("#{@chapter.name}_nonum#{@nonum_counter}") puts %Q(<h#{level} id="#{id}">#{compile_inline(caption)}</h#{level}>) end end
nonum_end(level)
click to toggle source
# File lib/review/htmlbuilder.rb, line 151 def nonum_end(level) end
note(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 302 def note(lines, caption = nil) captionblock('note', lines, caption) end
notice(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 273 def notice(lines, caption = nil) captionblock('notice', lines, caption) end
notoc_begin(level, label, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 154 def notoc_begin(level, label, caption) @nonum_counter += 1 puts if level > 1 return unless caption.present? if label puts %Q(<h#{level} id="#{normalize_id(label)}" notoc="true">#{compile_inline(caption)}</h#{level}>) else id = normalize_id("#{@chapter.name}_nonum#{@nonum_counter}") puts %Q(<h#{level} id="#{id}" notoc="true">#{compile_inline(caption)}</h#{level}>) end end
notoc_end(level)
click to toggle source
# File lib/review/htmlbuilder.rb, line 166 def notoc_end(level) end
ol_begin()
click to toggle source
# File lib/review/htmlbuilder.rb, line 322 def ol_begin if @ol_num puts %Q(<ol start="#{@ol_num}">) # it's OK in HTML5, but not OK in XHTML1.1 @ol_num = nil else puts '<ol>' end end
ol_end()
click to toggle source
# File lib/review/htmlbuilder.rb, line 335 def ol_end puts '</ol>' end
ol_item(lines, _num)
click to toggle source
# File lib/review/htmlbuilder.rb, line 331 def ol_item(lines, _num) puts "<li>#{lines.join}</li>" end
olnum(num)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1218 def olnum(num) @ol_num = num.to_i end
pagebreak()
click to toggle source
# File lib/review/htmlbuilder.rb, line 810 def pagebreak puts %Q(<br class="pagebreak" />) end
paragraph(lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 355 def paragraph(lines) if @noindent puts %Q(<p class="noindent">#{lines.join}</p>) @noindent = nil else puts "<p>#{lines.join}</p>" end end
parasep()
click to toggle source
# File lib/review/htmlbuilder.rb, line 364 def parasep puts '<br />' end
planning(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 253 def planning(lines, caption = nil) captionblock('planning', lines, caption) end
point(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 281 def point(lines, caption = nil) captionblock('point', lines, caption) end
post_paragraph()
click to toggle source
# File lib/review/htmlbuilder.rb, line 37 def post_paragraph '</p>' end
pre_paragraph()
click to toggle source
# File lib/review/htmlbuilder.rb, line 33 def pre_paragraph '<p>' end
quote(lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 522 def quote(lines) blocked_lines = split_paragraph(lines) puts %Q(<blockquote>#{blocked_lines.join("\n")}</blockquote>) end
read(lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 368 def read(lines) blocked_lines = split_paragraph(lines) puts %Q(<div class="lead">\n#{blocked_lines.join("\n")}\n</div>) end
Also aliased as: lead
ref_begin(level, label, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 213 def ref_begin(level, label, caption) print %Q(<div class="reference">) headline(level, label, caption) end
ref_end(_level)
click to toggle source
# File lib/review/htmlbuilder.rb, line 218 def ref_end(_level) puts '</div>' end
result()
click to toggle source
# File lib/review/htmlbuilder.rb, line 93 def result # default XHTML header/footer @title = strip_html(compile_inline(@chapter.title)) @body = @output.string @language = @book.config['language'] @stylesheets = @book.config['stylesheet'] @next = @chapter.next_chapter @prev = @chapter.prev_chapter @next_title = @next ? compile_inline(@next.title) : '' @prev_title = @prev ? compile_inline(@prev.title) : '' if @book.config.maker == 'webmaker' @toc = ReVIEW::WEBTOCPrinter.book_to_string(@book) end ReVIEW::Template.load(layoutfile).result(binding) end
result_metric(array)
click to toggle source
# File lib/review/htmlbuilder.rb, line 602 def result_metric(array) attrs = {} array.each do |item| k = item.keys[0] if attrs[k] attrs[k] << item[k] else attrs[k] = [item[k]] end end ' ' + attrs.map { |k, v| %Q(#{k}="#{v.join(' ')}") }.join(' ') end
security(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 265 def security(lines, caption = nil) captionblock('security', lines, caption) end
shoot(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 285 def shoot(lines, caption = nil) captionblock('shoot', lines, caption) end
source(lines, caption = nil, lang = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 405 def source(lines, caption = nil, lang = nil) puts %Q(<div class="source-code">) source_header caption source_body caption, lines, lang puts '</div>' end
source_body(_id, lines, lang)
click to toggle source
# File lib/review/htmlbuilder.rb, line 418 def source_body(_id, lines, lang) print %Q(<pre class="source">) body = lines.inject('') { |i, j| i + detab(j) + "\n" } lexer = lang puts highlight(body: body, lexer: lexer, format: 'html') puts '</pre>' end
source_header(caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 412 def source_header(caption) if caption.present? puts %Q(<p class="caption">#{compile_inline(caption)}</p>) end end
sup_begin(level, label, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 222 def sup_begin(level, label, caption) print %Q(<div class="supplement">) headline(level, label, caption) end
sup_end(_level)
click to toggle source
# File lib/review/htmlbuilder.rb, line 227 def sup_end(_level) puts '</div>' end
table(lines, id = nil, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 645 def table(lines, id = nil, caption = nil) rows = [] sepidx = nil lines.each_with_index do |line, idx| if /\A[\=\-]{12}/ =~ line # just ignore # error "too many table separator" if sepidx sepidx ||= idx next end rows.push(line.strip.split(/\t+/).map { |s| s.sub(/\A\./, '') }) end rows = adjust_n_cols(rows) error 'no rows in the table' if rows.empty? if id puts %Q(<div id="#{normalize_id(id)}" class="table">) else puts %Q(<div class="table">) end begin if caption.present? table_header id, caption end rescue KeyError error "no such table: #{id}" end table_begin rows.first.size if sepidx sepidx.times do tr(rows.shift.map { |s| th(s) }) end 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 puts '</div>' end
table_begin(_ncols)
click to toggle source
# File lib/review/htmlbuilder.rb, line 700 def table_begin(_ncols) puts '<table>' end
table_end()
click to toggle source
# File lib/review/htmlbuilder.rb, line 716 def table_end puts '</table>' end
table_header(id, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 690 def table_header(id, caption) if id.nil? puts %Q(<p class="caption">#{compile_inline(caption)}</p>) elsif get_chap puts %Q(<p class="caption">#{I18n.t('table')}#{I18n.t('format_number_header', [get_chap, @chapter.table(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}</p>) else puts %Q(<p class="caption">#{I18n.t('table')}#{I18n.t('format_number_header_without_chapter', [@chapter.table(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}</p>) end end
talk(lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 535 def talk(lines) puts %Q(<div class="talk">) blocked_lines = split_paragraph(lines) puts blocked_lines.join("\n") puts '</div>' end
td(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 712 def td(str) "<td>#{str}</td>" end
texequation(lines, id = nil, caption = '')
click to toggle source
# File lib/review/htmlbuilder.rb, line 542 def texequation(lines, id = nil, caption = '') if id texequation_header id, caption end texequation_body(lines) if id puts '</div>' end end
texequation_body(lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 563 def texequation_body(lines) puts %Q(<div class="equation">) if @book.config['mathml'] require 'math_ml' require 'math_ml/symbol/character_reference' p = MathML::LaTeX::Parser.new(symbol: MathML::Symbol::CharacterReference) puts p.parse(unescape(lines.join("\n")), true) elsif @book.config['imgmath'] fontsize = @book.config['imgmath_options']['fontsize'].to_f lineheight = @book.config['imgmath_options']['lineheight'].to_f math_str = "\\begin{equation*}\n\\fontsize{#{fontsize}}{#{lineheight}}\\selectfont\n#{unescape(lines.join("\n"))}\n\\end{equation*}\n" key = Digest::SHA256.hexdigest(math_str) math_dir = File.join(@book.config['imagedir'], '_review_math') Dir.mkdir(math_dir) unless Dir.exist?(math_dir) img_path = File.join(math_dir, "_gen_#{key}.#{@book.config['imgmath_options']['format']}") if @book.config.check_version('2', exception: false) make_math_image(math_str, img_path) puts %Q(<img src="#{img_path}" />) else defer_math_image(math_str, img_path, key) puts %Q(<img src="#{img_path}" class="math_gen_#{key}" alt="#{escape(lines.join(' '))}" />) end else print '<pre>' puts escape(lines.join("\n")) puts '</pre>' end puts '</div>' end
texequation_header(id, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 554 def texequation_header(id, caption) puts %Q(<div id="#{normalize_id(id)}" class="caption-equation">) if get_chap puts %Q(<p class="caption">#{I18n.t('equation')}#{I18n.t('format_number_header', [get_chap, @chapter.equation(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}</p>) else puts %Q(<p class="caption">#{I18n.t('equation')}#{I18n.t('format_number_header_without_chapter', [@chapter.equation(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}</p>) end end
text(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 975 def text(str) str end
th(str)
click to toggle source
# File lib/review/htmlbuilder.rb, line 708 def th(str) "<th>#{str}</th>" end
tip(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 245 def tip(lines, caption = nil) captionblock('tip', lines, caption) end
tr(rows)
click to toggle source
# File lib/review/htmlbuilder.rb, line 704 def tr(rows) puts "<tr>#{rows.join}</tr>" end
ul_begin()
click to toggle source
# File lib/review/htmlbuilder.rb, line 306 def ul_begin puts '<ul>' end
ul_end()
click to toggle source
# File lib/review/htmlbuilder.rb, line 318 def ul_end puts '</ul>' end
ul_item_begin(lines)
click to toggle source
# File lib/review/htmlbuilder.rb, line 310 def ul_item_begin(lines) print "<li>#{lines.join}" end
ul_item_end()
click to toggle source
# File lib/review/htmlbuilder.rb, line 314 def ul_item_end puts '</li>' end
warning(lines, caption = nil)
click to toggle source
# File lib/review/htmlbuilder.rb, line 277 def warning(lines, caption = nil) captionblock('warning', lines, caption) end
xcolumn_begin(level, label, caption)
click to toggle source
# File lib/review/htmlbuilder.rb, line 204 def xcolumn_begin(level, label, caption) puts %Q(<div class="xcolumn">) headline(level, label, caption) end
xcolumn_end(_level)
click to toggle source
# File lib/review/htmlbuilder.rb, line 209 def xcolumn_end(_level) puts '</div>' end
xmlns_ops_prefix()
click to toggle source
# File lib/review/htmlbuilder.rb, line 111 def xmlns_ops_prefix if @book.config['epubversion'].to_i == 3 'epub' else 'ops' end end
Private Instance Methods
builder_init()
click to toggle source
# File lib/review/htmlbuilder.rb, line 45 def builder_init end
builder_init_file()
click to toggle source
# File lib/review/htmlbuilder.rb, line 49 def builder_init_file @noindent = nil @ol_num = nil @warns = [] @errors = [] @chapter.book.image_types = %w[.png .jpg .jpeg .gif .svg] @column = 0 @sec_counter = SecCounter.new(5, @chapter) @nonum_counter = 0 @first_line_num = nil @body_ext = nil @toc = nil end
column_label(id, chapter = @chapter)
click to toggle source
# File lib/review/htmlbuilder.rb, line 1020 def column_label(id, chapter = @chapter) num = chapter.column(id).number "column-#{num}" end
quotedlist(lines, css_class)
click to toggle source
# File lib/review/htmlbuilder.rb, line 513 def quotedlist(lines, css_class) print %Q(<blockquote><pre class="#{css_class}">) lines.each do |line| puts detab(line) end puts '</pre></blockquote>' end