diff --git a/doc/config.yml.sample b/doc/config.yml.sample index f5d7b31c0..d69531f5c 100644 --- a/doc/config.yml.sample +++ b/doc/config.yml.sample @@ -92,6 +92,9 @@ debug: null # ISBN。省略した場合はurnidが入る # isbn: null # +# @, @, @, @<hd>命令をハイパーリンクにする(nullでハイパーリンクにしない) +# chapterlink: true + # HTMLファイルの拡張子(省略した場合はhtml) # htmlext: html # diff --git a/lib/review/configure.rb b/lib/review/configure.rb index afe94136c..e2aaa6495 100644 --- a/lib/review/configure.rb +++ b/lib/review/configure.rb @@ -64,6 +64,7 @@ def self.values 'bib_file' => 'bib.re', 'words_file' => nil, 'colophon_order' => %w[aut csl trl dsr ill cov edt pbl contact prt], + 'chapterlink' => true, 'externallink' => true, 'join_lines_by_lang' => nil, # experimental. default should be nil 'table_row_separator' => 'tabs', diff --git a/lib/review/htmlbuilder.rb b/lib/review/htmlbuilder.rb index 42704b410..1bff4bf8a 100644 --- a/lib/review/htmlbuilder.rb +++ b/lib/review/htmlbuilder.rb @@ -1018,7 +1018,7 @@ def column_label(id, chapter = @chapter) def inline_column_chap(chapter, id) if @book.config['chapterlink'] - %Q(<a href="\##{column_label(id, chapter)}" class="columnref">#{I18n.t('column', compile_inline(chapter.column(id).caption))}</a>) + %Q(<a href="#{chapter.id}#{extname}##{column_label(id, chapter)}" class="columnref">#{I18n.t('column', compile_inline(chapter.column(id).caption))}</a>) else I18n.t('column', compile_inline(chapter.column(id).caption)) end diff --git a/templates/latex/review-jlreq/review-base.sty b/templates/latex/review-jlreq/review-base.sty index 952950bf0..d193ddada 100644 --- a/templates/latex/review-jlreq/review-base.sty +++ b/templates/latex/review-jlreq/review-base.sty @@ -1,4 +1,4 @@ -\ProvidesClass{review-base}[2020/07/23] +\ProvidesClass{review-base}[2020/08/14] % jlreq用基本設定 \def\recls@tmp{luatex}\ifx\recls@tmp\recls@driver \hypersetup{ @@ -127,9 +127,9 @@ \newcommand{\reviewtableref}[2]{\review@intn@table #1} \newcommand{\reviewlistref}[1]{\review@intn@list #1} \newcommand{\reviewequationref}[1]{\review@intn@equation #1} -\newcommand{\reviewbibref}[2]{#1} -\newcommand{\reviewcolumnref}[2]{#1} -\newcommand{\reviewsecref}[2]{#1} +\newcommand{\reviewbibref}[2]{\hyperref[#2]{#1}} +\newcommand{\reviewcolumnref}[2]{#1}% XXX:ハイパーリンクにはreviewcolumn側の調整が必要 +\newcommand{\reviewsecref}[2]{\hyperref[#2]{#1}} \renewcommand{\contentsname}{\review@toctitle} diff --git a/templates/latex/review-jsbook/review-base.sty b/templates/latex/review-jsbook/review-base.sty index d9b063b4c..de7724b3e 100644 --- a/templates/latex/review-jsbook/review-base.sty +++ b/templates/latex/review-jsbook/review-base.sty @@ -1,4 +1,4 @@ -\ProvidesClass{review-base}[2020/07/23] +\ProvidesClass{review-base}[2020/08/14] \RequirePackage{ifthen} \@ifundefined{Hy@Info}{% for jsbook.cls \RequirePackage[dvipdfmx,bookmarks=true,bookmarksnumbered=true]{hyperref} @@ -210,9 +210,9 @@ \newcommand{\reviewtableref}[2]{\review@intn@table #1} \newcommand{\reviewlistref}[1]{\review@intn@list #1} \newcommand{\reviewequationref}[1]{\review@intn@equation #1} -\newcommand{\reviewbibref}[2]{#1} -\newcommand{\reviewcolumnref}[2]{#1} -\newcommand{\reviewsecref}[2]{#1} +\newcommand{\reviewbibref}[2]{\hyperref[#2]{#1}} +\newcommand{\reviewcolumnref}[2]{#1}% XXX:ハイパーリンクにはreviewcolumn側の調整が必要 +\newcommand{\reviewsecref}[2]{\hyperref[#2]{#1}} \newenvironment{reviewpart}{% \setcounter{section}{0}% diff --git a/test/test_htmlbuilder.rb b/test/test_htmlbuilder.rb index 91813358d..f304d147e 100644 --- a/test/test_htmlbuilder.rb +++ b/test/test_htmlbuilder.rb @@ -250,6 +250,15 @@ def @chapter.headline_index idx end + @config['secnolevel'] = 2 + actual = compile_inline('test @<hd>{chap1|test} test2') + assert_equal 'test <a href="-.html#h1-1-1">「te_st」</a> test2', actual + + @config['secnolevel'] = 3 + actual = compile_inline('test @<hd>{chap1|test} test2') + assert_equal 'test <a href="-.html#h1-1-1">「1.1.1 te_st」</a> test2', actual + + @config['chapterlink'] = nil @config['secnolevel'] = 2 actual = compile_inline('test @<hd>{chap1|test} test2') assert_equal 'test 「te_st」 test2', actual @@ -278,6 +287,10 @@ def @chapter.headline_index idx end + actual = compile_inline('test @<hd>{test} test2') + assert_equal 'test <a href="-.html#hI-1">「I.1 te_st」</a> test2', actual + + @config['chapterlink'] = nil actual = compile_inline('test @<hd>{test} test2') assert_equal 'test 「I.1 te_st」 test2', actual end @@ -303,6 +316,10 @@ def @chapter.headline_index idx end + actual = compile_inline('test @<hd>{test} test2') + assert_equal 'test <a href="-.html#hA-1">「A.1 te_st」</a> test2', actual + + @config['chapterlink'] = nil actual = compile_inline('test @<hd>{test} test2') assert_equal 'test 「A.1 te_st」 test2', actual end @@ -354,6 +371,11 @@ def @chapter.image(_id) item end + actual = compile_block("@<img>{sampleimg}\n") + expected = %Q(<p><span class="imgref"><a href="./-.html#sampleimg">図1.1</a></span></p>\n) + assert_equal expected, actual + + @config['chapterlink'] = nil actual = compile_block("@<img>{sampleimg}\n") expected = %Q(<p><span class="imgref">図1.1</span></p>\n) assert_equal expected, actual @@ -366,6 +388,11 @@ def @chapter.image(_id) item end + actual = compile_block("@<imgref>{sampleimg}\n") + expected = %Q(<p><span class="imgref"><a href="./-.html#sampleimg">図1.1</a></span>「sample photo」</p>\n) + assert_equal expected, actual + + @config['chapterlink'] = nil actual = compile_block("@<imgref>{sampleimg}\n") expected = %Q(<p><span class="imgref">図1.1</span>「sample photo」</p>\n) assert_equal expected, actual @@ -378,6 +405,11 @@ def @chapter.image(_id) item end + actual = compile_block("@<imgref>{sampleimg}\n") + expected = %Q(<p><span class="imgref"><a href="./-.html#sampleimg">図1.1</a></span></p>\n) + assert_equal expected, actual + + @config['chapterlink'] = nil actual = compile_block("@<imgref>{sampleimg}\n") expected = %Q(<p><span class="imgref">図1.1</span></p>\n) assert_equal expected, actual @@ -417,6 +449,33 @@ def test_inline_imgref3 expected = <<-EOS <h1><a id="h1"></a><span class="secno">第1章 </span>test</h1> +<p>tbl1 is <span class="tableref"><a href="./-.html#tbl1">表1.1</a></span>.</p> +<p>img2 is <span class="imgref"><a href="./-.html#img2">図1.2</a></span>.</p> +<div id="img1" class="image"> +<img src="images/img1.png" alt="image 1" /> +<p class="caption"> +図1.1: image 1 +</p> +</div> +<div id="tbl1" class="imgtable image"> +<p class="caption">表1.1: table 1</p> +<img src="images/tbl1.png" alt="table 1" /> +</div> +<div id="img2" class="image"> +<img src="images/img2.png" alt="image 2" /> +<p class="caption"> +図1.2: image 2 +</p> +</div> +EOS + + assert_equal expected, actual + + @config['chapterlink'] = nil + actual = compile_block(content) + + expected = <<-EOS +<h1><a id="h1"></a><span class="secno">第1章 </span>test</h1> <p>tbl1 is <span class="tableref">表1.1</span>.</p> <p>img2 is <span class="imgref">図1.2</span>.</p> <div id="img1" class="image"> @@ -852,7 +911,11 @@ def test_inline_list def @chapter.list(_id) Book::Index::Item.new('samplelist', 1) end - actual = compile_block("@<list>{sampletest}\n") + actual = compile_block("@<list>{samplelist}\n") + assert_equal %Q(<p><span class="listref"><a href="./-.html#samplelist">リスト1.1</a></span></p>\n), actual + + @config['chapterlink'] = nil + actual = compile_block("@<list>{samplelist}\n") assert_equal %Q(<p><span class="listref">リスト1.1</span></p>\n), actual end @@ -1771,6 +1834,20 @@ def test_column_ref <p>inside column</p> </div> +<h3><a id="h1-0-1"></a>next level</h3> +<p>this is <a href="-.html#column-1" class="columnref">コラム「test」</a>.</p> +EOS + + assert_equal expected, column_helper(review) + + @config['chapterlink'] = nil + expected = <<-EOS +<div class="column"> + +<h3 id="foo"><a id="column-1"></a>test</h3> +<p>inside column</p> +</div> + <h3><a id="h1-0-1"></a>next level</h3> <p>this is コラム「test」.</p> EOS @@ -1786,6 +1863,11 @@ def @chapter.column_index idx end + actual = compile_inline('test @<column>{chap1|column} test2') + expected = 'test <a href="-.html#column-1" class="columnref">コラム「column_cap」</a> test2' + assert_equal expected, actual + + @config['chapterlink'] = nil actual = compile_inline('test @<column>{chap1|column} test2') expected = 'test コラム「column_cap」 test2' assert_equal expected, actual @@ -2145,6 +2227,11 @@ def test_inline_hd builder = ReVIEW::HTMLBuilder.new comp = ReVIEW::Compiler.new(builder) builder.bind(comp, chap2, nil) + + hd = builder.inline_hd('ch1|test1-1') + assert_equal '<a href="ch1.html#h1-1">「1.1 test1-1」</a>', hd + + builder.instance_eval { @book.config['chapterlink'] = nil } hd = builder.inline_hd('ch1|test1-1') assert_equal '「1.1 test1-1」', hd end @@ -2162,6 +2249,10 @@ def test_inline_hd_for_part comp = ReVIEW::Compiler.new(builder) builder.bind(comp, chap2, nil) hd = builder.inline_hd('part1|part1-1') + assert_equal '<a href="part1.html#h1-1">「1.1 part1-1」</a>', hd + + builder.instance_eval { @book.config['chapterlink'] = nil } + hd = builder.inline_hd('part1|part1-1') assert_equal '「1.1 part1-1」', hd end @@ -2171,7 +2262,12 @@ def test_inline_hd_with_block location = Location.new(nil, nil) @builder.bind(@compiler, chap1, location) hd = @builder.inline_hd('foo') + assert_equal '<a href="-.html#h1-1">「1.1 foo」</a>', hd + + @config['chapterlink'] = nil + hd = @builder.inline_hd('foo') assert_equal '「1.1 foo」', hd + hd = @builder.inline_hd('bar') assert_equal '「1.2 bar」', hd end @@ -2227,6 +2323,10 @@ def @chapter.table(_id) Book::Index::Item.new('sampletable', 1) end actual = compile_block("@<table>{sampletest}\n") + assert_equal %Q(<p><span class="tableref"><a href="./-.html#sampletest">表1.1</a></span></p>\n), actual + + @config['chapterlink'] = nil + actual = compile_block("@<table>{sampletest}\n") assert_equal %Q(<p><span class="tableref">表1.1</span></p>\n), actual end @@ -2540,6 +2640,20 @@ def test_texequation_with_caption //} EOS expected = <<-EOS +<p><span class="eqref"><a href="./-.html#emc2">式1.1</a></span></p> +<div id="emc2" class="caption-equation"> +<p class="caption">式1.1: The Equivalence of Mass <i>and</i> Energy</p> +<div class="equation"> +<pre>e=mc^2 +</pre> +</div> +</div> +EOS + actual = compile_block(src) + assert_equal expected, actual + + @config['chapterlink'] = nil + expected = <<-EOS <p><span class="eqref">式1.1</span></p> <div id="emc2" class="caption-equation"> <p class="caption">式1.1: The Equivalence of Mass <i>and</i> Energy</p> diff --git a/test/test_idgxmlbuilder.rb b/test/test_idgxmlbuilder.rb index cac822da6..b7e65c0c9 100644 --- a/test/test_idgxmlbuilder.rb +++ b/test/test_idgxmlbuilder.rb @@ -847,10 +847,16 @@ def test_column_ref this is @<column>{foo}. EOS expected = <<-EOS.chomp -<column id="column-1"><title aid:pstyle="column-title">test

