review 2.5.0 → 3.0.0.preview1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +28 -10
  3. data/.travis.yml +11 -2
  4. data/NEWS.ja.md +89 -17
  5. data/NEWS.md +92 -0
  6. data/README.md +1 -1
  7. data/Rakefile +0 -13
  8. data/bin/review-catalog-converter +83 -37
  9. data/bin/review-check +17 -5
  10. data/bin/review-compile +1 -1
  11. data/bin/review-index +6 -0
  12. data/bin/review-init +3 -155
  13. data/bin/review-preproc +0 -5
  14. data/bin/review-validate +21 -7
  15. data/bin/review-vol +13 -5
  16. data/doc/config.yml.sample +12 -7
  17. data/doc/config.yml.sample-simple +1 -1
  18. data/doc/format.ja.md +39 -3
  19. data/doc/format.md +39 -3
  20. data/doc/format_idg.ja.md +0 -4
  21. data/doc/pdfmaker.ja.md +1 -1
  22. data/doc/pdfmaker.md +1 -1
  23. data/doc/sample.css +7 -0
  24. data/lib/epubmaker/content.rb +31 -12
  25. data/lib/epubmaker/epubcommon.rb +10 -3
  26. data/lib/epubmaker/epubv2.rb +11 -3
  27. data/lib/epubmaker/epubv3.rb +11 -3
  28. data/lib/epubmaker/producer.rb +55 -20
  29. data/lib/review/book/base.rb +63 -48
  30. data/lib/review/book/chapter.rb +19 -7
  31. data/lib/review/book/compilable.rb +5 -20
  32. data/lib/review/book/image_finder.rb +10 -3
  33. data/lib/review/book/index.rb +30 -9
  34. data/lib/review/book/part.rb +9 -6
  35. data/lib/review/book.rb +0 -14
  36. data/lib/review/builder.rb +110 -18
  37. data/lib/review/catalog.rb +24 -4
  38. data/lib/review/compiler.rb +3 -1
  39. data/lib/review/configure.rb +43 -9
  40. data/lib/review/epubmaker/reviewheaderlistener.rb +57 -0
  41. data/lib/review/epubmaker.rb +129 -85
  42. data/lib/review/htmlbuilder.rb +76 -58
  43. data/lib/review/htmlutils.rb +20 -13
  44. data/lib/review/i18n.rb +6 -2
  45. data/lib/review/idgxmlbuilder.rb +52 -41
  46. data/lib/review/init.rb +194 -0
  47. data/lib/review/latexbuilder.rb +118 -34
  48. data/lib/review/latexutils.rb +5 -5
  49. data/lib/review/logger.rb +2 -1
  50. data/lib/review/makerhelper.rb +1 -1
  51. data/lib/review/markdownbuilder.rb +66 -6
  52. data/lib/review/md2inaobuilder.rb +2 -2
  53. data/lib/review/pdfmaker.rb +74 -22
  54. data/lib/review/plaintextbuilder.rb +8 -4
  55. data/lib/review/preprocessor.rb +14 -17
  56. data/lib/review/sec_counter.rb +8 -2
  57. data/lib/review/textmaker.rb +2 -2
  58. data/lib/review/textutils.rb +9 -2
  59. data/lib/review/tocparser.rb +7 -4
  60. data/lib/review/tocprinter.rb +3 -1
  61. data/lib/review/version.rb +1 -1
  62. data/lib/review/webmaker.rb +19 -7
  63. data/lib/review/webtocprinter.rb +8 -4
  64. data/review.gemspec +4 -3
  65. data/templates/latex/config.erb +84 -0
  66. data/templates/latex/layout.tex.erb +76 -361
  67. data/templates/latex/review-jlreq/README.md +22 -0
  68. data/templates/latex/review-jlreq/review-base.sty +178 -0
  69. data/templates/latex/review-jlreq/review-custom.sty +1 -0
  70. data/templates/latex/review-jlreq/review-jlreq.cls +141 -0
  71. data/templates/latex/review-jlreq/review-style.sty +149 -0
  72. data/templates/latex/review-jlreq/reviewmacro.sty +8 -0
  73. data/templates/latex/review-jsbook/jumoline.sty +310 -0
  74. data/templates/latex/review-jsbook/plistings.sty +326 -0
  75. data/templates/latex/review-jsbook/review-base.sty +405 -0
  76. data/templates/latex/review-jsbook/review-custom.sty +1 -0
  77. data/templates/latex/review-jsbook/review-style.sty +38 -0
  78. data/templates/latex/review-jsbook/reviewmacro.sty +8 -0
  79. data/templates/latex-compat2/layout.tex.erb +387 -0
  80. data/test/assets/test_template.tex +105 -235
  81. data/test/assets/test_template_backmatter.tex +133 -14
  82. data/test/book_test_helper.rb +1 -1
  83. data/test/run_test.rb +2 -0
  84. data/test/sample-book/src/Rakefile +11 -6
  85. data/test/sample-book/src/config.yml +2 -2
  86. data/test/sample-book/src/sty/reviewmacro.sty +1 -39
  87. data/test/sample-book/src/style.css +6 -0
  88. data/test/syntax-book/config.yml +1 -1
  89. data/test/test_book.rb +13 -16
  90. data/test/test_book_chapter.rb +4 -10
  91. data/test/test_book_part.rb +4 -3
  92. data/test/test_catalog.rb +15 -4
  93. data/test/test_helper.rb +2 -2
  94. data/test/test_htmlbuilder.rb +78 -10
  95. data/test/test_htmlutils.rb +12 -5
  96. data/test/test_idgxmlbuilder.rb +1 -1
  97. data/test/test_latexbuilder.rb +94 -49
  98. data/test/test_latexbuilder_v2.rb +1077 -0
  99. data/test/test_logger.rb +20 -0
  100. data/test/test_markdownbuilder.rb +10 -0
  101. data/test/test_pdfmaker.rb +6 -7
  102. data/test/test_plaintextbuilder.rb +1 -1
  103. data/test/test_review_ext.rb +0 -1
  104. data/test/test_rstbuilder.rb +1 -1
  105. data/test/test_topbuilder.rb +19 -7
  106. data/test/test_webtocprinter.rb +14 -14
  107. data/{test/sample-book/src/vendor → vendor}/jumoline/README +0 -0
  108. data/{test/sample-book/src/vendor → vendor}/jumoline/jumoline.dtx +0 -0
  109. data/{test/sample-book/src/vendor → vendor}/jumoline/jumoline.ins +0 -0
  110. data/{test/sample-book/src/vendor → vendor}/jumoline/lppl.txt +0 -0
  111. data/vendor/plistings/.gitignore +9 -0
  112. data/vendor/plistings/LICENSE +21 -0
  113. data/vendor/plistings/README.md +18 -0
  114. data/vendor/plistings/plistings.sty +326 -0
  115. data/vendor/plistings/test1.tex +174 -0
  116. data/vendor/plistings/test2.tex +54 -0
  117. metadata +48 -19
  118. data/lib/review/unfold.rb +0 -129
  119. data/test/CHAPS +0 -2
  120. data/test/bib.re +0 -13
  121. data/test/test.re +0 -43
