Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

後注のサポート追加 #1728

Merged
merged 2 commits into from
Sep 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion doc/format.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Re:VIEW フォーマットの文法について解説します。Re:VIEW フォーマットはアスキー社(現カドカワ)の EWB を基本としながら、一部に RD や各種 Wiki の文法を取り入れて簡素化しています。

このドキュメントは、Re:VIEW 5.1 に基づいています。
このドキュメントは、Re:VIEW 5.3 に基づいています。

## 段落

Expand Down Expand Up @@ -524,6 +524,7 @@ Re:VIEW 5.0 以降では、囲み記事に箇条書きや図表・リストを
```
パッケージは本書のサポートサイトから入手できます@<fn>{site}。
各自ダウンロードしてインストールしておいてください。

//footnote[site][本書のサポートサイト: http://i.loveruby.net/ja/stdcompiler ]
```

Expand All @@ -538,6 +539,31 @@ TeX PDF において、コラム以外の `//note` などの囲み記事の中

ただし、通常の脚注(footnote)ではなく、footnotemark と footnotetext を使うため、本文と脚注が別ページに分かれる可能性があるなど、いろいろな制約があります。また、採番が別々になるため、footnote と footnotemark/footnotetext を両立させることはできません。

## 後注

後注(最後にまとめて出力される注釈)は、「`//endnote`」を使って記述します。

```
パッケージは本書のサポートサイトから入手できます@<endnote>{site}。
各自ダウンロードしてインストールしておいてください。

//endnote[site][本書のサポートサイト: http://i.loveruby.net/ja/stdcompiler ]
```

本文中のインライン命令「`@<endnote>{site}`」は後注番号に置換され、「本書のサポートサイト……」という文は後注として内部に保存されます。

保存されている後注を書き出すには、書き出したい箇所(通常は章の末尾)に「`//printendnotes`」を置きます。

```

==== 注釈

//printendnotes
```

後注の管理は章 (re ファイル) 単位であり、複数の章にまたがった後注を作ることはできません。

## 参考文献の定義

参考文献は同一ディレクトリ内の `bib.re` ファイルに定義します。
Expand Down
31 changes: 30 additions & 1 deletion doc/format.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The document is a brief guide for Re:VIEW markup syntax.

Re:VIEW is based on EWB of ASCII (now KADOKAWA), influenced RD and other Wiki system's syntax.

This document explains about the format of Re:VIEW 5.1.
This document explains about the format of Re:VIEW 5.3.

## Paragraph

Expand Down Expand Up @@ -551,6 +551,7 @@ Usage:
```
You can get the packages from support site for the book.@<fn>{site}
You should get and install it before reading the book.

//footnote[site][support site of the book: http://i.loveruby.net/ja/stdcompiler ]
```

Expand All @@ -572,6 +573,34 @@ Note that with this option, Re:VIEW use footnotemark and footnotetext instead of
There are some constraints to use this option.
You cannot use footnote and footnotemark/footnotetext at the same time.

## Endnotes

You can use `//endnote` to write endnotes.

Usage:

```
You can get the packages from support site for the book.@<endnote>{site}
You should get and install it before reading the book.

//endnote[site][support site of the book: http://i.loveruby.net/ja/stdcompiler ]
```

`@<endnote>{site}` in source are replaced by endnote marks, and the phrase "support site of .."
is stored for printing later.

To print stored endnotes, place "`//printendnotes`" where you want to write down them (usually at the end of the chapter).

```
...

==== Endnote

//printendnotes
```

It is not possible to create an endnote that spans multiple chapters.

## Bibliography

When you want to use a bibliography, you should write them in the file `bib.re`.
Expand Down
14 changes: 12 additions & 2 deletions lib/review/book/book_unit.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2009-2017 Minero Aoki, Kenshi Muto
# Copyright (c) 2009-2021 Minero Aoki, Kenshi Muto
# 2002-2008 Minero Aoki
#
# This program is free software.
Expand All @@ -18,7 +18,8 @@ class BookUnit
attr_reader :lines
attr_accessor :content

