Skip to content

Commit

Permalink
Merge pull request #1234 from kmuto/back-footnote
Browse files Browse the repository at this point in the history
EPUBMaker: 「本文に戻るリンク」、脚注記号の変更
  • Loading branch information
kmuto authored Jan 14, 2019
2 parents 4bcf883 + db15d63 commit dea5020
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/epubmaker/producer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ def complement
'rename_for_legacy' => nil,
'verify_target_images' => nil,
'force_include_images' => [],
'cover_linear' => nil
'cover_linear' => nil,
'back_footnote' => nil
},
'externallink' => true,
'contentdir' => '.',
Expand Down
9 changes: 7 additions & 2 deletions lib/review/htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,12 @@ def comment(lines, comment = nil)

def footnote(id, str)
if @book.config['epubversion'].to_i == 3
puts %Q(<div class="footnote" epub:type="footnote" id="fn-#{normalize_id(id)}"><p class="footnote">[*#{@chapter.footnote(id).number}] #{compile_inline(str)}</p></div>)
back = ''
if @book.config['epubmaker'] && @book.config['epubmaker']['back_footnote']
back = %Q(<a href="#fnb-#{normalize_id(id)}">#{I18n.t('html_footnote_backmark')}</a>)
end
# XXX: back link must be located at first of p for Kindle.
puts %Q(<div class="footnote" epub:type="footnote" id="fn-#{normalize_id(id)}"><p class="footnote">#{back}#{I18n.t('html_footnote_textmark', @chapter.footnote(id).number)}#{compile_inline(str)}</p></div>)
else
puts %Q(<div class="footnote" id="fn-#{normalize_id(id)}"><p class="footnote">[<a href="#fnb-#{normalize_id(id)}">*#{@chapter.footnote(id).number}</a>] #{compile_inline(str)}</p></div>)
end
Expand Down Expand Up @@ -862,7 +867,7 @@ def inline_title(id)

def inline_fn(id)
if @book.config['epubversion'].to_i == 3
%Q(<a id="fnb-#{normalize_id(id)}" href="#fn-#{normalize_id(id)}" class="noteref" epub:type="noteref">*#{@chapter.footnote(id).number}</a>)
%Q(<a id="fnb-#{normalize_id(id)}" href="#fn-#{normalize_id(id)}" class="noteref" epub:type="noteref">#{I18n.t('html_footnote_refmark', @chapter.footnote(id).number)}</a>)
else
%Q(<a id="fnb-#{normalize_id(id)}" href="#fn-#{normalize_id(id)}" class="noteref">*#{@chapter.footnote(id).number}</a>)
end
Expand Down
9 changes: 9 additions & 0 deletions lib/review/i18n.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ ja:
ruby_postfix: ""
external_link: "%s(%s)"
label_marker: "●● "
html_footnote_refmark: "*%s"
html_footnote_textmark: "[*%s] "
html_footnote_backmark: ""
aut: "著 者"
csl: "監 修"
dsr: "デザイン"
Expand Down Expand Up @@ -114,6 +117,9 @@ en:
ruby_prefix: "("
ruby_postfix: ")"
label_marker: "●● "
html_footnote_refmark: "*%s"
html_footnote_textmark: "[*%s] "
html_footnote_backmark: ""
aut: "Author"
csl: "Consultant"
dsr: "Design"
Expand Down Expand Up @@ -179,6 +185,9 @@ zh-TW:
ruby_postfix: ""
external_link: "%s (%s)"
label_marker: "●● "
html_footnote_refmark: "*%s"
html_footnote_textmark: "[*%s] "
html_footnote_backmark: ""
aut: "著作人"
csl: "監 修"
dsr: "美術編輯"
Expand Down
37 changes: 35 additions & 2 deletions test/test_htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def setup
@config['secnolevel'] = 2
@config['stylesheet'] = nil
@config['htmlext'] = 'html'
@config['epubmaker'] = {}
@book = Book::Base.new('.')
@book.config = @config
@compiler = ReVIEW::Compiler.new(@builder)
Expand Down Expand Up @@ -1590,17 +1591,33 @@ def test_embed2b
assert_equal expected, actual
end

def test_inline_fn
def test_footnote
fn = Book::FootnoteIndex.parse(['//footnote[foo][bar\\a\\$buz]'])
@chapter.instance_eval { @footnote_index = fn }
actual = compile_block("//footnote[foo][bar\\a\\$buz]\n")
expected = <<-'EOS'
<div class="footnote" epub:type="footnote" id="fn-foo"><p class="footnote">[*1] bar\a\$buz</p></div>
EOS
assert_equal expected, actual

@book.config['epubmaker'] ||= {}
@book.config['epubmaker']['back_footnote'] = true
actual = compile_block("//footnote[foo][bar\\a\\$buz]\n")
expected = <<-'EOS'
<div class="footnote" epub:type="footnote" id="fn-foo"><p class="footnote"><a href="#fnb-foo">⏎</a>[*1] bar\a\$buz</p></div>
EOS
assert_equal expected, actual

I18n.set('html_footnote_textmark', '+%s:')
I18n.set('html_footnote_backmark', '←')
actual = compile_block("//footnote[foo][bar\\a\\$buz]\n")
expected = <<-'EOS'
<div class="footnote" epub:type="footnote" id="fn-foo"><p class="footnote"><a href="#fnb-foo">←</a>+1:bar\a\$buz</p></div>
EOS
assert_equal expected, actual
end

def test_inline_fn_with_tricky_id
def test_footnote_with_tricky_id
fn = Book::FootnoteIndex.parse(['//footnote[123 あ_;][bar\\a\\$buz]'])
@chapter.instance_eval { @footnote_index = fn }
actual = compile_block("//footnote[123 あ_;][bar\\a\\$buz]\n")
Expand All @@ -1610,6 +1627,22 @@ def test_inline_fn_with_tricky_id
assert_equal expected, actual
end

def test_inline_fn
book = ReVIEW::Book::Base.load
book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re])
io1 = StringIO.new("//footnote[foo][bar]\n")
chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
book.parts = [ReVIEW::Book::Part.new(self, nil, [chap1])]
builder = ReVIEW::HTMLBuilder.new
comp = ReVIEW::Compiler.new(builder)
builder.bind(comp, chap1, nil)
fn = builder.inline_fn('foo')
assert_equal '<a id="fnb-foo" href="#fn-foo" class="noteref" epub:type="noteref">*1</a>', fn
I18n.set('html_footnote_refmark', '+%s')
fn = builder.inline_fn('foo')
assert_equal '<a id="fnb-foo" href="#fn-foo" class="noteref" epub:type="noteref">+1</a>', fn
end

def test_inline_hd
book = ReVIEW::Book::Base.load
book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re])
Expand Down

0 comments on commit dea5020

Please sign in to comment.