Skip to content

Commit

Permalink
enable chapterlink by default (Cloess: #1529). use hyperref in review…
Browse files Browse the repository at this point in the history
…secref (Closes: #1530)
  • Loading branch information
kmuto committed Aug 14, 2020
1 parent a80fb4c commit 39db3bb
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 11 deletions.
3 changes: 3 additions & 0 deletions doc/config.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ debug: null
# ISBN。省略した場合はurnidが入る
# isbn: null
#
# @<chap>, @<chapref>, @<title>, @<hd>命令をハイパーリンクにする(nullでハイパーリンクにしない)
# chapterlink: true

# HTMLファイルの拡張子(省略した場合はhtml)
# htmlext: html
#
Expand Down
1 change: 1 addition & 0 deletions lib/review/configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion lib/review/htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions templates/latex/review-jlreq/review-base.sty
Original file line number Diff line number Diff line change
@@ -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{
Expand Down Expand Up @@ -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}

Expand Down
8 changes: 4 additions & 4 deletions templates/latex/review-jsbook/review-base.sty
Original file line number Diff line number Diff line change
@@ -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}
Expand Down Expand Up @@ -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}%
Expand Down
116 changes: 115 additions & 1 deletion test/test_htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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>
Expand Down
13 changes: 12 additions & 1 deletion test/test_idgxmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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</title><?dtp level="9" section="test"?><p>inside column</p></column><title aid:pstyle="h3">next level</title><?dtp level="3" section="next level"?><p>this is コラム「test」.</p>
<column id="column-1"><title aid:pstyle="column-title">test</title><?dtp level="9" section="test"?><p>inside column</p></column><title aid:pstyle="h3">next level</title><?dtp level="3" section="next level"?><p>this is <link href="column-1">コラム「test」</link>.</p>
EOS

assert_equal expected, column_helper(review)

@config['chapterlink'] = nil
expected = <<-EOS.chomp
<column id="column-1"><title aid:pstyle="column-title">test</title><?dtp level="9" section="test"?><p>inside column</p></column><title aid:pstyle="h3">next level</title><?dtp level="3" section="next level"?><p>this is コラム「test」.</p>
EOS
assert_equal expected, column_helper(review)
end

def test_column_in_aother_chapter_ref
Expand All @@ -861,6 +867,11 @@ def @chapter.column_index
idx
end

actual = compile_inline('test @<column>{chap1|column} test2')
expected = 'test <link href="column-1">コラム「column_cap」</link> 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
Expand Down
4 changes: 4 additions & 0 deletions test/test_latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ def @chapter.headline_index

@config['secnolevel'] = 3
actual = compile_inline('test @<hd>{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 @<hd>{chap1|test} test2')
assert_equal 'test 「1.1.1 te\\textunderscore{}st」 test2', actual
end

Expand Down
4 changes: 4 additions & 0 deletions test/test_latexbuilder_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ def @chapter.headline_index

@config['secnolevel'] = 3
actual = compile_inline('test @<hd>{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 @<hd>{chap1|test} test2')
assert_equal 'test 「1.1.1 te\\textunderscore{}st」 test2', actual
end

Expand Down

0 comments on commit 39db3bb

Please sign in to comment.