attr_reader :list_index, :table_index, :equation_index, :footnote_index,
attr_reader :list_index, :table_index, :equation_index,
:footnote_index, :endnote_index,
:numberless_image_index, :image_index, :icon_index, :indepimage_index,
:headline_index, :column_index

Expand Down Expand Up @@ -56,6 +57,7 @@ def generate_indexes(use_bib: false)
@table_index = @indexes.table_index
@equation_index = @indexes.equation_index
@footnote_index = @indexes.footnote_index
@endnote_index = @indexes.endnote_index
@headline_index = @indexes.headline_index
@column_index = @indexes.column_index
if use_bib
Expand Down Expand Up @@ -116,6 +118,14 @@ def footnote(id)
footnote_index[id]
end

def endnote(id)
endnote_index[id]
end

def endnotes
endnote_index
end

def image(id)
return image_index[id] if image_index.key?(id)
return icon_index[id] if icon_index.key?(id)
Expand Down
5 changes: 4 additions & 1 deletion lib/review/book/index.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2008-2019 Minero Aoki, Kenshi Muto
# Copyright (c) 2008-2021 Minero Aoki, Kenshi Muto
# 2002-2007 Minero Aoki
#
# This program is free software.
Expand Down Expand Up @@ -125,6 +125,9 @@ def self.item_type
class FootnoteIndex < Index
end

class EndnoteIndex < Index
end

class ImageIndex < Index
def self.item_type
'(image|graph|imgtable)'
Expand Down
49 changes: 37 additions & 12 deletions lib/review/builder.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2002-2020 Minero Aoki, Kenshi Muto
# Copyright (c) 2002-2021 Minero Aoki, Kenshi Muto
#
# This program is free software.
# You can distribute or modify this program under the terms of
Expand Down Expand Up @@ -42,6 +42,7 @@ def initialize(strict = false, *_args, img_math: nil)
@doc_status = {}
@dictionary = {}
@img_math = img_math
@shown_endnotes = true
end

def bind(compiler, chapter, location)
Expand Down Expand Up @@ -107,7 +108,14 @@ def check_nest
end
end

def check_printendnotes
if @shown_endnotes.nil?
app_error '//endnote is found but //printendnotes is not found.'
end
end

def result
check_printendnotes
solve_nest(@output.string)
end

Expand Down Expand Up @@ -273,17 +281,28 @@ def emtable(lines, caption = nil)
table(lines, nil, caption)
end

# def footnote(id, str)
# @footnotes.push [id, str]
# end
#
# def flush_footnote
# footnote_begin
# @footnotes.each do |id, str|
# footnote_item(id, str)
# end
# footnote_end
# end
def printendnotes
@shown_endnotes = true
endnote_begin
@chapter.endnotes.each do |en|
endnote_item(en.id)
end
endnote_end
end

def endnote(_id, _str)
@shown_endnotes = nil
end

def endnote_begin
end

def endnote_end
end

def endnote_item(id)
puts "(#{@chapter.endnote(id).number}) #{compile_inline(@chapter.endnote(id).content)}"
end

def blankline
puts ''
Expand Down Expand Up @@ -371,6 +390,12 @@ def inline_fn(id)
app_error "unknown footnote: #{id}"
end

def inline_endnote(id)
"(#{@chapter.endnote(id).number})"
rescue KeyError
app_error "unknown endnote: #{id}"
end

def inline_bou(str)
text(str)
end
Expand Down
5 changes: 4 additions & 1 deletion lib/review/compiler.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2009-2020 Minero Aoki, Kenshi Muto
# Copyright (c) 2009-2021 Minero Aoki, Kenshi Muto
# Copyright (c) 2002-2007 Minero Aoki
#
# This program is free software.
Expand Down Expand Up @@ -196,6 +196,8 @@ def inline_defined?(name)
defminicolumn :notice, 0..1

defsingle :footnote, 2
defsingle :endnote, 2
defsingle :printendnotes, 0
defsingle :noindent, 0
defsingle :blankline, 0
defsingle :pagebreak, 0
Expand All @@ -220,6 +222,7 @@ def inline_defined?(name)
definline :table
definline :eq
definline :fn
definline :endnote
definline :kw
definline :ruby
definline :bou
Expand Down
24 changes: 24 additions & 0 deletions lib/review/htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def close_sections
end

