Class: ReVIEW::HTMLBuilder

Inherits:
Builder show all
Includes:
HTMLUtils, TextUtils
Defined in:
lib/review/htmlbuilder.rb

Direct Known Subclasses

EPUBBuilder

Constant Summary

Constants included from HTMLUtils

ReVIEW::HTMLUtils::ESC

Constants inherited from Builder

Builder::CAPTION_TITLES

Instance Method Summary collapse

Methods included from HTMLUtils

#escape_html, #strip_html, #unescape_html

Methods included from TextUtils

#convert_inencoding, #convert_outencoding, #detab, #split_paragraph

Methods inherited from Builder

#bind, #compile_inline, #detab, #entries, #extract_chapter_id, #find_pathes, #get_chap, #graph, #image, #include, #initialize, #inline_hd, #inline_href, #inline_include, #inline_kw, #inline_ruby, #parse_metric, #print, #puts, #raw

Constructor Details

This class inherits a constructor from ReVIEW::Builder

Instance Method Details

#best(lines, caption = nil) ⇒ Object



326
327
328
# File 'lib/review/htmlbuilder.rb', line 326

def best(lines, caption = nil)
  captionblock("best", lines, caption)
end

#bibpaper(lines, id, caption) ⇒ Object



886
887
888
889
890
891
892
893
# File 'lib/review/htmlbuilder.rb', line 886

def bibpaper(lines, id, caption)
  puts %Q[<div class="bibpaper">]
  bibpaper_header id, caption
  unless lines.empty?
    bibpaper_bibpaper id, caption, lines
  end
  puts "</div>"
end

#bibpaper_bibpaper(id, caption, lines) ⇒ Object



901
902
903
904
905
906
907
# File 'lib/review/htmlbuilder.rb', line 901

def bibpaper_bibpaper(id, caption, lines)
  print %Q(<p>)
  lines.each do |line|
    puts detab(line)
  end
  puts %Q(</p>)
end

#bibpaper_header(id, caption) ⇒ Object



895
896
897
898
899
# File 'lib/review/htmlbuilder.rb', line 895

def bibpaper_header(id, caption)
  print %Q(<a id="bib-#{id}">)
  print "[#{@chapter.bibpaper(id).number}] #{compile_inline(caption)}"
  puts %Q(</a>)
end

#box(lines, caption = nil) ⇒ Object



354
355
356
357
358
359
360
361
# File 'lib/review/htmlbuilder.rb', line 354