inside column

next level

this is コラム「test」.

+test

inside column

next level

this is コラム「test」.

EOS assert_equal expected, column_helper(review) + + @config['chapterlink'] = nil + expected = <<-EOS.chomp +test

inside column

next level

this is コラム「test」.

+EOS + assert_equal expected, column_helper(review) end def test_column_in_aother_chapter_ref @@ -861,6 +867,11 @@ def @chapter.column_index idx end + actual = compile_inline('test @{chap1|column} test2') + expected = 'test コラム「column_cap」 test2' + assert_equal expected, actual + + @config['chapterlink'] = nil actual = compile_inline('test @{chap1|column} test2') expected = 'test コラム「column_cap」 test2' assert_equal expected, actual diff --git a/test/test_latexbuilder.rb b/test/test_latexbuilder.rb index 1cc837289..b3608ba7a 100644 --- a/test/test_latexbuilder.rb +++ b/test/test_latexbuilder.rb @@ -255,6 +255,10 @@ def @chapter.headline_index @config['secnolevel'] = 3 actual = compile_inline('test @{chap1|test} test2') + assert_equal 'test \reviewsecref{「1.1.1 te\\textunderscore{}st」}{sec:1-1-1} test2', actual + + @config['chapterlink'] = nil + actual = compile_inline('test @{chap1|test} test2') assert_equal 'test 「1.1.1 te\\textunderscore{}st」 test2', actual end diff --git a/test/test_latexbuilder_v2.rb b/test/test_latexbuilder_v2.rb index f0126fd8e..c9579815b 100644 --- a/test/test_latexbuilder_v2.rb +++ b/test/test_latexbuilder_v2.rb @@ -229,6 +229,10 @@ def @chapter.headline_index @config['secnolevel'] = 3 actual = compile_inline('test @{chap1|test} test2') + assert_equal 'test \reviewsecref{「1.1.1 te\\textunderscore{}st」}{sec:1-1-1} test2', actual + + @config['chapterlink'] = nil + actual = compile_inline('test @{chap1|test} test2') assert_equal 'test 「1.1.1 te\\textunderscore{}st」 test2', actual end