def result
check_printendnotes

# flush all `</section>`
if use_section?
print close_sections
Expand Down Expand Up @@ -825,6 +827,22 @@ def footnote(id, str)
end
end

def endnote_begin
puts %Q(<div class="endnotes">)
end

def endnote_end
puts %Q(</div>)
end

def endnote_item(id)
back = ''
if @book.config['epubmaker'] && @book.config['epubmaker']['back_footnote']
back = %Q(<a href="#endnoteb-#{normalize_id(id)}">#{I18n.t('html_footnote_backmark')}</a>)
end
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>)
end

def indepimage(lines, id, caption = '', metric = nil)
metrics = parse_metric('html', metric)
caption = '' unless caption.present?
Expand Down Expand Up @@ -942,6 +960,12 @@ def inline_fn(id)
app_error "unknown footnote: #{id}"
end

def inline_endnote(id)
%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>)
rescue KeyError
app_error "unknown endnote: #{id}"
end

def compile_ruby(base, ruby)
if @book.htmlversion == 5
%Q(<ruby>#{escape(base)}<rp>#{I18n.t('ruby_prefix')}</rp><rt>#{escape(ruby)}</rt><rp>#{I18n.t('ruby_postfix')}</rp></ruby>)
Expand Down
6 changes: 6 additions & 0 deletions lib/review/i18n.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ ja:
html_footnote_refmark: "*%s"
html_footnote_textmark: "[*%s] "
html_footnote_backmark: "⏎"
html_endnote_refmark: "(%s)"
html_endnote_textmark: "(%s) "
aut: "著 者"
csl: "監 修"
dsr: "デザイン"
Expand Down Expand Up @@ -120,6 +122,8 @@ en:
html_footnote_refmark: "*%s"
html_footnote_textmark: "[*%s] "
html_footnote_backmark: "⏎"
html_endnote_refmark: "(%s)"
html_endnote_textmark: "(%s) "
aut: "Author"
csl: "Consultant"
dsr: "Design"
Expand Down Expand Up @@ -188,6 +192,8 @@ zh-TW:
html_footnote_refmark: "*%s"
html_footnote_textmark: "[*%s] "
html_footnote_backmark: "⏎"
html_endnote_refmark: "(%s)"
html_endnote_textmark: "(%s) "
aut: "著作人"
csl: "監 修"
dsr: "美術編輯"
Expand Down
22 changes: 21 additions & 1 deletion lib/review/idgxmlbuilder.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2008-2020 Minero Aoki, Kenshi Muto
# Copyright (c) 2008-2021 Minero Aoki, Kenshi Muto
# 2002-2007 Minero Aoki
#
# This program is free software.
Expand Down Expand Up @@ -78,6 +78,8 @@ def puts(arg)
end

def result
check_printendnotes

s = ''
if @secttags
s += '</sect4>' if @subsubsubsection > 0
Expand Down Expand Up @@ -660,6 +662,24 @@ def inline_fn(id)
app_error "unknown footnote: #{id}"
end

def inline_endnote(id)
%Q(<span type='endnoteref' idref='endnoteb-#{normalize_id(id)}'>(#{@chapter.endnote(id).number})</span>)
rescue KeyError
app_error "unknown endnote: #{id}"
end

def endnote_begin
puts '<endnotes>'
end

def endnote_end
puts '</endnotes>'
end

def endnote_item(id)
puts %Q(<endnote id='endnoteb-#{normalize_id(id)}'><span type='endnotenumber'>(#{@chapter.endnote(id).number})</span>\t#{compile_inline(@chapter.endnote(id).content)}</endnote>)
end

def compile_ruby(base, ruby)
%Q(<GroupRuby><aid:ruby xmlns:aid="http://ns.adobe.com/AdobeInDesign/3.0/"><aid:rb>#{escape(base.strip)}</aid:rb><aid:rt>#{escape(ruby.strip)}</aid:rt></aid:ruby></GroupRuby>)
end
Expand Down
Loading