def box(lines, caption = nil)
  puts %Q[<div class="syntax">]
  puts %Q[<p class="caption">#{compile_inline(caption)}</p>] unless caption.nil?
  print %Q[<pre class="syntax">]
  lines.each {|line| puts detab(line) }
  puts '</pre>'
  puts '</div>'
end

#bpo(lines) ⇒ Object



760
761
762
763
764
765
766
# File 'lib/review/htmlbuilder.rb', line 760

def bpo(lines)
  puts "<bpo>"
  lines.each do |line|
    puts detab(line)
  end
  puts "</bpo>"
end

#captionblock(type, lines, caption) ⇒ Object



296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/review/htmlbuilder.rb', line 296

def captionblock(type, lines, caption)
  puts %Q[<div class="#{type}">]
  unless caption.nil?
    puts %Q[<p class="caption">#{compile_inline(caption)}</p>]
  end
  if ReVIEW.book.param["deprecated-blocklines"].nil?
    blocked_lines = split_paragraph(lines)
    puts blocked_lines.join("\n")
  else
    lines.each {|l| puts "<p>#{l}</p>" }
  end
  puts '</div>'
end

#caution(lines, caption = nil) ⇒ Object



338
339
340
# File 'lib/review/htmlbuilder.rb', line 338

def caution(lines, caption = nil)
  captionblock("caution", lines, caption)
end

#centering(lines) ⇒ Object



1084
1085
1086
# File 'lib/review/htmlbuilder.rb', line 1084

def centering(lines)
  puts split_paragraph(lines).join("\n").gsub("<p>", "<p class=\"center\">")
end

#cmd(lines, caption = nil) ⇒ Object



530
531
532
533
534
535
536
537
538
539
# File 'lib/review/htmlbuilder.rb', line 530

def cmd(lines, caption = nil)
  puts %Q[<div class="cmd-code">]
  puts %Q(<p class="caption">#{caption}</p>) unless caption.nil?
  print %Q[<pre class="cmd">]
  lines.each do |line|
    puts detab(line)
  end
  puts '</pre>'
  puts '</div>'
end

#column_begin(level, label, caption) ⇒ Object



256
257
258
259
# File 'lib/review/htmlbuilder.rb', line 256

def column_begin(level, label, caption)
  puts %Q[<div class="column">]
  headline(level, label, caption)
end

#column_end(level) ⇒ Object



261
262
263
# File 'lib/review/htmlbuilder.rb', line 261

def column_end(level)
  puts '</div>'
end

#comment(str) ⇒ Object



712
713
714
715
716
717
718
# File 'lib/review/htmlbuilder.rb', line 712

def comment(str)
  if ReVIEW.book.param["draft"]
    puts %Q(<div class="draft-comment">#{escape_html(str)}</div>)
  else
    puts %Q(<!-- #{escape_html(str)} -->)
  end
end

#compile_href(url, label) ⇒ Object



1068
1069
1070
# File 'lib/review/htmlbuilder.rb', line 1068

def compile_href(url, label)
  %Q(<a href="#{escape_html(url)}" class="link">#{label.nil? ? escape_html(url) : escape_html(label)}</a>)
end

#compile_kw(word, alt) ⇒ Object



820
821
822
823
824
825
826
827
# File 'lib/review/htmlbuilder.rb', line 820

def compile_kw(word, alt)
  %Q[<b class="kw">] +
    if alt
    then escape_html(word + " (#{alt.strip})")
    else escape_html(word)
    end +
    "</b><!-- IDX:#{escape_html(word)} -->"
end

#compile_ruby(base, ruby) ⇒ Object



816
817
818
# File 'lib/review/htmlbuilder.rb', line 816

def compile_ruby(base, ruby)
  %Q[<ruby><rb>#{escape_html(base)}</rb><rp>#{I18n.t("ruby_prefix")}</rp><rt>#{ruby}</rt><rp>#{I18n.t("ruby_postfix")}</rp></ruby>]
end

#dd(lines) ⇒ Object



412
413
414
# File 'lib/review/htmlbuilder.rb', line 412

def dd(lines)
  puts "<dd>#{lines.join}</dd>"
end

#dl_beginObject



404
405
406
# File 'lib/review/htmlbuilder.rb', line 404

def dl_begin
  puts '<dl>'
end

#dl_endObject



416
417
418
# File 'lib/review/htmlbuilder.rb', line 416

def dl_end
  puts '</dl>'
end

#doorquote(lines, ref) ⇒ Object



559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
# File 'lib/review/htmlbuilder.rb', line 559

def doorquote(lines, ref)
  if ReVIEW.book.param["deprecated-blocklines"].nil?
    blocked_lines = split_paragraph(lines)
    puts %Q[<blockquote style="text-align:right;">]
    puts "#{blocked_lines.join("\n")}"
    puts %Q[<p>#{ref}より</p>]
    puts %Q[</blockquote>]
  else
    puts <<-QUOTE
<blockquote style="text-align:right;">
  <pre>#{lines.join("\n")}

#{ref}より</pre>
</blockquote>
QUOTE
  end
end

#dt(line) ⇒ Object



408
409
410
# File 'lib/review/htmlbuilder.rb', line 408

def dt(line)
  puts "<dt>#{line}</dt>"
end

#emlist(lines, caption = nil) ⇒ Object



509
510
511
512
513
514
515
516
517
518
# File 'lib/review/htmlbuilder.rb', line 509

def emlist(lines, caption = nil)
  puts %Q[<div class="emlist-code">]
  puts %Q(<p class="caption">#{caption}</p>) unless caption.nil?
  print %Q[<pre class="emlist">]
  lines.each do |line|
    puts detab(line)
  end
  puts '</pre>'
  puts '</div>'
end

#emlistnum(lines) ⇒ Object



520
521
522
523
524
525
526
527
528
# File 'lib/review/htmlbuilder.rb', line 520

def emlistnum(lines)
  puts %Q[<div class="emlistnum-code">]
  print %Q[<pre class="emlist">]
  lines.each_with_index do |line, i|
    puts detab((i+1).to_s.rjust(2) + ": " + line)
  end
  puts '</pre>'
  puts '</div>'
end

#error(msg) ⇒ Object



122
123
124
125
126
127
128
129
# File 'lib/review/htmlbuilder.rb', line 122

def error(msg)
  if @no_error
    @errors.push [@location.filename, @location.lineno, msg]
    puts "----ERROR: #{escape_html(msg)}----"
  else
    $stderr.puts "#{@location}: error: #{msg}"
  end
end

#error_messagesObject



135
136
137
138
139
140
141
142
143
# File 'lib/review/htmlbuilder.rb', line 135

def error_messages
  return '' if @errors.empty?
  "<h2>Syntax Errors</h2>\n" +
  "<ul>\n" +
    @errors.map {|file, line, msg|
    "<li>#{escape_html(file)}:#{line}: #{escape_html(msg.to_s)}</li>\n"
  }.join('') +
  "</ul>\n"
end

#extnameObject



44
45
46
# File 'lib/review/htmlbuilder.rb', line 44

def extname
  ".#{ReVIEW.book.param["htmlext"]}"
end

#flushright(lines) ⇒ Object



1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
# File 'lib/review/htmlbuilder.rb', line 1072

def flushright(lines)
  if ReVIEW.book.param["deprecated-blocklines"].nil?
    puts split_paragraph(lines).join("\n").gsub("<p>", "<p class=\"flushright\">")
  else
    puts %Q[<div style="text-align:right;">]
    print %Q[<pre class="flushright">]
    lines.each {|line| puts detab(line) }
    puts '</pre>'
    puts '</div>'
  end
end

#footnote(id, str) ⇒ Object



720
721
722
# File 'lib/review/htmlbuilder.rb', line 720

def footnote(id, str)
  puts %Q(<div class="footnote"><p class="footnote">[<a id="fn-#{id}">*#{@chapter.footnote(id).number}</a>] #{compile_inline(str)}</p></div>)
end

#handle_metric(str) ⇒ Object



603
604
605
606
607
608
609
610
# File 'lib/review/htmlbuilder.rb', line 603

def handle_metric(str)
  if str =~ /\Ascale=([\d.]+)\Z/
    return "width=\"#{($1.to_f * 100).round}%\""
  else
    k, v = str.split('=', 2)
    return %Q|#{k}=\"#{v.sub(/\A["']/, '').sub(/["']\Z/, '')}\"|
  end
end

#headline(level, label, caption) ⇒ Object



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/review/htmlbuilder.rb', line 224

def headline(level, label, caption)
  prefix, anchor = headline_prefix(level)
  puts '' if level > 1
  a_id = ""
  unless anchor.nil?
    a_id = %Q[<a id="h#{anchor}"></a>]
  end
  if caption.empty?
    puts a_id unless label.nil?
  else
    if label.nil?
      puts %Q[<h#{level}>#{a_id}#{prefix}#{compile_inline(caption)}</h#{level}>]
    else
      puts %Q[<h#{level} id="#{label}">#{a_id}#{prefix}#{compile_inline(caption)}</h#{level}>]
    end
  end
end

#hrObject



744
745
746
# File 'lib/review/htmlbuilder.rb', line 744

def hr
  puts "<hr />"
end

#image_dummy(id, caption, lines) ⇒ Object



624
625
626
627
628
629
630
631
632
633
# File 'lib/review/htmlbuilder.rb', line 624

def image_dummy(id, caption, lines)
  puts %Q[<div class="image">]
  puts %Q[<pre class="dummyimage">]
  lines.each do |line|
    puts detab(line)
  end
  puts %Q[</pre>]
  image_header id, caption
  puts %Q[</div>]
end

#image_extObject



1088
1089
1090
# File 'lib/review/htmlbuilder.rb', line 1088

def image_ext
  "png"
end

#image_header(id, caption) ⇒ Object



635
636
637
638
639
640
641
642
643
# File 'lib/review/htmlbuilder.rb', line 635

def image_header(id, caption)
  puts %Q[<p class="caption">]
  if get_chap.nil?
    puts %Q[#{I18n.t("image")}#{I18n.t("format_number_header_without_chapter", [@chapter.image(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}]
  else
    puts %Q[#{I18n.t("image")}#{I18n.t("format_number_header", [get_chap, @chapter.image(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}]
  end
  puts %Q[</p>]
end

#image_image(id, caption, metric) ⇒ Object



616
617
618
619
620
621
622
# File 'lib/review/htmlbuilder.rb', line 616

def image_image(id, caption, metric)
  metrics = parse_metric("html", metric)
  puts %Q[<div class="image">]
  puts %Q[<img src="#{@chapter.image(id).path.sub(/\A\.\//, "")}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />]
  image_header id, caption
  puts %Q[</div>]
end

#important(lines, caption = nil) ⇒ Object



330
331
332
# File 'lib/review/htmlbuilder.rb', line 330

def important(lines, caption = nil)
  captionblock("important", lines, caption)
end

#indepimage(id, caption = "", metric = nil) ⇒ Object Also known as: numberlessimage



724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
# File 'lib/review/htmlbuilder.rb', line 724

def indepimage(id, caption="", metric=nil)
  metrics = parse_metric("html", metric)
  caption = "" if caption.nil?
  puts %Q[<div class="image">]
  begin
    puts %Q[<img src="#{@chapter.image(id).path.sub(/\A\.\//, "")}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />]
  rescue
    puts %Q[<pre>missing image: #{id}</pre>]
  end

  unless caption.empty?
    puts %Q[<p class="caption">]
    puts %Q[#{I18n.t("numberless_image")}#{I18n.t("caption_prefix")}#{compile_inline(caption)}]
    puts %Q[</p>]
  end
  puts %Q[</div>]
end

#info(lines, caption = nil) ⇒ Object



318
319
320
# File 'lib/review/htmlbuilder.rb', line 318

def info(lines, caption = nil)
  captionblock("info", lines, caption)
end

#inline_abbr(str) ⇒ Object



968
969
970
# File 'lib/review/htmlbuilder.rb', line 968

def inline_abbr(str)
  inline_asis(str, "abbr")
end

#inline_acronym(str) ⇒ Object



972
973
974
# File 'lib/review/htmlbuilder.rb', line 972

def inline_acronym(str)
  inline_asis(str, "acronym")
end

#inline_ami(str) ⇒ Object



837
838
839
# File 'lib/review/htmlbuilder.rb', line 837

def inline_ami(str)
  %Q(<span class="ami">#{escape_html(str)}</span>)
end

#inline_asis(str, tag) ⇒ Object



964
965
966
# File 'lib/review/htmlbuilder.rb', line 964

def inline_asis(str, tag)
  %Q(<#{tag}>#{escape_html(str)}</#{tag}>)
end

#inline_b(str) ⇒ Object



833
834
835
# File 'lib/review/htmlbuilder.rb', line 833

def inline_b(str)
  %Q(<b>#{escape_html(str)}</b>)
end

#inline_bib(id) ⇒ Object



909
910
911
# File 'lib/review/htmlbuilder.rb', line 909

def inline_bib(id)
  %Q(<a href=".#{@book.bib_file.gsub(/re\Z/, "html")}#bib-#{id}">[#{@chapter.bibpaper(id).number}]</a>)
end

#inline_big(str) ⇒ Object



1004
1005
1006
# File 'lib/review/htmlbuilder.rb', line 1004

def inline_big(str)
  inline_asis(str, "big")
end

#inline_bou(str) ⇒ Object



841
842
843
# File 'lib/review/htmlbuilder.rb', line 841

def inline_bou(str)
  %Q(<span class="bou">#{escape_html(str)}</span>)
end

#inline_br(str) ⇒ Object



869
870
871
# File 'lib/review/htmlbuilder.rb', line 869

def inline_br(str)
  %Q(<br />)
end

#inline_chap(id) ⇒ Object



789
790
791
792
793
794
795
796
797
798
# File 'lib/review/htmlbuilder.rb', line 789

def inline_chap(id)
  if ReVIEW.book.param["chapterlink"]
    %Q(<a href="./#{id}.html">#{@chapter.env.chapter_index.number(id)}</a>)
  else
    @chapter.env.chapter_index.number(id)
  end
rescue KeyError
  error "unknown chapter: #{id}"
  nofunc_text("[UnknownChapter:#{id}]")
end

#inline_chapref(id) ⇒ Object



778
779
780
781
782
783
784
785
786
787
# File 'lib/review/htmlbuilder.rb', line 778

def inline_chapref(id)
  if ReVIEW.book.param["chapterlink"]
    %Q(<a href="./#{id}.html">#{@chapter.env.chapter_index.display_string(id)}</a>)
  else
    @chapter.env.chapter_index.display_string(id)
  end
rescue KeyError
  error "unknown chapter: #{id}"
  nofunc_text("[UnknownChapter:#{id}]")
end

#inline_cite(str) ⇒ Object



976
977
978
# File 'lib/review/htmlbuilder.rb', line 976

def inline_cite(str)
  inline_asis(str, "cite")
end

#inline_code(str) ⇒ Object



857
858
859
# File 'lib/review/htmlbuilder.rb', line 857

def inline_code(str)
  %Q(<tt class="inline-code">#{escape_html(str)}</tt>)
end

#inline_comment(str) ⇒ Object



1052
1053
1054
1055
1056
1057
1058
# File 'lib/review/htmlbuilder.rb', line 1052

def inline_comment(str)
  if ReVIEW.book.param["draft"]
    %Q(<span class="draft-comment">#{escape_html(str)}</span>)
  else
    %Q(<!-- #{escape_html(str)} -->)
  end
end

#inline_del(str) ⇒ Object



1024
1025
1026
# File 'lib/review/htmlbuilder.rb', line 1024

def inline_del(str)
  inline_asis(str, "del")
end

#inline_dfn(str) ⇒ Object



980
981
982
# File 'lib/review/htmlbuilder.rb', line 980

def inline_dfn(str)
  inline_asis(str, "dfn")
end

#inline_dtp(str) ⇒ Object



853
854
855
# File 'lib/review/htmlbuilder.rb', line 853

def inline_dtp(str)
  "<?dtp #{str} ?>"
end

#inline_em(str) ⇒ Object



984
985
986
# File 'lib/review/htmlbuilder.rb', line 984

def inline_em(str)
  inline_asis(str, "em")
end

#inline_fn(id) ⇒ Object



812
813
814
# File 'lib/review/htmlbuilder.rb', line 812

def inline_fn(id)
  %Q(<a href="#fn-#{id}">*#{@chapter.footnote(id).number}</a>)
end

#inline_hd_chap(chap, id) ⇒ Object



913
914
915
916
917
918
919
920
921
922
923
924
925
926
# File 'lib/review/htmlbuilder.rb', line 913

def inline_hd_chap(chap, id)
  n = chap.headline_index.number(id)
  if chap.number and ReVIEW.book.param["secnolevel"] >= n.split('.').size
    str = "#{n} #{compile_inline(chap.headline(id).caption)}"
  else
    str = "#{compile_inline(chap.headline(id).caption)}"
  end
  if ReVIEW.book.param["chapterlink"]
    anchor = "h"+n.gsub(/\./, "-")
    %Q(<a href="#{chap.id}.html\##{anchor}">#{str}</a>)
  else
    str
  end
end

#inline_hidx(str) ⇒ Object



865
866
867
# File 'lib/review/htmlbuilder.rb', line 865

def inline_hidx(str)
  %Q(<!-- IDX:#{escape_html(str)} -->)
end

#inline_i(str) ⇒ Object



829
830
831
# File 'lib/review/htmlbuilder.rb', line 829

def inline_i(str)
  %Q(<i>#{escape_html(str)}</i>)
end

#inline_icon(id) ⇒ Object



1040
1041
1042
1043
1044
1045
1046
# File 'lib/review/htmlbuilder.rb', line 1040

def inline_icon(id)
  begin
    %Q[<img src="#{@chapter.image(id).path.sub(/\A\.\//, "")}" alt="[#{id}]" />]
  rescue
    %Q[<pre>missing image: #{id}</pre>]
  end
end

#inline_idx(str) ⇒ Object



861
862
863
# File 'lib/review/htmlbuilder.rb', line 861

def inline_idx(str)
  %Q(#{escape_html(str)}<!-- IDX:#{escape_html(str)} -->)
end

#inline_img(id) ⇒ Object



952
953
954
955
956
957
958
959
960
961
962
# File 'lib/review/htmlbuilder.rb', line 952

def inline_img(id)
  chapter, id = extract_chapter_id(id)
  if get_chap(chapter).nil?
    "#{I18n.t("image")}#{I18n.t("format_number_without_chapter", [chapter.image(id).number])}"
  else
    "#{I18n.t("image")}#{I18n.t("format_number", [get_chap(chapter), chapter.image(id).number])}"
  end
rescue KeyError
  error "unknown image: #{id}"
  nofunc_text("[UnknownImage:#{id}]")
end

#inline_ins(str) ⇒ Object



1028
1029
1030
# File 'lib/review/htmlbuilder.rb', line 1028

def inline_ins(str)
  inline_asis(str, "ins")
end

#inline_kbd(str) ⇒ Object



988
989
990
# File 'lib/review/htmlbuilder.rb', line 988

def inline_kbd(str)
  inline_asis(str, "kbd")
end

#inline_labelref(idref) ⇒ Object Also known as: inline_ref



772
773
774
# File 'lib/review/htmlbuilder.rb', line 772

def inline_labelref(idref)
  %Q[<a target='#{escape_html(idref)}'>「●● #{escape_html(idref)}」</a>]
end

#inline_list(id) ⇒ Object



928
929
930
931
932
933
934
935
936
937
938
# File 'lib/review/htmlbuilder.rb', line 928

def inline_list(id)
  chapter, id = extract_chapter_id(id)
  if get_chap(chapter).nil?
    "#{I18n.t("list")}#{I18n.t("format_number_without_header", [chapter.list(id).number])}"
  else
    "#{I18n.t("list")}#{I18n.t("format_number", [get_chap(chapter), chapter.list(id).number])}"
  end
rescue KeyError
  error "unknown list: #{id}"
  nofunc_text("[UnknownList:#{id}]")
end

#inline_m(str) ⇒ Object



873
874
875
876
877
878
879
880
# File 'lib/review/htmlbuilder.rb', line 873

def inline_m(str)
  if ReVIEW.book.param["mathml"]
    p = MathML::LaTeX::Parser.new
    %Q[<span class="equation">#{p.parse(str, nil)}</span>]
  else
    %Q[<span class="equation">#{escape_html(str)}</span>]
  end
end

#inline_raw(str) ⇒ Object



1060
1061
1062
# File 'lib/review/htmlbuilder.rb', line 1060

def inline_raw(str)
  super(str)
end

#inline_recipe(str) ⇒ Object



1036
1037
1038
# File 'lib/review/htmlbuilder.rb', line 1036

def inline_recipe(str)
  %Q(<span class="recipe">「#{escape_html(str)}」</span>)
end

#inline_samp(str) ⇒ Object



992
993
994
# File 'lib/review/htmlbuilder.rb', line 992

def inline_samp(str)
  inline_asis(str, "samp")
end

#inline_small(str) ⇒ Object



1008
1009
1010
# File 'lib/review/htmlbuilder.rb', line 1008

def inline_small(str)
  inline_asis(str, "small")
end

#inline_strong(str) ⇒ Object



996
997
998
# File 'lib/review/htmlbuilder.rb', line 996

def inline_strong(str)
  inline_asis(str, "strong")
end

#inline_sub(str) ⇒ Object



1012
1013
1014
# File 'lib/review/htmlbuilder.rb', line 1012

def inline_sub(str)
  inline_asis(str, "sub")
end

#inline_sup(str) ⇒ Object



1016
1017
1018
# File 'lib/review/htmlbuilder.rb', line 1016

def inline_sup(str)
  inline_asis(str, "sup")
end

#inline_table(id) ⇒ Object



940
941
942
943
944
945
946
947
948
949
950
# File 'lib/review/htmlbuilder.rb', line 940

def inline_table(id)
  chapter, id = extract_chapter_id(id)
  if get_chap(chapter).nil?
    "#{I18n.t("table")}#{I18n.t("format_number_without_chapter", [chapter.table(id).number])}"
  else
    "#{I18n.t("table")}#{I18n.t("format_number", [get_chap(chapter), chapter.table(id).number])}"
  end
rescue KeyError
  error "unknown table: #{id}"
  nofunc_text("[UnknownTable:#{id}]")
end

#inline_title(id) ⇒ Object



800
801
802
803
804
805
806
807
808
809
# File 'lib/review/htmlbuilder.rb', line 800

def inline_title(id)
  if ReVIEW.book.param["chapterlink"]
    %Q(<a href="./#{id}.html">#{compile_inline(@chapter.env.chapter_index.title(id))}</a>)
  else
    @chapter.env.chapter_index.title(id)
  end
rescue KeyError
  error "unknown chapter: #{id}"
  nofunc_text("[UnknownChapter:#{id}]")
end

#inline_tt(str) ⇒ Object



1020
1021
1022
# File 'lib/review/htmlbuilder.rb', line 1020

def inline_tt(str)
  inline_asis(str, "tt")
end

#inline_ttb(str) ⇒ Object



849
850
851
# File 'lib/review/htmlbuilder.rb', line 849

def inline_ttb(str)
  %Q(<tt><b>#{escape_html(str)}</b></tt>)
end

#inline_tti(str) ⇒ Object



845
846
847
# File 'lib/review/htmlbuilder.rb', line 845

def inline_tti(str)
  %Q(<tt><i>#{escape_html(str)}</i></tt>)
end

#inline_u(str) ⇒ Object



1032
1033
1034
# File 'lib/review/htmlbuilder.rb', line 1032

def inline_u(str)
  %Q(<u>#{escape_html(str)}</u>)
end

#inline_uchar(str) ⇒ Object



1048
1049
1050
# File 'lib/review/htmlbuilder.rb', line 1048

def inline_uchar(str)
  %Q(&#x#{str};)
end

#inline_var(str) ⇒ Object



1000
1001
1002
# File 'lib/review/htmlbuilder.rb', line 1000

def inline_var(str)
  inline_asis(str, "var")
end

#label(id) ⇒ Object



748
749
750
# File 'lib/review/htmlbuilder.rb', line 748

def label(id)
  puts %Q(<a id="#{id}"></a>)
end

#linebreakObject



752
753
754
# File 'lib/review/htmlbuilder.rb', line 752

def linebreak
  puts "<br />"
end

#list(lines, id, caption) ⇒ Object



444
445
446
447
448
449
450
451
452
453
# File 'lib/review/htmlbuilder.rb', line 444

def list(lines, id, caption)
  puts %Q[<div class="caption-code">]
  begin
    list_header id, caption
  rescue KeyError
    error "no such list: #{id}"
  end
  list_body lines
  puts '</div>'
end

#list_body(lines) ⇒ Object



463
464
465
466
467
468
469
# File 'lib/review/htmlbuilder.rb', line 463

def list_body(lines)
  print %Q[<pre class="list">]
  lines.each do |line|
    puts detab(line)
  end
  puts '</pre>'
end

#list_header(id, caption) ⇒ Object



455
456
457
458
459
460
461
# File 'lib/review/htmlbuilder.rb', line 455

def list_header(id, caption)
  if get_chap.nil?
    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>]
  else
    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>]
  end
end

#listnum(lines, id, caption) ⇒ Object



490
491
492
493
494
495
496
497
498
499
# File 'lib/review/htmlbuilder.rb', line 490

def listnum(lines, id, caption)
  puts %Q[<div class="code">]
  begin
    list_header id, caption
  rescue KeyError
    error "no such list: #{id}"
  end
  listnum_body lines
  puts '</div>'
end

#listnum_body(lines) ⇒ Object



501
502
503
504
505
506
507
# File 'lib/review/htmlbuilder.rb', line 501

def listnum_body(lines)
  print %Q[<pre class="list">]
  lines.each_with_index do |line, i|
    puts detab((i+1).to_s.rjust(2) + ": " + line)
  end
  puts '</pre>'
end

#memo(lines, caption = nil) ⇒ Object



310
311
312
# File 'lib/review/htmlbuilder.rb', line 310

def memo(lines, caption = nil)
  captionblock("memo", lines, caption)
end

#messagesObject



131
132
133
# File 'lib/review/htmlbuilder.rb', line 131

def messages
  error_messages() + warning_messages()
end

#nofunc_text(str) ⇒ Object



1064
1065
1066
# File 'lib/review/htmlbuilder.rb', line 1064

def nofunc_text(str)
  escape_html(str)
end

#noindentObject



768
769
770
# File 'lib/review/htmlbuilder.rb', line 768

def noindent
  @noindent = true
end

#nonum_begin(level, label, caption) ⇒ Object



242
243
244
245
246
247
248
249
250
251
# File 'lib/review/htmlbuilder.rb', line 242

def nonum_begin(level, label, caption)
  puts '' if level > 1
  unless caption.empty?
    if label.nil?
      puts %Q[<h#{level}>#{compile_inline(caption)}</h#{level}>]
    else
      puts %Q[<h#{level} id="#{label}">#{compile_inline(caption)}</h#{level}>]
    end
  end
end

#nonum_end(level) ⇒ Object



253
254
# File 'lib/review/htmlbuilder.rb', line 253

def nonum_end(level)
end

#note(lines, caption = nil) ⇒ Object



363
364
365
# File 'lib/review/htmlbuilder.rb', line 363

def note(lines, caption = nil)
  captionblock("note", lines, caption)
end

#notice(lines, caption = nil) ⇒ Object



342
343
344
# File 'lib/review/htmlbuilder.rb', line 342

def notice(lines, caption = nil)
  captionblock("notice", lines, caption)
end

#ol_beginObject



387
388
389
390
391
392
393
394
# File 'lib/review/htmlbuilder.rb', line 387

def ol_begin
  if @ol_num
    puts "<ol start=\"#{@ol_num}\">"  ## it's OK in HTML5, but not OK in XHTML1.1
    @ol_num = nil
  else
    puts '<ol>'
  end
end

#ol_endObject



400
401
402
# File 'lib/review/htmlbuilder.rb', line 400

def ol_end
  puts '</ol>'
end

#ol_item(lines, num) ⇒ Object



396
397
398
# File 'lib/review/htmlbuilder.rb', line 396

def ol_item(lines, num)
  puts "<li>#{lines.join}</li>"
end

#olnum(num) ⇒ Object



1092
1093
1094
# File 'lib/review/htmlbuilder.rb', line 1092

def olnum(num)
  @ol_num = num.to_i
end

#pagebreakObject



756
757
758
# File 'lib/review/htmlbuilder.rb', line 756

def pagebreak
  puts %Q(<br class="pagebreak" />)
end

#paragraph(lines) ⇒ Object



420
421
422
423
424
425
426
427
# File 'lib/review/htmlbuilder.rb', line 420

def paragraph(lines)
  if @noindent.nil?
    puts "<p>#{lines.join}</p>"
  else
    puts %Q[<p class="noindent">#{lines.join}</p>]
    @noindent = nil
  end
end

#parasepObject



429
430
431
# File 'lib/review/htmlbuilder.rb', line 429

def parasep()
  puts '<br />'
end

#planning(lines, caption = nil) ⇒ Object



322
323
324
# File 'lib/review/htmlbuilder.rb', line 322

def planning(lines, caption = nil)
  captionblock("planning", lines, caption)
end

#point(lines, caption = nil) ⇒ Object



346
347
348
# File 'lib/review/htmlbuilder.rb', line 346

def point(lines, caption = nil)
  captionblock("point", lines, caption)
end

#post_paragraphObject



40
41
42
# File 'lib/review/htmlbuilder.rb', line 40

def post_paragraph
  '</p>'
end

#pre_paragraphObject



37
38
39
# File 'lib/review/htmlbuilder.rb', line 37

def pre_paragraph
  '<p>'
end

#quote(lines) ⇒ Object



550
551
552
553
554
555
556
557
# File 'lib/review/htmlbuilder.rb', line 550

def quote(lines)
  if ReVIEW.book.param["deprecated-blocklines"].nil?
    blocked_lines = split_paragraph(lines)
    puts "<blockquote>#{blocked_lines.join("\n")}</blockquote>"
  else
    puts "<blockquote><pre>#{lines.join("\n")}</pre></blockquote>"
  end
end

#read(lines) ⇒ Object Also known as: lead



433
434
435
436
437
438
439
440
# File 'lib/review/htmlbuilder.rb', line 433

def read(lines)
  if ReVIEW.book.param["deprecated-blocklines"].nil?
    blocked_lines = split_paragraph(lines)
    puts %Q[<div class="lead">\n#{blocked_lines.join("\n")}\n</div>]
  else
    puts %Q[<p class="lead">\n#{lines.join("\n")}\n</p>]
  end
end

#ref_begin(level, label, caption) ⇒ Object



274
275
276
277
# File 'lib/review/htmlbuilder.rb', line 274

def ref_begin(level, label, caption)
  print %Q[<div class="reference">]
  headline(level, label, caption)
end

#ref_end(level) ⇒ Object



279
280
281
# File 'lib/review/htmlbuilder.rb', line 279

def ref_end(level)
  puts '</div>'
end

#resultObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/review/htmlbuilder.rb', line 65

def result
  layout_file = File.join(@book.basedir, "layouts", "layout.erb")
  if File.exists?(layout_file)
    messages() +
      HTMLLayout.new(@output.string, @chapter.title, layout_file).result
  else
    # default XHTML header/footer
    header = <<EOT
<?xml version="1.0" encoding="#{ReVIEW.book.param["outencoding"] || :UTF-8}"?>
EOT

    if ReVIEW.book.param["htmlversion"] == 5
      header += <<EOT
<!DOCTYPE html>
EOT
    else
      header += <<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
EOT
    end

    header += <<EOT
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="#{ReVIEW.book.param["language"]}">
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=#{ReVIEW.book.param["outencoding"] || :UTF-8}" />
  <meta http-equiv="Content-Style-Type" content="text/css" />
EOT
    unless ReVIEW.book.param["stylesheet"].nil?
      ReVIEW.book.param["stylesheet"].each do |style|
        header += <<EOT
  <link rel="stylesheet" type="text/css" href="#{style}" />
EOT
      end
    end
    header += <<EOT
  <meta name="generator" content="ReVIEW" />
  <title>#{convert_outencoding(strip_html(compile_inline(@chapter.title)), ReVIEW.book.param["outencoding"])}</title>
</head>
<body>
EOT
    footer = <<EOT
</body>
</html>
EOT
    header + messages() + convert_outencoding(@output.string, ReVIEW.book.param["outencoding"]) + footer
  end
end

#result_metric(array) ⇒ Object



612
613
614
# File 'lib/review/htmlbuilder.rb', line 612

def result_metric(array)
  " #{array.join(' ')}"
end

#security(lines, caption = nil) ⇒ Object



334
335
336
# File 'lib/review/htmlbuilder.rb', line 334

def security(lines, caption = nil)
  captionblock("security", lines, caption)
end

#shoot(lines, caption = nil) ⇒ Object



350
351
352
# File 'lib/review/htmlbuilder.rb', line 350

def shoot(lines, caption = nil)
  captionblock("shoot", lines, caption)
end

#source(lines, caption) ⇒ Object



471
472
473
474
475
476
# File 'lib/review/htmlbuilder.rb', line 471

def source(lines, caption)
  puts %Q[<div class="source-code">]
  source_header caption
  source_body lines
  puts '</div>'
end

#source_body(lines) ⇒ Object



482
483
484
485
486
487
488
# File 'lib/review/htmlbuilder.rb', line 482

def source_body(lines)
  print %Q[<pre class="source">]
  lines.each do |line|
    puts detab(line)
  end
  puts '</pre>'
end

#source_header(caption) ⇒ Object



478
479
480
# File 'lib/review/htmlbuilder.rb', line 478

def source_header(caption)
  puts %Q[<p class="caption">#{compile_inline(caption)}</p>]
end

#sup_begin(level, label, caption) ⇒ Object



283
284
285
286
# File 'lib/review/htmlbuilder.rb', line 283

def sup_begin(level, label, caption)
  print %Q[<div class="supplement">]
  headline(level, label, caption)
end

#sup_end(level) ⇒ Object



288
289
290
# File 'lib/review/htmlbuilder.rb', line 288

def sup_end(level)
  puts '</div>'
end

#table(lines, id = nil, caption = nil) ⇒ Object



645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
# 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)

  puts %Q[<div class="table">]
  begin
    table_header id, caption unless caption.nil?
  rescue KeyError => err
    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
    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 %Q[</div>]
end

#table_begin(ncols) ⇒ Object



692
693
694
# File 'lib/review/htmlbuilder.rb', line 692

def table_begin(ncols)
  puts '<table>'
end

#table_endObject



708
709
710
# File 'lib/review/htmlbuilder.rb', line 708

def table_end
  puts '</table>'
end

#table_header(id, caption) ⇒ Object



684
685
686
687
688
689
690
# File 'lib/review/htmlbuilder.rb', line 684

def table_header(id, caption)
  if get_chap.nil?
    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>]
  else
    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>]
  end
end

#talk(lines) ⇒ Object



577
578
579
580
581
582
583
584
585
586
587
588
# File 'lib/review/htmlbuilder.rb', line 577

def talk(lines)
  puts %Q[<div class="talk">]
  if ReVIEW.book.param["deprecated-blocklines"].nil?
    blocked_lines = split_paragraph(lines)
    puts "#{blocked_lines.join("\n")}"
  else
    print '<pre>'
    puts "#{lines.join("\n")}"
    puts '</pre>'
  end
  puts '</div>'
end

#td(str) ⇒ Object



704
705
706
# File 'lib/review/htmlbuilder.rb', line 704

def td(str)
  "<td>#{str}</td>"
end

#texequation(lines) ⇒ Object



590
591
592
593
594
595
596
597
598
599
600
601
# File 'lib/review/htmlbuilder.rb', line 590

def texequation(lines)
  puts %Q[<div class="equation">]
  if ReVIEW.book.param["mathml"]
    p = MathML::LaTeX::Parser.new
    puts p.parse(unescape_html(lines.join("\n")), true)
  else
    print '<pre>'
    puts "#{lines.join("\n")}"
    puts '</pre>'
  end
  puts '</div>'
end

#text(str) ⇒ Object



882
883
884
# File 'lib/review/htmlbuilder.rb', line 882

def text(str)
  str
end

#th(str) ⇒ Object



700
701
702
# File 'lib/review/htmlbuilder.rb', line 700

def th(str)
  "<th>#{str}</th>"
end

#tip(lines, caption = nil) ⇒ Object



314
315
316
# File 'lib/review/htmlbuilder.rb', line 314

def tip(lines, caption = nil)
  captionblock("tip", lines, caption)
end

#tr(rows) ⇒ Object



696
697
698
# File 'lib/review/htmlbuilder.rb', line 696

def tr(rows)
  puts "<tr>#{rows.join}</tr>"
end

#tsize(str) ⇒ Object



292
293
294
# File 'lib/review/htmlbuilder.rb', line 292

def tsize(str)
  # null
end

#ul_beginObject



367
368
369
# File 'lib/review/htmlbuilder.rb', line 367

def ul_begin
  puts '<ul>'
end

#ul_endObject



383
384
385
# File 'lib/review/htmlbuilder.rb', line 383

def ul_end
  puts '</ul>'
end

#ul_item(lines) ⇒ Object



371
372
373
# File 'lib/review/htmlbuilder.rb', line 371

def ul_item(lines)
  puts "<li>#{lines.join}</li>"
end

#ul_item_begin(lines) ⇒ Object



375
376
377
# File 'lib/review/htmlbuilder.rb', line 375

def ul_item_begin(lines)
  print "<li>#{lines.join}"
end

#ul_item_endObject



379
380
381
# File 'lib/review/htmlbuilder.rb', line 379

def ul_item_end
  puts "</li>"
end

#warn(msg) ⇒ Object



113
114
115
116
117
118
119
120
# File 'lib/review/htmlbuilder.rb', line 113

def warn(msg)
  if @no_error
    @warns.push [@location.filename, @location.lineno, msg]
    puts "----WARNING: #{escape_html(msg)}----"
  else
    $stderr.puts "#{@location}: warning: #{msg}"
  end
end

#warning_messagesObject



145
146
147
148
149
150
151
152
153
# File 'lib/review/htmlbuilder.rb', line 145

def warning_messages
  return '' if @warns.empty?
  "<h2>Warnings</h2>\n" +
  "<ul>\n" +
  @warns.map {|file, line, msg|
    "<li>#{escape_html(file)}:#{line}: #{escape_html(msg)}</li>\n"
  }.join('') +
  "</ul>\n"
end

#xcolumn_begin(level, label, caption) ⇒ Object



265
266
267
268
# File 'lib/review/htmlbuilder.rb', line 265

def xcolumn_begin(level, label, caption)
  puts %Q[<div class="xcolumn">]
  headline(level, label, caption)
end

#xcolumn_end(level) ⇒ Object



270
271
272
# File 'lib/review/htmlbuilder.rb', line 270

def xcolumn_end(level)
  puts '</div>'
end