review 5.0.0 → 5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby-tex.yml +35 -0
- data/.github/workflows/ruby-win.yml +8 -4
- data/.github/workflows/ruby.yml +6 -2
- data/.rubocop.yml +24 -9
- data/NEWS.ja.md +215 -0
- data/NEWS.md +215 -1
- data/README.md +7 -6
- data/Rakefile +7 -2
- data/bin/review +2 -4
- data/bin/review-catalog-converter +3 -3
- data/bin/review-check +6 -8
- data/bin/review-checkdep +1 -4
- data/bin/review-compile +10 -20
- data/bin/review-epub2html +1 -4
- data/bin/review-epubmaker +3 -4
- data/bin/review-idgxmlmaker +1 -3
- data/bin/review-index +11 -5
- data/bin/review-init +1 -4
- data/bin/review-pdfmaker +1 -3
- data/bin/review-preproc +30 -38
- data/bin/review-textmaker +1 -3
- data/bin/review-update +1 -4
- data/bin/review-validate +3 -3
- data/bin/review-vol +1 -4
- data/bin/review-webmaker +1 -3
- data/doc/config.yml.sample +23 -5
- data/doc/config.yml.sample-simple +1 -1
- data/doc/format.ja.md +49 -12
- data/doc/format.md +52 -12
- data/doc/quickstart.ja.md +11 -1
- data/doc/quickstart.md +11 -2
- data/doc/writing_vertical.ja.md +6 -0
- data/lib/review/book/base.rb +4 -0
- data/lib/review/book/book_unit.rb +15 -2
- data/lib/review/book/chapter.rb +3 -0
- data/lib/review/book/index.rb +5 -1
- data/lib/review/book/volume.rb +1 -0
- data/lib/review/builder.rb +90 -54
- data/lib/review/call_hook.rb +20 -0
- data/lib/review/catalog.rb +2 -0
- data/lib/review/compiler.rb +88 -52
- data/lib/review/configure.rb +64 -7
- data/lib/review/epubmaker/content.rb +113 -0
- data/lib/review/epubmaker/epubcommon.rb +372 -0
- data/lib/review/epubmaker/epubv2.rb +178 -0
- data/lib/review/epubmaker/epubv3.rb +231 -0
- data/lib/review/epubmaker/producer.rb +167 -0
- data/lib/review/epubmaker/reviewheaderlistener.rb +12 -2
- data/lib/review/epubmaker/zip_exporter.rb +84 -0
- data/lib/review/epubmaker.rb +114 -129
- data/lib/review/exception.rb +13 -0
- data/lib/review/htmlbuilder.rb +109 -67
- data/lib/review/htmlutils.rb +1 -1
- data/lib/review/i18n.rb +1 -0
- data/lib/review/i18n.yml +6 -0
- data/lib/review/idgxmlbuilder.rb +72 -48
- data/lib/review/idgxmlmaker.rb +15 -14
- data/lib/review/img_math.rb +239 -0
- data/lib/review/index_builder.rb +90 -32
- data/lib/review/init.rb +4 -4
- data/lib/review/latexbox.rb +58 -0
- data/lib/review/latexbuilder.rb +79 -58
- data/lib/review/latexutils.rb +9 -1
- data/lib/review/lineinput.rb +112 -2
- data/lib/review/loggable.rb +27 -0
- data/lib/review/logger.rb +89 -2
- data/lib/review/makerhelper.rb +7 -206
- data/lib/review/markdownbuilder.rb +44 -4
- data/lib/review/pdfmaker.rb +70 -51
- data/lib/review/plaintextbuilder.rb +20 -11
- data/lib/review/preprocessor/directive.rb +35 -0
- data/lib/review/preprocessor/line.rb +34 -0
- data/lib/review/preprocessor/repository.rb +177 -0
- data/lib/review/preprocessor.rb +105 -301
- data/lib/review/rstbuilder.rb +13 -4
- data/lib/review/sec_counter.rb +1 -0
- data/lib/review/template.rb +11 -1
- data/lib/review/textmaker.rb +23 -20
- data/lib/review/textutils.rb +10 -17
- data/lib/review/tocprinter.rb +93 -71
- data/lib/review/topbuilder.rb +44 -19
- data/lib/review/update.rb +5 -6
- data/lib/review/version.rb +1 -1
- data/lib/review/volumeprinter.rb +11 -12
- data/lib/review/webmaker.rb +31 -27
- data/lib/review/webtocprinter.rb +10 -9
- data/lib/review/yamlloader.rb +2 -1
- data/lib/review.rb +1 -1
- data/review.gemspec +5 -3
- data/samples/sample-book/src/config-epub2.yml +1 -1
- data/samples/sample-book/src/config.yml +1 -1
- data/samples/sample-book/src/lib/tasks/review.rake +19 -1
- data/samples/sample-book/src/lib/tasks/z01_copy_sty.rake +2 -1
- data/samples/syntax-book/ch01.re +1 -1
- data/samples/syntax-book/ch02.re +30 -6
- data/samples/syntax-book/ch03.re +1 -1
- data/samples/syntax-book/images/img3-2.png +0 -0
- data/samples/syntax-book/lib/tasks/z01_copy_sty.rake +2 -1
- data/templates/html/_colophon.html.erb +23 -0
- data/templates/html/_colophon_history.html.erb +9 -0
- data/templates/html/_cover.html.erb +10 -0
- data/templates/html/_part_body.html.erb +6 -0
- data/templates/html/_titlepage.html.erb +20 -0
- data/templates/html/layout-html5.html.erb +6 -0
- data/templates/html/layout-xhtml1.html.erb +6 -0
- data/templates/latex/config.erb +11 -0
- data/templates/latex/review-jlreq/review-base.sty +7 -9
- data/templates/latex/review-jlreq/review-jlreq.cls +48 -6
- data/templates/latex/review-jlreq/review-style.sty +6 -1
- data/templates/latex/review-jlreq/review-tcbox.sty +348 -0
- data/templates/latex/review-jlreq/reviewmacro.sty +5 -0
- data/templates/latex/review-jsbook/review-base.sty +13 -9
- data/templates/latex/review-jsbook/review-jsbook.cls +41 -6
- data/templates/latex/review-jsbook/review-style.sty +6 -1
- data/templates/latex/review-jsbook/review-tcbox.sty +348 -0
- data/templates/latex/review-jsbook/reviewmacro.sty +5 -0
- data/templates/opf/epubv2.opf.erb +7 -7
- data/templates/opf/epubv3.opf.erb +7 -7
- data/templates/opf/opf_manifest_epubv2.opf.erb +10 -0
- data/templates/opf/opf_manifest_epubv3.opf.erb +10 -0
- data/templates/opf/opf_metainfo_epubv2.opf.erb +17 -0
- data/templates/opf/opf_metainfo_epubv3.opf.erb +49 -0
- data/templates/opf/opf_tocx_epubv2.opf.erb +9 -0
- data/templates/opf/opf_tocx_epubv3.opf.erb +17 -0
- data/templates/web/html/layout-html5.html.erb +6 -5
- data/templates/web/html/layout-xhtml1.html.erb +6 -0
- data/test/assets/header_listener.html +35 -0
- data/test/assets/img_math/img1.png +0 -0
- data/test/assets/img_math/img2.png +0 -0
- data/test/assets/img_math/img3.png +0 -0
- data/test/assets/syntax_book_index_detail.txt +60 -0
- data/test/assets/test_template.tex +7 -1
- data/test/assets/test_template_backmatter.tex +7 -1
- data/test/run_test.rb +1 -1
- data/test/test_book_chapter.rb +27 -4
- data/test/test_builder.rb +10 -8
- data/test/test_catalog_converter_cmd.rb +1 -1
- data/test/test_epub3maker.rb +168 -124
- data/test/test_epubmaker.rb +248 -131
- data/test/test_epubmaker_cmd.rb +15 -4
- data/test/test_helper.rb +5 -4
- data/test/test_htmlbuilder.rb +170 -31
- data/test/test_idgxmlbuilder.rb +44 -23
- data/test/test_idgxmlmaker_cmd.rb +7 -3
- data/test/test_img_math.rb +111 -0
- data/test/test_index.rb +30 -4
- data/test/test_indexbuilder.rb +5 -5
- data/test/test_latexbuilder.rb +151 -26
- data/test/test_latexbuilder_v2.rb +18 -10
- data/test/test_lineinput.rb +20 -93
- data/test/test_markdownbuilder.rb +42 -0
- data/test/test_pdfmaker.rb +90 -0
- data/test/test_pdfmaker_cmd.rb +2 -2
- data/test/test_plaintextbuilder.rb +56 -40
- data/test/test_preprocessor.rb +188 -1
- data/test/test_reviewheaderlistener.rb +49 -0
- data/test/test_rstbuilder.rb +13 -0
- data/test/test_template.rb +12 -2
- data/test/test_textmaker_cmd.rb +5 -1
- data/test/test_tocprinter.rb +46 -0
- data/test/test_topbuilder.rb +50 -19
- data/test/test_update.rb +34 -34
- data/test/test_zip_exporter.rb +5 -6
- metadata +95 -17
- data/lib/epubmaker/content.rb +0 -111
- data/lib/epubmaker/epubcommon.rb +0 -449
- data/lib/epubmaker/epubv2.rb +0 -142
- data/lib/epubmaker/epubv3.rb +0 -235
- data/lib/epubmaker/producer.rb +0 -375
- data/lib/epubmaker/zip_exporter.rb +0 -81
- data/lib/epubmaker.rb +0 -23
- data/lib/lineinput.rb +0 -155
data/lib/review/htmlbuilder.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2008-
|
1
|
+
# Copyright (c) 2008-2021 Minero Aoki, Kenshi Muto, Masayoshi Takahashi,
|
2
2
|
# KADO Masanori
|
3
3
|
# 2002-2007 Minero Aoki
|
4
4
|
#
|
@@ -42,17 +42,20 @@ module ReVIEW
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def builder_init_file
|
45
|
+
super
|
45
46
|
@noindent = nil
|
46
47
|
@ol_num = nil
|
47
|
-
@warns = []
|
48
|
-
@errors = []
|
49
48
|
@chapter.book.image_types = %w[.png .jpg .jpeg .gif .svg]
|
50
49
|
@column = 0
|
51
|
-
@sec_counter = SecCounter.new(5, @chapter)
|
52
50
|
@nonum_counter = 0
|
53
51
|
@first_line_num = nil
|
54
52
|
@body_ext = nil
|
55
53
|
@toc = nil
|
54
|
+
@javascripts = []
|
55
|
+
@section_stack = []
|
56
|
+
|
57
|
+
maker = @book.config.maker || 'epubmaker' # for review-compile
|
58
|
+
@use_section = @book.config[maker] && @book.config[maker]['use_section']
|
56
59
|
end
|
57
60
|
private :builder_init_file
|
58
61
|
|
@@ -74,9 +77,10 @@ module ReVIEW
|
|
74
77
|
if !File.exist?(layout_file) && File.exist?(File.join(@book.basedir, 'layouts', 'layout.erb'))
|
75
78
|
raise ReVIEW::ConfigError, 'layout.erb is obsoleted. Please use layout.html.erb.'
|
76
79
|
end
|
80
|
+
|
77
81
|
if File.exist?(layout_file)
|
78
82
|
if ENV['REVIEW_SAFE_MODE'].to_i & 4 > 0
|
79
|
-
warn %Q(user's layout is prohibited in safe mode. ignored.)
|
83
|
+
warn %Q(user's layout is prohibited in safe mode. ignored.), location: location
|
80
84
|
layout_file = File.expand_path(htmlfilename, ReVIEW::Template::TEMPLATE_DIR)
|
81
85
|
end
|
82
86
|
else
|
@@ -85,7 +89,35 @@ module ReVIEW
|
|
85
89
|
layout_file
|
86
90
|
end
|
87
91
|
|
92
|
+
def use_section?
|
93
|
+
@use_section
|
94
|
+
end
|
95
|
+
|
96
|
+
def open_section(level)
|
97
|
+
result = []
|
98
|
+
|
99
|
+
while @section_stack.size > 0 && level <= @section_stack[-1]
|
100
|
+
result << '</section>'
|
101
|
+
@section_stack.pop
|
102
|
+
end
|
103
|
+
@section_stack.push(level)
|
104
|
+
result << %Q(<section class="level#{level}">)
|
105
|
+
|
106
|
+
return result.join("\n")
|
107
|
+
end
|
108
|
+
|
109
|
+
def close_sections
|
110
|
+
"</section>\n" * @section_stack.size
|
111
|
+
end
|
112
|
+
|
88
113
|
def result
|
114
|
+
check_printendnotes
|
115
|
+
|
116
|
+
# flush all `</section>`
|
117
|
+
if use_section?
|
118
|
+
print close_sections
|
119
|
+
end
|
120
|
+
|
89
121
|
# default XHTML header/footer
|
90
122
|
@title = strip_html(compile_inline(@chapter.title))
|
91
123
|
@body = solve_nest(@output.string)
|
@@ -100,6 +132,11 @@ module ReVIEW
|
|
100
132
|
@toc = ReVIEW::WEBTOCPrinter.book_to_string(@book)
|
101
133
|
end
|
102
134
|
|
135
|
+
if @book.config['math_format'] == 'mathjax'
|
136
|
+
@javascripts.push(%Q(<script>MathJax = { tex: { inlineMath: [['\\\\(', '\\\\)']] }, svg: { fontCache: 'global' } };</script>))
|
137
|
+
@javascripts.push(%Q(<script type="text/javascript" id="MathJax-script" async="true" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>))
|
138
|
+
end
|
139
|
+
|
103
140
|
ReVIEW::Template.load(layoutfile).result(binding)
|
104
141
|
end
|
105
142
|
|
@@ -126,6 +163,9 @@ module ReVIEW
|
|
126
163
|
end
|
127
164
|
|
128
165
|
def headline(level, label, caption)
|
166
|
+
if use_section?
|
167
|
+
print open_section(level)
|
168
|
+
end
|
129
169
|
prefix, anchor = headline_prefix(level)
|
130
170
|
if prefix
|
131
171
|
prefix = %Q(<span class="secno">#{prefix}</span>)
|
@@ -149,6 +189,7 @@ module ReVIEW
|
|
149
189
|
@nonum_counter += 1
|
150
190
|
puts if level > 1
|
151
191
|
return unless caption.present?
|
192
|
+
|
152
193
|
if label
|
153
194
|
puts %Q(<h#{level} id="#{normalize_id(label)}">#{compile_inline(caption)}</h#{level}>)
|
154
195
|
else
|
@@ -164,6 +205,7 @@ module ReVIEW
|
|
164
205
|
@nonum_counter += 1
|
165
206
|
puts if level > 1
|
166
207
|
return unless caption.present?
|
208
|
+
|
167
209
|
if label
|
168
210
|
puts %Q(<h#{level} id="#{normalize_id(label)}" notoc="true">#{compile_inline(caption)}</h#{level}>)
|
169
211
|
else
|
@@ -179,6 +221,7 @@ module ReVIEW
|
|
179
221
|
@nonum_counter += 1
|
180
222
|
puts '' if level > 1
|
181
223
|
return unless caption.present?
|
224
|
+
|
182
225
|
if label
|
183
226
|
puts %Q(<a id="#{normalize_id(label)}" /><h#{level} id="#{normalize_id(label)}" hidden="true">#{compile_inline(caption)}</h#{level}>)
|
184
227
|
else
|
@@ -603,24 +646,27 @@ module ReVIEW
|
|
603
646
|
|
604
647
|
def texequation_body(lines)
|
605
648
|
puts %Q(<div class="equation">)
|
606
|
-
if @book.config['mathml'
|
607
|
-
|
608
|
-
|
649
|
+
if @book.config['math_format'] == 'mathml'
|
650
|
+
begin
|
651
|
+
require 'math_ml'
|
652
|
+
require 'math_ml/symbol/character_reference'
|
653
|
+
rescue LoadError
|
654
|
+
app_error 'not found math_ml'
|
655
|
+
end
|
609
656
|
p = MathML::LaTeX::Parser.new(symbol: MathML::Symbol::CharacterReference)
|
610
657
|
print p.parse(lines.join("\n") + "\n", true)
|
611
|
-
elsif @book.config['
|
658
|
+
elsif @book.config['math_format'] == 'mathjax'
|
659
|
+
puts "$$#{lines.join("\n")}$$"
|
660
|
+
elsif @book.config['math_format'] == 'imgmath'
|
612
661
|
fontsize = @book.config['imgmath_options']['fontsize'].to_f
|
613
662
|
lineheight = @book.config['imgmath_options']['lineheight'].to_f
|
614
663
|
math_str = "\\begin{equation*}\n\\fontsize{#{fontsize}}{#{lineheight}}\\selectfont\n#{lines.join("\n")}\n\\end{equation*}\n"
|
615
664
|
key = Digest::SHA256.hexdigest(math_str)
|
616
|
-
math_dir = File.join(@book.config['imagedir'], '_review_math')
|
617
|
-
Dir.mkdir(math_dir) unless Dir.exist?(math_dir)
|
618
|
-
img_path = File.join(math_dir, "_gen_#{key}.#{@book.config['imgmath_options']['format']}")
|
619
665
|
if @book.config.check_version('2', exception: false)
|
620
|
-
make_math_image(math_str,
|
666
|
+
img_path = @img_math.make_math_image(math_str, key)
|
621
667
|
puts %Q(<img src="#{img_path}" />)
|
622
668
|
else
|
623
|
-
defer_math_image(math_str,
|
669
|
+
img_path = @img_math.defer_math_image(math_str, key)
|
624
670
|
puts %Q(<img src="#{img_path}" class="math_gen_#{key}" alt="#{escape(lines.join(' '))}" />)
|
625
671
|
end
|
626
672
|
else
|
@@ -663,7 +709,7 @@ module ReVIEW
|
|
663
709
|
end
|
664
710
|
|
665
711
|
def image_dummy(id, caption, lines)
|
666
|
-
warn "image not bound: #{id}"
|
712
|
+
warn "image not bound: #{id}", location: location
|
667
713
|
puts %Q(<div id="#{normalize_id(id)}" class="image">)
|
668
714
|
image_header(id, caption) if caption_top?('image')
|
669
715
|
puts %Q(<pre class="dummyimage">)
|
@@ -727,7 +773,7 @@ module ReVIEW
|
|
727
773
|
|
728
774
|
def imgtable(lines, id, caption = nil, metric = nil)
|
729
775
|
unless @chapter.image_bound?(id)
|
730
|
-
warn "image not bound: #{id}"
|
776
|
+
warn "image not bound: #{id}", location: location
|
731
777
|
image_dummy(id, caption, lines)
|
732
778
|
return
|
733
779
|
end
|
@@ -744,7 +790,7 @@ module ReVIEW
|
|
744
790
|
table_header(id, caption)
|
745
791
|
end
|
746
792
|
rescue KeyError
|
747
|
-
|
793
|
+
app_error "no such table: #{id}"
|
748
794
|
end
|
749
795
|
|
750
796
|
puts '</div>'
|
@@ -761,6 +807,7 @@ module ReVIEW
|
|
761
807
|
|
762
808
|
def comment(lines, comment = nil)
|
763
809
|
return unless @book.config['draft']
|
810
|
+
|
764
811
|
lines ||= []
|
765
812
|
lines.unshift(escape(comment)) unless comment.blank?
|
766
813
|
str = lines.join('<br />')
|
@@ -780,6 +827,22 @@ module ReVIEW
|
|
780
827
|
end
|
781
828
|
end
|
782
829
|
|
830
|
+
def endnote_begin
|
831
|
+
puts %Q(<div class="endnotes">)
|
832
|
+
end
|
833
|
+
|
834
|
+
def endnote_end
|
835
|
+
puts %Q(</div>)
|
836
|
+
end
|
837
|
+
|
838
|
+
def endnote_item(id)
|
839
|
+
back = ''
|
840
|
+
if @book.config['epubmaker'] && @book.config['epubmaker']['back_footnote']
|
841
|
+
back = %Q(<a href="#endnoteb-#{normalize_id(id)}">#{I18n.t('html_footnote_backmark')}</a>)
|
842
|
+
end
|
843
|
+
puts %Q(<div class="endnote" id="endnote-#{normalize_id(id)}"><p class="endnote">#{back}#{I18n.t('html_endnote_textmark', @chapter.endnote(id).number)}#{compile_inline(@chapter.endnote(id).content)}</p></div>)
|
844
|
+
end
|
845
|
+
|
783
846
|
def indepimage(lines, id, caption = '', metric = nil)
|
784
847
|
metrics = parse_metric('html', metric)
|
785
848
|
caption = '' unless caption.present?
|
@@ -799,7 +862,7 @@ EOS
|
|
799
862
|
begin
|
800
863
|
puts %Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="#{escape(compile_inline(caption))}"#{metrics} />)
|
801
864
|
rescue
|
802
|
-
warn "image not bound: #{id}"
|
865
|
+
warn "image not bound: #{id}", location: location
|
803
866
|
if lines
|
804
867
|
puts %Q(<pre class="dummyimage">)
|
805
868
|
lines.each do |line|
|
@@ -852,7 +915,7 @@ EOS
|
|
852
915
|
alias_method :inline_ref, :inline_labelref
|
853
916
|
|
854
917
|
def inline_pageref(id)
|
855
|
-
|
918
|
+
app_error "pageref op is unsupported on this builder: #{id}"
|
856
919
|
end
|
857
920
|
|
858
921
|
def inline_chapref(id)
|
@@ -863,7 +926,7 @@ EOS
|
|
863
926
|
title
|
864
927
|
end
|
865
928
|
rescue KeyError
|
866
|
-
|
929
|
+
app_error "unknown chapter: #{id}"
|
867
930
|
end
|
868
931
|
|
869
932
|
def inline_chap(id)
|
@@ -873,7 +936,7 @@ EOS
|
|
873
936
|
@book.chapter_index.number(id)
|
874
937
|
end
|
875
938
|
rescue KeyError
|
876
|
-
|
939
|
+
app_error "unknown chapter: #{id}"
|
877
940
|
end
|
878
941
|
|
879
942
|
def inline_title(id)
|
@@ -884,7 +947,7 @@ EOS
|
|
884
947
|
title
|
885
948
|
end
|
886
949
|
rescue KeyError
|
887
|
-
|
950
|
+
app_error "unknown chapter: #{id}"
|
888
951
|
end
|
889
952
|
|
890
953
|
def inline_fn(id)
|
@@ -894,7 +957,13 @@ EOS
|
|
894
957
|
%Q(<a id="fnb-#{normalize_id(id)}" href="#fn-#{normalize_id(id)}" class="noteref">*#{@chapter.footnote(id).number}</a>)
|
895
958
|
end
|
896
959
|
rescue KeyError
|
897
|
-
|
960
|
+
app_error "unknown footnote: #{id}"
|
961
|
+
end
|
962
|
+
|
963
|
+
def inline_endnote(id)
|
964
|
+
%Q(<a id="endnoteb-#{normalize_id(id)}" href="#endnote-#{normalize_id(id)}" class="noteref" epub:type="noteref">#{I18n.t('html_endnote_refmark', @chapter.endnote(id).number)}</a>)
|
965
|
+
rescue KeyError
|
966
|
+
app_error "unknown endnote: #{id}"
|
898
967
|
end
|
899
968
|
|
900
969
|
def compile_ruby(base, ruby)
|
@@ -971,22 +1040,25 @@ EOS
|
|
971
1040
|
end
|
972
1041
|
|
973
1042
|
def inline_m(str)
|
974
|
-
if @book.config['mathml'
|
975
|
-
|
976
|
-
|
1043
|
+
if @book.config['math_format'] == 'mathml'
|
1044
|
+
begin
|
1045
|
+
require 'math_ml'
|
1046
|
+
require 'math_ml/symbol/character_reference'
|
1047
|
+
rescue LoadError
|
1048
|
+
app_error 'not found math_ml'
|
1049
|
+
end
|
977
1050
|
parser = MathML::LaTeX::Parser.new(symbol: MathML::Symbol::CharacterReference)
|
978
1051
|
%Q(<span class="equation">#{parser.parse(str, nil)}</span>)
|
979
|
-
elsif @book.config['
|
1052
|
+
elsif @book.config['math_format'] == 'mathjax'
|
1053
|
+
%Q(<span class="equation">\\( #{str} \\)</span>)
|
1054
|
+
elsif @book.config['math_format'] == 'imgmath'
|
980
1055
|
math_str = '$' + str + '$'
|
981
1056
|
key = Digest::SHA256.hexdigest(str)
|
982
|
-
math_dir = File.join(@book.config['imagedir'], '_review_math')
|
983
|
-
Dir.mkdir(math_dir) unless Dir.exist?(math_dir)
|
984
|
-
img_path = File.join(math_dir, "_gen_#{key}.#{@book.config['imgmath_options']['format']}")
|
985
1057
|
if @book.config.check_version('2', exception: false)
|
986
|
-
make_math_image(math_str,
|
1058
|
+
img_path = @img_math.make_math_image(math_str, key)
|
987
1059
|
%Q(<span class="equation"><img src="#{img_path}" /></span>)
|
988
1060
|
else
|
989
|
-
defer_math_image(math_str,
|
1061
|
+
img_path = @img_math.defer_math_image(math_str, key)
|
990
1062
|
%Q(<span class="equation"><img src="#{img_path}" class="math_gen_#{key}" alt="#{escape(str)}" /></span>)
|
991
1063
|
end
|
992
1064
|
else
|
@@ -1019,7 +1091,7 @@ EOS
|
|
1019
1091
|
def inline_bib(id)
|
1020
1092
|
%Q(<a href="#{@book.bib_file.gsub(/\.re\Z/, ".#{@book.config['htmlext']}")}#bib-#{normalize_id(id)}">[#{@chapter.bibpaper(id).number}]</a>)
|
1021
1093
|
rescue KeyError
|
1022
|
-
|
1094
|
+
app_error "unknown bib: #{id}"
|
1023
1095
|
end
|
1024
1096
|
|
1025
1097
|
def inline_hd_chap(chap, id)
|
@@ -1030,13 +1102,13 @@ EOS
|
|
1030
1102
|
str = I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption))
|
1031
1103
|
end
|
1032
1104
|
if @book.config['chapterlink']
|
1033
|
-
anchor = 'h' + n.
|
1105
|
+
anchor = 'h' + n.tr('.', '-')
|
1034
1106
|
%Q(<a href="#{chap.id}#{extname}##{anchor}">#{str}</a>)
|
1035
1107
|
else
|
1036
1108
|
str
|
1037
1109
|
end
|
1038
1110
|
rescue KeyError
|
1039
|
-
|
1111
|
+
app_error "unknown headline: #{id}"
|
1040
1112
|
end
|
1041
1113
|
|
1042
1114
|
def column_label(id, chapter = @chapter)
|
@@ -1052,7 +1124,7 @@ EOS
|
|
1052
1124
|
I18n.t('column', compile_inline(chapter.column(id).caption))
|
1053
1125
|
end
|
1054
1126
|
rescue KeyError
|
1055
|
-
|
1127
|
+
app_error "unknown column: #{id}"
|
1056
1128
|
end
|
1057
1129
|
|
1058
1130
|
def inline_list(id)
|
@@ -1179,7 +1251,7 @@ EOS
|
|
1179
1251
|
begin
|
1180
1252
|
%Q(<img src="#{@chapter.image(id).path.sub(%r{\A\./}, '')}" alt="[#{id}]" />)
|
1181
1253
|
rescue
|
1182
|
-
warn "image not bound: #{id}"
|
1254
|
+
warn "image not bound: #{id}", location: location
|
1183
1255
|
%Q(<pre>missing image: #{id}</pre>)
|
1184
1256
|
end
|
1185
1257
|
end
|
@@ -1240,35 +1312,5 @@ EOS
|
|
1240
1312
|
def olnum(num)
|
1241
1313
|
@ol_num = num.to_i
|
1242
1314
|
end
|
1243
|
-
|
1244
|
-
def make_math_image(str, path, fontsize = 12)
|
1245
|
-
# Re:VIEW 2 compatibility
|
1246
|
-
fontsize2 = (fontsize * 1.2).round.to_i
|
1247
|
-
texsrc = <<-EOB
|
1248
|
-
\\documentclass[12pt]{article}
|
1249
|
-
\\usepackage[utf8]{inputenc}
|
1250
|
-
\\usepackage{amsmath}
|
1251
|
-
\\usepackage{amsthm}
|
1252
|
-
\\usepackage{amssymb}
|
1253
|
-
\\usepackage{amsfonts}
|
1254
|
-
\\usepackage{anyfontsize}
|
1255
|
-
\\usepackage{bm}
|
1256
|
-
\\pagestyle{empty}
|
1257
|
-
|
1258
|
-
\\begin{document}
|
1259
|
-
\\fontsize{#{fontsize}}{#{fontsize2}}\\selectfont #{str}
|
1260
|
-
\\end{document}
|
1261
|
-
EOB
|
1262
|
-
Dir.mktmpdir do |tmpdir|
|
1263
|
-
tex_path = File.join(tmpdir, 'tmpmath.tex')
|
1264
|
-
dvi_path = File.join(tmpdir, 'tmpmath.dvi')
|
1265
|
-
File.write(tex_path, texsrc)
|
1266
|
-
cmd = "latex --interaction=nonstopmode --output-directory=#{tmpdir} #{tex_path} && dvipng -T tight -z9 -o #{path} #{dvi_path}"
|
1267
|
-
out, status = Open3.capture2e(cmd)
|
1268
|
-
unless status.success?
|
1269
|
-
error "latex compile error\n\nError log:\n" + out
|
1270
|
-
end
|
1271
|
-
end
|
1272
|
-
end
|
1273
1315
|
end
|
1274
1316
|
end # module ReVIEW
|
data/lib/review/htmlutils.rb
CHANGED
@@ -134,7 +134,7 @@ module ReVIEW
|
|
134
134
|
elsif id =~ /\A[0-9_.-][a-z0-9_.-]*\Z/i
|
135
135
|
"id_#{id}" # dummy prefix
|
136
136
|
else
|
137
|
-
"id_#{CGI.escape(id.gsub('_', '__')).
|
137
|
+
"id_#{CGI.escape(id.gsub('_', '__')).tr('%', '_').tr('+', '-')}" # escape all
|
138
138
|
end
|
139
139
|
end
|
140
140
|
end
|
data/lib/review/i18n.rb
CHANGED
data/lib/review/i18n.yml
CHANGED
@@ -32,6 +32,8 @@ ja:
|
|
32
32
|
html_footnote_refmark: "*%s"
|
33
33
|
html_footnote_textmark: "[*%s] "
|
34
34
|
html_footnote_backmark: "⏎"
|
35
|
+
html_endnote_refmark: "(%s)"
|
36
|
+
html_endnote_textmark: "(%s) "
|
35
37
|
aut: "著 者"
|
36
38
|
csl: "監 修"
|
37
39
|
dsr: "デザイン"
|
@@ -120,6 +122,8 @@ en:
|
|
120
122
|
html_footnote_refmark: "*%s"
|
121
123
|
html_footnote_textmark: "[*%s] "
|
122
124
|
html_footnote_backmark: "⏎"
|
125
|
+
html_endnote_refmark: "(%s)"
|
126
|
+
html_endnote_textmark: "(%s) "
|
123
127
|
aut: "Author"
|
124
128
|
csl: "Consultant"
|
125
129
|
dsr: "Design"
|
@@ -188,6 +192,8 @@ zh-TW:
|
|
188
192
|
html_footnote_refmark: "*%s"
|
189
193
|
html_footnote_textmark: "[*%s] "
|
190
194
|
html_footnote_backmark: "⏎"
|
195
|
+
html_endnote_refmark: "(%s)"
|
196
|
+
html_endnote_textmark: "(%s) "
|
191
197
|
aut: "著作人"
|
192
198
|
csl: "監 修"
|
193
199
|
dsr: "美術編輯"
|