@@ -14,6 +14,7 @@ require 'review/textutils'
14
14
  require 'review/webtocprinter'
15
15
  require 'digest'
16
16
  require 'tmpdir'
17
+ require 'open3'
17
18
 
18
19
  module ReVIEW
19
20
  class HTMLBuilder < Builder
@@ -41,16 +42,13 @@ module ReVIEW
41
42
  ".#{@book.config['htmlext']}"
42
43
  end
43
44
 
44
- def builder_init(no_error = false)
45
- @no_error = no_error
46
- @noindent = nil
47
- @ol_num = nil
48
- @error_messages = nil
49
- @warning_messages = nil
45
+ def builder_init
50
46
  end
51
47
  private :builder_init
52
48
 
53
49
  def builder_init_file
50
+ @noindent = nil
51
+ @ol_num = nil
54
52
  @warns = []
55
53
  @errors = []
56
54
  @chapter.book.image_types = %w[.png .jpg .jpeg .gif .svg]
@@ -232,7 +230,9 @@ module ReVIEW
232
230
 
233
231
  def captionblock(type, lines, caption)
234
232
  puts %Q(<div class="#{type}">)
235
- puts %Q(<p class="caption">#{compile_inline(caption)}</p>) if caption.present?
233
+ if caption.present?
234
+ puts %Q(<p class="caption">#{compile_inline(caption)}</p>)
235
+ end
236
236
  blocked_lines = split_paragraph(lines)
237
237
  puts blocked_lines.join("\n")
238
238
  puts '</div>'
@@ -288,7 +288,9 @@ module ReVIEW
288
288
 
289
289
  def box(lines, caption = nil)
290
290
  puts %Q(<div class="syntax">)
291
- puts %Q(<p class="caption">#{compile_inline(caption)}</p>) if caption.present?
291
+ if caption.present?
292
+ puts %Q(<p class="caption">#{compile_inline(caption)}</p>)
293
+ end
292
294
  print %Q(<pre class="syntax">)
293
295
  lines.each do |line|
294
296
  puts detab(line)
@@ -389,10 +391,9 @@ module ReVIEW
389
391
  end
390
392
  end
391
393
 
392
- def list_body(id, lines, lang)
393
- id ||= ''
394
+ def list_body(_id, lines, lang)
394
395
  class_names = ['list']
395
- lexer = lang || File.extname(id).gsub('.', '')
396
+ lexer = lang
396
397
  class_names.push("language-#{lexer}") unless lexer.blank?
397
398
  class_names.push('highlight') if highlight?
398
399
  print %Q(<pre class="#{class_names.join(' ')}">)
@@ -409,14 +410,15 @@ module ReVIEW
409
410
  end
410
411
 
411
412
  def source_header(caption)
412
- puts %Q(<p class="caption">#{compile_inline(caption)}</p>) if caption.present?
413
+ if caption.present?
414
+ puts %Q(<p class="caption">#{compile_inline(caption)}</p>)
415
+ end
413
416
  end
414
417
 
415
- def source_body(id, lines, lang)
416
- id ||= ''
418
+ def source_body(_id, lines, lang)
417
419
  print %Q(<pre class="source">)
418
420
  body = lines.inject('') { |i, j| i + detab(j) + "\n" }
419
- lexer = lang || File.extname(id).gsub('.', '')
421
+ lexer = lang
420
422
  puts highlight(body: body, lexer: lexer, format: 'html')
421
423
  puts '</pre>'
422
424
  end
@@ -454,7 +456,9 @@ module ReVIEW
454
456
 
455
457
  def emlist(lines, caption = nil, lang = nil)
456
458
  puts %Q(<div class="emlist-code">)
457
- puts %Q(<p class="caption">#{compile_inline(caption)}</p>) if caption.present?
459
+ if caption.present?
460
+ puts %Q(<p class="caption">#{compile_inline(caption)}</p>)
461
+ end
458
462
  class_names = ['emlist']
459
463
  class_names.push("language-#{lang}") unless lang.blank?
460
464
  class_names.push('highlight') if highlight?
@@ -468,7 +472,9 @@ module ReVIEW
468
472
 
469
473
  def emlistnum(lines, caption = nil, lang = nil)
470
474
  puts %Q(<div class="emlistnum-code">)
471
- puts %Q(<p class="caption">#{compile_inline(caption)}</p>) if caption.present?
475
+ if caption.present?
476
+ puts %Q(<p class="caption">#{compile_inline(caption)}</p>)
477
+ end
472
478
 
473
479
  if highlight?
474
480
  body = lines.inject('') { |i, j| i + detab(j) + "\n" }
@@ -493,7 +499,9 @@ module ReVIEW
493
499
 
494
500
  def cmd(lines, caption = nil)
495
501
  puts %Q(<div class="cmd-code">)
496
- puts %Q(<p class="caption">#{compile_inline(caption)}</p>) if caption.present?
502
+ if caption.present?
503
+ puts %Q(<p class="caption">#{compile_inline(caption)}</p>)
504
+ end
497
505
  print %Q(<pre class="cmd">)
498
506
  body = lines.inject('') { |i, j| i + detab(j) + "\n" }
499
507
  lexer = 'shell-session'
@@ -537,17 +545,15 @@ module ReVIEW
537
545
  require 'math_ml'
538
546
  require 'math_ml/symbol/character_reference'
539
547
  p = MathML::LaTeX::Parser.new(symbol: MathML::Symbol::CharacterReference)
540
- puts p.parse(unescape_html(lines.join("\n")), true)
548
+ puts p.parse(unescape(lines.join("\n")), true)
541
549
  elsif @book.config['imgmath']
542
- puts %Q(<div class="equation">)
543
- math_str = "\\begin{equation*}\n" + unescape_html(lines.join("\n")) + "\n\\end{equation*}\n"
550
+ math_str = "\\begin{equation*}\n" + unescape(lines.join("\n")) + "\n\\end{equation*}\n"
544
551
  key = Digest::SHA256.hexdigest(math_str)
545
552
  math_dir = "./#{@book.config['imagedir']}/_review_math"
546
553
  Dir.mkdir(math_dir) unless Dir.exist?(math_dir)
547
554
  img_path = "./#{math_dir}/_gen_#{key}.png"
548
555
  make_math_image(math_str, img_path)
549
556
  puts %Q(<img src="#{img_path}" />)
550
- puts '</div>'
551
557
  else
552
558
  print '<pre>'
553
559
  puts lines.join("\n")
@@ -581,7 +587,7 @@ module ReVIEW
581
587
  def image_image(id, caption, metric)
582
588
  metrics = parse_metric('html', metric)
583
589
  puts %Q(<div id="#{normalize_id(id)}" class="image">)
584
- puts %Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />)
590
+ puts %Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="#{escape(compile_inline(caption))}"#{metrics} />)
585
591
  image_header id, caption
586
592
  puts '</div>'
587
593
  end
@@ -628,7 +634,9 @@ module ReVIEW
628
634
  puts %Q(<div class="table">)
629
635
  end
630
636
  begin
631
- table_header id, caption if caption.present?
637
+ if caption.present?
638
+ table_header id, caption
639
+ end
632
640
  rescue KeyError
633
641
  error "no such table: #{id}"
634
642
  end
@@ -690,7 +698,9 @@ module ReVIEW
690
698
 
691
699
  puts %Q(<div id="#{normalize_id(id)}" class="imgtable image">)
692
700
  begin
693
- table_header id, caption if caption.present?
701
+ if caption.present?
702
+ table_header id, caption
703
+ end
694
704
  rescue KeyError
695
705
  error "no such table: #{id}"
696
706
  end
@@ -702,7 +712,7 @@ module ReVIEW
702
712
 
703
713
  def imgtable_image(id, caption, metric)
704
714
  metrics = parse_metric('html', metric)
705
- puts %Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />)
715
+ puts %Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="#{escape(compile_inline(caption))}"#{metrics} />)
706
716
  end
707
717
 
708
718
  def emtable(lines, caption = nil)
@@ -714,7 +724,7 @@ module ReVIEW
714
724
  lines.unshift comment unless comment.blank?
715
725
  return unless @book.config['draft']
716
726
  str = lines.join('<br />')
717
- puts %Q(<div class="draft-comment">#{escape_html(str)}</div>)
727
+ puts %Q(<div class="draft-comment">#{escape(str)}</div>)
718
728
  end
719
729
 
720
730
  def footnote(id, str)
@@ -730,7 +740,7 @@ module ReVIEW
730
740
  caption = '' unless caption.present?
731
741
  puts %Q(<div id="#{normalize_id(id)}" class="image">)
732
742
  begin
733
- puts %Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="#{escape_html(compile_inline(caption))}"#{metrics} />)
743
+ puts %Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="#{escape(compile_inline(caption))}"#{metrics} />)
734
744
  rescue
735
745
  warn "image not bound: #{id}"
736
746
  if lines
@@ -781,7 +791,7 @@ module ReVIEW
781
791
  end
782
792
 
783
793
  def inline_labelref(idref)
784
- %Q(<a target='#{escape_html(idref)}'>「#{I18n.t('label_marker')}#{escape_html(idref)}」</a>)
794
+ %Q(<a target='#{escape(idref)}'>「#{I18n.t('label_marker')}#{escape(idref)}」</a>)
785
795
  end
786
796
 
787
797
  alias_method :inline_ref, :inline_labelref
@@ -834,50 +844,50 @@ module ReVIEW
834
844
 
835
845
  def compile_ruby(base, ruby)
836
846
  if @book.htmlversion == 5
837
- %Q(<ruby>#{escape_html(base)}<rp>#{I18n.t('ruby_prefix')}</rp><rt>#{escape_html(ruby)}</rt><rp>#{I18n.t('ruby_postfix')}</rp></ruby>)
847
+ %Q(<ruby>#{escape(base)}<rp>#{I18n.t('ruby_prefix')}</rp><rt>#{escape(ruby)}</rt><rp>#{I18n.t('ruby_postfix')}</rp></ruby>)
838
848
  else
839
- %Q(<ruby><rb>#{escape_html(base)}</rb><rp>#{I18n.t('ruby_prefix')}</rp><rt>#{ruby}</rt><rp>#{I18n.t('ruby_postfix')}</rp></ruby>)
849
+ %Q(<ruby><rb>#{escape(base)}</rb><rp>#{I18n.t('ruby_prefix')}</rp><rt>#{ruby}</rt><rp>#{I18n.t('ruby_postfix')}</rp></ruby>)
840
850
  end
841
851
  end
842
852
 
843
853
  def compile_kw(word, alt)
844
854
  %Q(<b class="kw">) +
845
855
  if alt
846
- then escape_html(word + " (#{alt.strip})")
847
- else escape_html(word)
856
+ then escape(word + " (#{alt.strip})")
857
+ else escape(word)
848
858
  end +
849
- "</b><!-- IDX:#{escape_comment(escape_html(word))} -->"
859
+ "</b><!-- IDX:#{escape_comment(escape(word))} -->"
850
860
  end
851
861
 
852
862
  def inline_i(str)
853
- %Q(<i>#{escape_html(str)}</i>)
863
+ %Q(<i>#{escape(str)}</i>)
854
864
  end
855
865
 
856
866
  def inline_b(str)
857
- %Q(<b>#{escape_html(str)}</b>)
867
+ %Q(<b>#{escape(str)}</b>)
858
868
  end
859
869
 
860
870
  def inline_ami(str)
861
- %Q(<span class="ami">#{escape_html(str)}</span>)
871
+ %Q(<span class="ami">#{escape(str)}</span>)
862
872
  end
863
873
 
864
874
  def inline_bou(str)
865
- %Q(<span class="bou">#{escape_html(str)}</span>)
875
+ %Q(<span class="bou">#{escape(str)}</span>)
866
876
  end
867
877
 
868
878
  def inline_tti(str)
869
879
  if @book.htmlversion == 5
870
- %Q(<code class="tt"><i>#{escape_html(str)}</i></code>)
880
+ %Q(<code class="tt"><i>#{escape(str)}</i></code>)
871
881
  else
872
- %Q(<tt><i>#{escape_html(str)}</i></tt>)
882
+ %Q(<tt><i>#{escape(str)}</i></tt>)
873
883
  end
874
884
  end
875
885
 
876
886
  def inline_ttb(str)
877
887
  if @book.htmlversion == 5
878
- %Q(<code class="tt"><b>#{escape_html(str)}</b></code>)
888
+ %Q(<code class="tt"><b>#{escape(str)}</b></code>)
879
889
  else
880
- %Q(<tt><b>#{escape_html(str)}</b></tt>)
890
+ %Q(<tt><b>#{escape(str)}</b></tt>)
881
891
  end
882
892
  end
883
893
 
@@ -887,18 +897,18 @@ module ReVIEW
887
897
 
888
898
  def inline_code(str)
889
899
  if @book.htmlversion == 5
890
- %Q(<code class="inline-code tt">#{escape_html(str)}</code>)
900
+ %Q(<code class="inline-code tt">#{escape(str)}</code>)
891
901
  else
892
- %Q(<tt class="inline-code">#{escape_html(str)}</tt>)
902
+ %Q(<tt class="inline-code">#{escape(str)}</tt>)
893
903
  end
894
904
  end
895
905
 
896
906
  def inline_idx(str)
897
- %Q(#{escape_html(str)}<!-- IDX:#{escape_comment(escape_html(str))} -->)
907
+ %Q(#{escape(str)}<!-- IDX:#{escape_comment(escape(str))} -->)
898
908
  end
899
909
 
900
910
  def inline_hidx(str)
901
- %Q(<!-- IDX:#{escape_comment(escape_html(str))} -->)
911
+ %Q(<!-- IDX:#{escape_comment(escape(str))} -->)
902
912
  end
903
913
 
904
914
  def inline_br(_str)
@@ -920,7 +930,7 @@ module ReVIEW
920
930
  make_math_image(math_str, img_path)
921
931
  %Q(<span class="equation"><img src="#{img_path}" /></span>)
922
932
  else
923
- %Q(<span class="equation">#{escape_html(str)}</span>)
933
+ %Q(<span class="equation">#{escape(str)}</span>)
924
934
  end
925
935
  end
926
936
 
@@ -1037,7 +1047,7 @@ module ReVIEW
1037
1047
  end
1038
1048
 
1039
1049
  def inline_asis(str, tag)
1040
- %Q(<#{tag}>#{escape_html(str)}</#{tag}>)
1050
+ %Q(<#{tag}>#{escape(str)}</#{tag}>)
1041
1051
  end
1042
1052
 
1043
1053
  def inline_abbr(str)
@@ -1094,9 +1104,9 @@ module ReVIEW
1094
1104
 
1095
1105
  def inline_tt(str)
1096
1106
  if @book.htmlversion == 5
1097
- %Q(<code class="tt">#{escape_html(str)}</code>)
1107
+ %Q(<code class="tt">#{escape(str)}</code>)
1098
1108
  else
1099
- %Q(<tt>#{escape_html(str)}</tt>)
1109
+ %Q(<tt>#{escape(str)}</tt>)
1100
1110
  end
1101
1111
  end
1102
1112
 
@@ -1109,11 +1119,11 @@ module ReVIEW
1109
1119
  end
1110
1120
 
1111
1121
  def inline_u(str)
1112
- %Q(<u>#{escape_html(str)}</u>)
1122
+ %Q(<u>#{escape(str)}</u>)
1113
1123
  end
1114
1124
 
1115
1125
  def inline_recipe(str)
1116
- %Q(<span class="recipe">「#{escape_html(str)}」</span>)
1126
+ %Q(<span class="recipe">「#{escape(str)}」</span>)
1117
1127
  end
1118
1128
 
1119
1129
  def inline_icon(id)
@@ -1131,7 +1141,7 @@ module ReVIEW
1131
1141
 
1132
1142
  def inline_comment(str)
1133
1143
  if @book.config['draft']
1134
- %Q(<span class="draft-comment">#{escape_html(str)}</span>)
1144
+ %Q(<span class="draft-comment">#{escape(str)}</span>)
1135
1145
  else
1136
1146
  ''
1137
1147
  end
@@ -1143,7 +1153,11 @@ module ReVIEW
1143
1153
  if str.size == 1 && str.match(/[[:ascii:]]/)
1144
1154
  style = 'upright'
1145
1155
  end
1146
- %Q(<span class="#{style}">#{escape_html(str)}</span>)
1156
+ %Q(<span class="#{style}">#{escape(str)}</span>)
1157
+ end
1158
+
1159
+ def inline_balloon(str)
1160
+ %Q(<span class="balloon">#{escape_html(str)}</span>)
1147
1161
  end
1148
1162
 
1149
1163
  def inline_raw(str)
@@ -1151,14 +1165,14 @@ module ReVIEW
1151
1165
  end
1152
1166
 
1153
1167
  def nofunc_text(str)
1154
- escape_html(str)
1168
+ escape(str)
1155
1169
  end
1156
1170
 
1157
1171
  def compile_href(url, label)
1158
1172
  if @book.config['externallink']
1159
- %Q(<a href="#{escape_html(url)}" class="link">#{label.nil? ? escape_html(url) : escape_html(label)}</a>)
1173
+ %Q(<a href="#{escape(url)}" class="link">#{label.nil? ? escape(url) : escape(label)}</a>)
1160
1174
  else
1161
- label.nil? ? escape_html(url) : I18n.t('external_link', [escape_html(label), escape_html(url)])
1175
+ label.nil? ? escape(url) : I18n.t('external_link', [escape(label), escape(url)])
1162
1176
  end
1163
1177
  end
1164
1178
 
@@ -1199,7 +1213,11 @@ module ReVIEW
1199
1213
  tex_path = File.join(tmpdir, 'tmpmath.tex')
1200
1214
  dvi_path = File.join(tmpdir, 'tmpmath.dvi')
1201
1215
  File.write(tex_path, texsrc)
1202
- system("latex --interaction=nonstopmode --output-directory=#{tmpdir} #{tex_path} && dvipng -T tight -z9 -o #{path} #{dvi_path}")
1216
+ cmd = "latex --interaction=nonstopmode --output-directory=#{tmpdir} #{tex_path} && dvipng -T tight -z9 -o #{path} #{dvi_path}"
1217
+ out, status = Open3.capture2e(cmd)
1218
+ unless status.success?
1219
+ error "latex compile error\n\nError log:\n" + out
1220
+ end
1203
1221
  end
1204
1222
  end
1205
1223
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2006-2017 Minero Aoki, Kenshi Muto
2
+ # Copyright (c) 2006-2018 Minero Aoki, Kenshi Muto
3
3
  # 2002-2006 Minero Aoki
4
4
  #
5
5
  # This program is free software.
@@ -17,20 +17,20 @@ module ReVIEW
17
17
  '"' => '&quot;'
18
18
  } # .freeze
19
19
 
20
- def escape_html(str)
20
+ def escape(str)
21
21
  t = ESC
22
22
  str.gsub(/[&"<>]/) { |c| t[c] }
23
23
  end
24
24
 
25
- alias_method :escape, :escape_html
26
- alias_method :h, :escape_html
25
+ alias_method :escape_html, :escape # for backward compatibility
26
+ alias_method :h, :escape
27
27
 
28
- def unescape_html(str)
28
+ def unescape(str)
29
29
  # FIXME: better code
30
30
  str.gsub('&quot;', '"').gsub('&gt;', '>').gsub('&lt;', '<').gsub('&amp;', '&')
31
31
  end
32
32
 
33
- alias_method :unescape, :unescape_html
33
+ alias_method :unescape_html, :unescape # for backward compatibility
34
34
 
35
35
  def strip_html(str)
36
36
  str.gsub(%r{</?[^>]*>}, '')
@@ -62,13 +62,14 @@ module ReVIEW
62
62
 
63
63
  def highlight_pygments(ops)
64
64
  body = ops[:body] || ''
65
- if @book.config['highlight'] && @book.config['highlight']['lang']
65
+ format = ops[:format] || ''
66
+ if ops[:lexer].present?
67
+ lexer = ops[:lexer]
68
+ elsif @book.config['highlight'] && @book.config['highlight']['lang']
66
69
  lexer = @book.config['highlight']['lang'] # default setting
67
70
  else
68
71
  lexer = 'text'
69
72
  end
70
- lexer = ops[:lexer] if ops[:lexer].present?
71
- format = ops[:format] || ''
72
73
  options = { nowrap: true, noclasses: true }
73
74
  if ops[:linenum]
74
75
  options[:nowrap] = false
@@ -81,7 +82,7 @@ module ReVIEW
81
82
  begin
82
83
  require 'pygments'
83
84
  begin
84
- Pygments.highlight(unescape_html(body),
85
+ Pygments.highlight(unescape(body),
85
86
  options: options,
86
87
  formatter: format,
87
88
  lexer: lexer)
@@ -111,7 +112,10 @@ module ReVIEW
111
112
 
112
113
  require 'rouge'
113
114
  lexer = Rouge::Lexer.find(lexer)
114
- raise "unknown lexer #{lexer}" unless lexer
115
+
116
+ unless lexer
117
+ return body
118
+ end
115
119
 
116
120
  formatter = Rouge::Formatters::HTML.new(css_class: 'highlight')
117
121
  if ops[:linenum]
@@ -119,9 +123,12 @@ module ReVIEW
119
123
  table_class: 'highlight rouge-table',
120
124
  start_line: first_line_num)
121
125
  end
122
- raise "unknown formatter #{formatter}" unless formatter
123
126
 
124
- text = unescape_html(body)
127
+ unless formatter
128
+ return body
129
+ end
130
+
131
+ text = unescape(body)
125
132
  formatter.format(lexer.lex(text))
126
133
  end
127
134
 
data/lib/review/i18n.rb CHANGED
@@ -21,10 +21,14 @@ module ReVIEW
21
21
  lfile = File.expand_path(ymlfile, Dir.pwd)
22
22
 
23
23
  # backward compatibility
24
- raise ReVIEW::ConfigError, 'locale.yaml is obsoleted. Please use locale.yml.' if !File.exist?(lfile) && (ymlfile == 'locale.yml') && File.exist?(File.expand_path('locale.yaml', Dir.pwd))
24
+ if !File.exist?(lfile) && (ymlfile == 'locale.yml') && File.exist?(File.expand_path('locale.yaml', Dir.pwd))
25
+ raise ReVIEW::ConfigError, 'locale.yaml is obsoleted. Please use locale.yml.'
26
+ end
25
27
  end
26
28
 
27
- @i18n.update_localefile(lfile) if lfile && File.file?(lfile)
29
+ if lfile && File.file?(lfile)
30
+ @i18n.update_localefile(lfile)
31
+ end
28
32
  end
29
33
 
30
34
  def self.i18n(*_args)