review 2.5.0 → 3.0.0.preview1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +28 -10
- data/.travis.yml +11 -2
- data/NEWS.ja.md +89 -17
- data/NEWS.md +92 -0
- data/README.md +1 -1
- data/Rakefile +0 -13
- data/bin/review-catalog-converter +83 -37
- data/bin/review-check +17 -5
- data/bin/review-compile +1 -1
- data/bin/review-index +6 -0
- data/bin/review-init +3 -155
- data/bin/review-preproc +0 -5
- data/bin/review-validate +21 -7
- data/bin/review-vol +13 -5
- data/doc/config.yml.sample +12 -7
- data/doc/config.yml.sample-simple +1 -1
- data/doc/format.ja.md +39 -3
- data/doc/format.md +39 -3
- data/doc/format_idg.ja.md +0 -4
- data/doc/pdfmaker.ja.md +1 -1
- data/doc/pdfmaker.md +1 -1
- data/doc/sample.css +7 -0
- data/lib/epubmaker/content.rb +31 -12
- data/lib/epubmaker/epubcommon.rb +10 -3
- data/lib/epubmaker/epubv2.rb +11 -3
- data/lib/epubmaker/epubv3.rb +11 -3
- data/lib/epubmaker/producer.rb +55 -20
- data/lib/review/book/base.rb +63 -48
- data/lib/review/book/chapter.rb +19 -7
- data/lib/review/book/compilable.rb +5 -20
- data/lib/review/book/image_finder.rb +10 -3
- data/lib/review/book/index.rb +30 -9
- data/lib/review/book/part.rb +9 -6
- data/lib/review/book.rb +0 -14
- data/lib/review/builder.rb +110 -18
- data/lib/review/catalog.rb +24 -4
- data/lib/review/compiler.rb +3 -1
- data/lib/review/configure.rb +43 -9
- data/lib/review/epubmaker/reviewheaderlistener.rb +57 -0
- data/lib/review/epubmaker.rb +129 -85
- data/lib/review/htmlbuilder.rb +76 -58
- data/lib/review/htmlutils.rb +20 -13
- data/lib/review/i18n.rb +6 -2
- data/lib/review/idgxmlbuilder.rb +52 -41
- data/lib/review/init.rb +194 -0
- data/lib/review/latexbuilder.rb +118 -34
- data/lib/review/latexutils.rb +5 -5
- data/lib/review/logger.rb +2 -1
- data/lib/review/makerhelper.rb +1 -1
- data/lib/review/markdownbuilder.rb +66 -6
- data/lib/review/md2inaobuilder.rb +2 -2
- data/lib/review/pdfmaker.rb +74 -22
- data/lib/review/plaintextbuilder.rb +8 -4
- data/lib/review/preprocessor.rb +14 -17
- data/lib/review/sec_counter.rb +8 -2
- data/lib/review/textmaker.rb +2 -2
- data/lib/review/textutils.rb +9 -2
- data/lib/review/tocparser.rb +7 -4
- data/lib/review/tocprinter.rb +3 -1
- data/lib/review/version.rb +1 -1
- data/lib/review/webmaker.rb +19 -7
- data/lib/review/webtocprinter.rb +8 -4
- data/review.gemspec +4 -3
- data/templates/latex/config.erb +84 -0
- data/templates/latex/layout.tex.erb +76 -361
- data/templates/latex/review-jlreq/README.md +22 -0
- data/templates/latex/review-jlreq/review-base.sty +178 -0
- data/templates/latex/review-jlreq/review-custom.sty +1 -0
- data/templates/latex/review-jlreq/review-jlreq.cls +141 -0
- data/templates/latex/review-jlreq/review-style.sty +149 -0
- data/templates/latex/review-jlreq/reviewmacro.sty +8 -0
- data/templates/latex/review-jsbook/jumoline.sty +310 -0
- data/templates/latex/review-jsbook/plistings.sty +326 -0
- data/templates/latex/review-jsbook/review-base.sty +405 -0
- data/templates/latex/review-jsbook/review-custom.sty +1 -0
- data/templates/latex/review-jsbook/review-style.sty +38 -0
- data/templates/latex/review-jsbook/reviewmacro.sty +8 -0
- data/templates/latex-compat2/layout.tex.erb +387 -0
- data/test/assets/test_template.tex +105 -235
- data/test/assets/test_template_backmatter.tex +133 -14
- data/test/book_test_helper.rb +1 -1
- data/test/run_test.rb +2 -0
- data/test/sample-book/src/Rakefile +11 -6
- data/test/sample-book/src/config.yml +2 -2
- data/test/sample-book/src/sty/reviewmacro.sty +1 -39
- data/test/sample-book/src/style.css +6 -0
- data/test/syntax-book/config.yml +1 -1
- data/test/test_book.rb +13 -16
- data/test/test_book_chapter.rb +4 -10
- data/test/test_book_part.rb +4 -3
- data/test/test_catalog.rb +15 -4
- data/test/test_helper.rb +2 -2
- data/test/test_htmlbuilder.rb +78 -10
- data/test/test_htmlutils.rb +12 -5
- data/test/test_idgxmlbuilder.rb +1 -1
- data/test/test_latexbuilder.rb +94 -49
- data/test/test_latexbuilder_v2.rb +1077 -0
- data/test/test_logger.rb +20 -0
- data/test/test_markdownbuilder.rb +10 -0
- data/test/test_pdfmaker.rb +6 -7
- data/test/test_plaintextbuilder.rb +1 -1
- data/test/test_review_ext.rb +0 -1
- data/test/test_rstbuilder.rb +1 -1
- data/test/test_topbuilder.rb +19 -7
- data/test/test_webtocprinter.rb +14 -14
- data/{test/sample-book/src/vendor → vendor}/jumoline/README +0 -0
- data/{test/sample-book/src/vendor → vendor}/jumoline/jumoline.dtx +0 -0
- data/{test/sample-book/src/vendor → vendor}/jumoline/jumoline.ins +0 -0
- data/{test/sample-book/src/vendor → vendor}/jumoline/lppl.txt +0 -0
- data/vendor/plistings/.gitignore +9 -0
- data/vendor/plistings/LICENSE +21 -0
- data/vendor/plistings/README.md +18 -0
- data/vendor/plistings/plistings.sty +326 -0
- data/vendor/plistings/test1.tex +174 -0
- data/vendor/plistings/test2.tex +54 -0
- metadata +48 -19
- data/lib/review/unfold.rb +0 -129
- data/test/CHAPS +0 -2
- data/test/bib.re +0 -13
- data/test/test.re +0 -43
data/lib/review/htmlbuilder.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
-
|
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(
|
393
|
-
id ||= ''
|
394
|
+
def list_body(_id, lines, lang)
|
394
395
|
class_names = ['list']
|
395
|
-
lexer = lang
|
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
|
-
|
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(
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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(
|
548
|
+
puts p.parse(unescape(lines.join("\n")), true)
|
541
549
|
elsif @book.config['imgmath']
|
542
|
-
|
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="#{
|
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
|
-
|
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
|
-
|
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="#{
|
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">#{
|
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="#{
|
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='#{
|
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>#{
|
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>#{
|
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
|
847
|
-
else
|
856
|
+
then escape(word + " (#{alt.strip})")
|
857
|
+
else escape(word)
|
848
858
|
end +
|
849
|
-
"</b><!-- IDX:#{escape_comment(
|
859
|
+
"</b><!-- IDX:#{escape_comment(escape(word))} -->"
|
850
860
|
end
|
851
861
|
|
852
862
|
def inline_i(str)
|
853
|
-
%Q(<i>#{
|
863
|
+
%Q(<i>#{escape(str)}</i>)
|
854
864
|
end
|
855
865
|
|
856
866
|
def inline_b(str)
|
857
|
-
%Q(<b>#{
|
867
|
+
%Q(<b>#{escape(str)}</b>)
|
858
868
|
end
|
859
869
|
|
860
870
|
def inline_ami(str)
|
861
|
-
%Q(<span class="ami">#{
|
871
|
+
%Q(<span class="ami">#{escape(str)}</span>)
|
862
872
|
end
|
863
873
|
|
864
874
|
def inline_bou(str)
|
865
|
-
%Q(<span class="bou">#{
|
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>#{
|
880
|
+
%Q(<code class="tt"><i>#{escape(str)}</i></code>)
|
871
881
|
else
|
872
|
-
%Q(<tt><i>#{
|
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>#{
|
888
|
+
%Q(<code class="tt"><b>#{escape(str)}</b></code>)
|
879
889
|
else
|
880
|
-
%Q(<tt><b>#{
|
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">#{
|
900
|
+
%Q(<code class="inline-code tt">#{escape(str)}</code>)
|
891
901
|
else
|
892
|
-
%Q(<tt class="inline-code">#{
|
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(#{
|
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(
|
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">#{
|
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}>#{
|
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">#{
|
1107
|
+
%Q(<code class="tt">#{escape(str)}</code>)
|
1098
1108
|
else
|
1099
|
-
%Q(<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>#{
|
1122
|
+
%Q(<u>#{escape(str)}</u>)
|
1113
1123
|
end
|
1114
1124
|
|
1115
1125
|
def inline_recipe(str)
|
1116
|
-
%Q(<span class="recipe">「#{
|
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">#{
|
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}">#{
|
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
|
-
|
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="#{
|
1173
|
+
%Q(<a href="#{escape(url)}" class="link">#{label.nil? ? escape(url) : escape(label)}</a>)
|
1160
1174
|
else
|
1161
|
-
label.nil? ?
|
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
|
-
|
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
|
data/lib/review/htmlutils.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright (c) 2006-
|
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
|
'"' => '"'
|
18
18
|
} # .freeze
|
19
19
|
|
20
|
-
def
|
20
|
+
def escape(str)
|
21
21
|
t = ESC
|
22
22
|
str.gsub(/[&"<>]/) { |c| t[c] }
|
23
23
|
end
|
24
24
|
|
25
|
-
alias_method :
|
26
|
-
alias_method :h, :
|
25
|
+
alias_method :escape_html, :escape # for backward compatibility
|
26
|
+
alias_method :h, :escape
|
27
27
|
|
28
|
-
def
|
28
|
+
def unescape(str)
|
29
29
|
# FIXME: better code
|
30
30
|
str.gsub('"', '"').gsub('>', '>').gsub('<', '<').gsub('&', '&')
|
31
31
|
end
|
32
32
|
|
33
|
-
alias_method :
|
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
|
-
|
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(
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
29
|
+
if lfile && File.file?(lfile)
|
30
|
+
@i18n.update_localefile(lfile)
|
31
|
+
end
|
28
32
|
end
|
29
33
|
|
30
34
|
def self.i18n(*_args)
|