From c4ef4048667fc7c216706f548dca1953f838de1d Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Sat, 4 Sep 2021 16:02:52 +0900 Subject: [PATCH 1/2] implements endnote. (Closes: #1724) --- doc/format.ja.md | 28 ++++++++++- doc/format.md | 31 +++++++++++- lib/review/book/book_unit.rb | 14 +++++- lib/review/book/index.rb | 5 +- lib/review/builder.rb | 49 ++++++++++++++----- lib/review/compiler.rb | 5 +- lib/review/htmlbuilder.rb | 24 +++++++++ lib/review/i18n.yml | 6 +++ lib/review/idgxmlbuilder.rb | 22 ++++++++- lib/review/index_builder.rb | 19 ++++++- lib/review/latexbuilder.rb | 14 ++++++ lib/review/markdownbuilder.rb | 10 +++- lib/review/plaintextbuilder.rb | 1 + lib/review/rstbuilder.rb | 9 ++++ lib/review/topbuilder.rb | 20 +++++++- samples/syntax-book/ch02.re | 9 ++++ templates/latex/review-jlreq/review-jlreq.cls | 14 +++++- templates/latex/review-jsbook/review-base.sty | 5 +- test/test_book_chapter.rb | 20 ++++++++ test/test_builder.rb | 2 + test/test_index.rb | 13 +++++ 21 files changed, 295 insertions(+), 25 deletions(-) diff --git a/doc/format.ja.md b/doc/format.ja.md index 510d2590a..48d13a15b 100644 --- a/doc/format.ja.md +++ b/doc/format.ja.md @@ -2,7 +2,7 @@ Re:VIEW フォーマットの文法について解説します。Re:VIEW フォーマットはアスキー社(現カドカワ)の EWB を基本としながら、一部に RD や各種 Wiki の文法を取り入れて簡素化しています。 -このドキュメントは、Re:VIEW 5.1 に基づいています。 +このドキュメントは、Re:VIEW 5.3 に基づいています。 ## 段落 @@ -524,6 +524,7 @@ Re:VIEW 5.0 以降では、囲み記事に箇条書きや図表・リストを ``` パッケージは本書のサポートサイトから入手できます@{site}。 各自ダウンロードしてインストールしておいてください。 + //footnote[site][本書のサポートサイト: http://i.loveruby.net/ja/stdcompiler ] ``` @@ -538,6 +539,31 @@ TeX PDF において、コラム以外の `//note` などの囲み記事の中 ただし、通常の脚注(footnote)ではなく、footnotemark と footnotetext を使うため、本文と脚注が別ページに分かれる可能性があるなど、いろいろな制約があります。また、採番が別々になるため、footnote と footnotemark/footnotetext を両立させることはできません。 +## 後注 + +後注(最後にまとめて出力される注釈)は、「`//endnote`」を使って記述します。 + +``` +パッケージは本書のサポートサイトから入手できます@{site}。 +各自ダウンロードしてインストールしておいてください。 + +//endnote[site][本書のサポートサイト: http://i.loveruby.net/ja/stdcompiler ] +``` + +本文中のインライン命令「`@{site}`」は後注番号に置換され、「本書のサポートサイト……」という文は後注として内部に保存されます。 + +保存されている後注を書き出すには、書き出したい箇所(通常は章の末尾)に「`//printendnotes`」を置きます。 + +``` + … + +==== 注釈 + +//printendnotes +``` + +後注の管理は章 (re ファイル) 単位であり、複数の章にまたがった後注を作ることはできません。 + ## 参考文献の定義 参考文献は同一ディレクトリ内の `bib.re` ファイルに定義します。 diff --git a/doc/format.md b/doc/format.md index e9948069f..6abeca686 100644 --- a/doc/format.md +++ b/doc/format.md @@ -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 @@ -551,6 +551,7 @@ Usage: ``` You can get the packages from support site for the book.@{site} You should get and install it before reading the book. + //footnote[site][support site of the book: http://i.loveruby.net/ja/stdcompiler ] ``` @@ -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.@{site} +You should get and install it before reading the book. + +//endnote[site][support site of the book: http://i.loveruby.net/ja/stdcompiler ] +``` + +`@{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`. diff --git a/lib/review/book/book_unit.rb b/lib/review/book/book_unit.rb index 1304607b3..deed1d1bf 100644 --- a/lib/review/book/book_unit.rb +++ b/lib/review/book/book_unit.rb @@ -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. @@ -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 @@ -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 @@ -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) diff --git a/lib/review/book/index.rb b/lib/review/book/index.rb index fd62384d2..b8c1503b5 100644 --- a/lib/review/book/index.rb +++ b/lib/review/book/index.rb @@ -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. @@ -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)' diff --git a/lib/review/builder.rb b/lib/review/builder.rb index 36ad5f2dd..92e0ad260 100644 --- a/lib/review/builder.rb +++ b/lib/review/builder.rb @@ -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 @@ -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) @@ -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 @@ -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 '' @@ -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 diff --git a/lib/review/compiler.rb b/lib/review/compiler.rb index 753669176..4a86e203b 100644 --- a/lib/review/compiler.rb +++ b/lib/review/compiler.rb @@ -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. @@ -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 @@ -220,6 +222,7 @@ def inline_defined?(name) definline :table definline :eq definline :fn + definline :endnote definline :kw definline :ruby definline :bou diff --git a/lib/review/htmlbuilder.rb b/lib/review/htmlbuilder.rb index 556a8ef39..876caea6d 100644 --- a/lib/review/htmlbuilder.rb +++ b/lib/review/htmlbuilder.rb @@ -111,6 +111,8 @@ def close_sections end def result + check_printendnotes + # flush all `` if use_section? print close_sections @@ -825,6 +827,22 @@ def footnote(id, str) end end + def endnote_begin + puts %Q(
) + end + + def endnote_end + puts %Q(
) + end + + def endnote_item(id) + back = '' + if @book.config['epubmaker'] && @book.config['epubmaker']['back_footnote'] + back = %Q(#{I18n.t('html_footnote_backmark')}) + end + puts %Q(

#{back}#{I18n.t('html_endnote_textmark', @chapter.endnote(id).number)}#{compile_inline(@chapter.endnote(id).content)}

) + end + def indepimage(lines, id, caption = '', metric = nil) metrics = parse_metric('html', metric) caption = '' unless caption.present? @@ -942,6 +960,12 @@ def inline_fn(id) app_error "unknown footnote: #{id}" end + def inline_endnote(id) + %Q(#{I18n.t('html_endnote_refmark', @chapter.endnote(id).number)}) + rescue KeyError + app_error "unknown endnote: #{id}" + end + def compile_ruby(base, ruby) if @book.htmlversion == 5 %Q(#{escape(base)}#{I18n.t('ruby_prefix')}#{escape(ruby)}#{I18n.t('ruby_postfix')}) diff --git a/lib/review/i18n.yml b/lib/review/i18n.yml index e8b33a477..4775dffcd 100644 --- a/lib/review/i18n.yml +++ b/lib/review/i18n.yml @@ -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: "デザイン" @@ -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" @@ -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: "美術編輯" diff --git a/lib/review/idgxmlbuilder.rb b/lib/review/idgxmlbuilder.rb index 27115dc76..0ee7c3723 100644 --- a/lib/review/idgxmlbuilder.rb +++ b/lib/review/idgxmlbuilder.rb @@ -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. @@ -78,6 +78,8 @@ def puts(arg) end def result + check_printendnotes + s = '' if @secttags s += '' if @subsubsubsection > 0 @@ -660,6 +662,24 @@ def inline_fn(id) app_error "unknown footnote: #{id}" end + def inline_endnote(id) + %Q((#{@chapter.endnote(id).number})) + rescue KeyError + app_error "unknown endnote: #{id}" + end + + def endnote_begin + puts '' + end + + def endnote_end + puts '' + end + + def endnote_item(id) + puts %Q((#{@chapter.endnote(id).number})\t#{compile_inline(@chapter.endnote(id).content)}) + end + def compile_ruby(base, ruby) %Q(#{escape(base.strip)}#{escape(ruby.strip)}) end diff --git a/lib/review/index_builder.rb b/lib/review/index_builder.rb index 0ae2c1ab5..b3e9dfce7 100644 --- a/lib/review/index_builder.rb +++ b/lib/review/index_builder.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2008-2020 Minero Aoki, Kenshi Muto, Masayoshi Takahashi, +# Copyright (c) 2008-2021 Minero Aoki, Kenshi Muto, Masayoshi Takahashi, # KADO Masanori # # This program is free software. @@ -13,7 +13,8 @@ module ReVIEW class IndexBuilder < Builder - 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, :bibpaper_index @@ -58,6 +59,7 @@ def builder_init_file @table_index = ReVIEW::Book::TableIndex.new @equation_index = ReVIEW::Book::EquationIndex.new @footnote_index = ReVIEW::Book::FootnoteIndex.new + @endnote_index = ReVIEW::Book::EndnoteIndex.new @headline_index = ReVIEW::Book::HeadlineIndex.new(@chapter) @column_index = ReVIEW::Book::ColumnIndex.new @chapter_index = ReVIEW::Book::ChapterIndex.new @@ -312,6 +314,12 @@ def footnote(id, str) @footnote_index.add_item(item) end + def endnote(id, str) + check_id(id) + item = ReVIEW::Book::Index::Item.new(id, @endnote_index.size + 1, str) + @endnote_index.add_item(item) + end + def indepimage(_lines, id, _caption = '', _metric = nil) check_id(id) item = ReVIEW::Book::Index::Item.new(id, @indepimage_index.size + 1) @@ -352,6 +360,9 @@ def bpo(_lines) def noindent end + def printendnotes + end + def compile_inline(s) @compiler.text(s) end @@ -392,6 +403,10 @@ def inline_fn(_id) '' end + def inline_endnote(_id) + '' + end + def inline_i(_str) '' end diff --git a/lib/review/latexbuilder.rb b/lib/review/latexbuilder.rb index d7bbf0fe1..46d6ba739 100644 --- a/lib/review/latexbuilder.rb +++ b/lib/review/latexbuilder.rb @@ -98,6 +98,8 @@ def puts(*s) private :puts def result + check_printendnotes + if @chapter.is_a?(ReVIEW::Book::Part) && !@book.config.check_version('2', exception: false) puts '\end{reviewpart}' end @@ -1151,6 +1153,18 @@ def inline_fn(id) app_error "unknown footnote: #{id}" end + def inline_endnote(id) + macro('endnote', compile_inline(@chapter.endnote(id).content.strip)) + rescue KeyError + app_error "unknown footnote: #{id}" + end + + def printendnotes + blank + puts '\theendnotes' + blank + end + BOUTEN = '・'.freeze def inline_bou(str) diff --git a/lib/review/markdownbuilder.rb b/lib/review/markdownbuilder.rb index 26afd014d..eb64105e0 100644 --- a/lib/review/markdownbuilder.rb +++ b/lib/review/markdownbuilder.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2020 KADO Masanori, Masayoshi Takahashi, Kenshi Muto +# Copyright (c) 2013-2021 KADO Masanori, Masayoshi Takahashi, Kenshi Muto # # This program is free software. # You can distribute or modify this program under the terms of @@ -361,6 +361,14 @@ def inline_fn(id) "[^#{id}]" end + def inline_endnote(id) + "#{I18n.t('html_endnote_refmark', @chapter.endnote(id).number)}" + end + + def endnote_item(id) + puts "#{I18n.t('html_endnote_textmark', @chapter.endnote(id).number)}#{compile_inline(@chapter.endnote(id).content)}" + end + def inline_br(_str) "\n" end diff --git a/lib/review/plaintextbuilder.rb b/lib/review/plaintextbuilder.rb index d3e1d1f33..5e9e28d07 100644 --- a/lib/review/plaintextbuilder.rb +++ b/lib/review/plaintextbuilder.rb @@ -74,6 +74,7 @@ def blank private :blank def result + check_printendnotes solve_nest(@output.string) end diff --git a/lib/review/rstbuilder.rb b/lib/review/rstbuilder.rb index e29c6c8e3..76ba7fe56 100644 --- a/lib/review/rstbuilder.rb +++ b/lib/review/rstbuilder.rb @@ -86,6 +86,7 @@ def blank private :blank def result + check_printendnotes solve_nest(@output.string) end @@ -367,6 +368,14 @@ def inline_fn(id) " [##{id.sub(' ', '_')}]_ " end + def inline_endnote(id) + " [(#{@chapter.endnote(id).number})]_ " + end + + def endnote_item(id) + puts ".. [(#{@chapter.endnote(id).number})] #{compile_inline(@chapter.endnote(id).content)}" + end + def compile_ruby(base, ruby) " :ruby:`#{base}`<#{ruby}>`_ " end diff --git a/lib/review/topbuilder.rb b/lib/review/topbuilder.rb index 00ea5efd0..84b721043 100644 --- a/lib/review/topbuilder.rb +++ b/lib/review/topbuilder.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2008-2020 Minero Aoki, Kenshi Muto +# Copyright (c) 2008-2021 Minero Aoki, Kenshi Muto # 2002-2006 Minero Aoki # # This program is free software. @@ -290,6 +290,24 @@ 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 endnote_begin + puts '◆→開始:後注←◆' + end + + def endnote_end + puts '◆→終了:後注←◆' + end + + def endnote_item(id) + puts "【後注#{@chapter.endnote(id).number}】#{compile_inline(@chapter.endnote(id).content)}" + end + def compile_ruby(base, ruby) "#{base}◆→DTP連絡:「#{base}」に「#{ruby}」とルビ←◆" end diff --git a/samples/syntax-book/ch02.re b/samples/syntax-book/ch02.re index 05c2c3518..dbc5ea9fb 100644 --- a/samples/syntax-book/ch02.re +++ b/samples/syntax-book/ch02.re @@ -254,6 +254,12 @@ Tips。@{太字bold}@{italicイタ}@{等幅code} #@# doorquote、bpo、talk、graph、address、box、linebreak、pagebreak、hr、comment、abbr、acronym、dfn、kbd、q、samp、var、big、small、del、ins、recipe、dtp、raw、embed、include +== 後注 +後注は脚注と同様の書式で、@{//endnote}で内容@{end1}、@{@}で参照します@{end2}。後注は@{//printendnotes}を書いた箇所にまとめて書き出されます。ここではファイル末尾に置いています。 + +//endnote[end1][後注その1です。] +//endnote[end2][後注その2です。] + == LaTeX式 LaTeX式はTeX紙面以外は保証されません。EPUBではMathML(@{math_format: mathml})を使えますが、表現や互換性が不足しており、LaTeXをバックエンドとして画像化する@{math_format: imgmath}のほうがよさそうです。 @@ -361,3 +367,6 @@ labelで定義したラベルへの参照の例です。EPUBだと@{#inlin @{|}@{{}@$}$ idx, hidxいずれも=見出しの中には入れないようにし、後続の段落先頭にhidxで入れるように注意します(入れてしまうと目次などがおかしくなります)。 + +===== 後注 +//printendnotes diff --git a/templates/latex/review-jlreq/review-jlreq.cls b/templates/latex/review-jlreq/review-jlreq.cls index 6a0f0a980..2625a5b1a 100644 --- a/templates/latex/review-jlreq/review-jlreq.cls +++ b/templates/latex/review-jlreq/review-jlreq.cls @@ -21,7 +21,7 @@ \IfFileExists{plautopatch.sty}{\RequirePackage{plautopatch}}{} \NeedsTeXFormat{LaTeX2e} -\ProvidesClass{review-jlreq}[2021/07/24 Re:VIEW 5.3 upLaTeX/LuaLaTeX class modified for jlreq.cls] +\ProvidesClass{review-jlreq}[2021/09/04 Re:VIEW 5.3 upLaTeX/LuaLaTeX class modified for jlreq.cls] %% hook at end of reviewmacro \let\@endofreviewmacrohook\@empty @@ -342,5 +342,17 @@ \def\reviewleftcurlybrace{\{} \def\reviewrightcurlybrace{\}} +%% 後注を見出しではなくchapter前にし、endnoteカウンタを新規に用意する +\jlreqsetup{endnote_position=_chapter} +\newcounter{reclsendnote} +\setcounter{reclsendnote}{0} +\if@tate + \renewcommand*{\thereclsendnote}{\jlreq@open@bracket@before@space\inhibitglue(\jlreq@rensuji{\@arabic\c@reclsendnote})\inhibitglue} +\else + \renewcommand*{\thereclsendnote}{(\arabic{reclsendnote}\hbox{})\inhibitglue} +\fi +\def\jlreq@endnotecounter{reclsendnote} +\ifthenelse{\equal{\jlreq@article@type}{article}}{}{\@addtoreset{reclsendnote}{chapter}} + \listfiles \endinput diff --git a/templates/latex/review-jsbook/review-base.sty b/templates/latex/review-jsbook/review-base.sty index 5c5c3796c..fa15bcd54 100644 --- a/templates/latex/review-jsbook/review-base.sty +++ b/templates/latex/review-jsbook/review-base.sty @@ -1,4 +1,4 @@ -\ProvidesClass{review-base}[2021/06/04] +\ProvidesClass{review-base}[2021/09/04] \RequirePackage{ifthen} \@ifundefined{Hy@Info}{% for jsbook.cls \RequirePackage[dvipdfmx,bookmarks=true,bookmarksnumbered=true]{hyperref} @@ -40,6 +40,9 @@ \RequirePackage{amsthm} \RequirePackage{bm} \RequirePackage{tabularx} +\RequirePackage{endnotesj} + +\def\enoteheading{}% endnotesj.styの後注前見出しおよび空行の出力を抑制 %% if you use @{} (underline), use jumoline.sty \IfFileExists{jumoline.sty}{ diff --git a/test/test_book_chapter.rb b/test/test_book_chapter.rb index fa9b73ed9..cb25db4c5 100644 --- a/test/test_book_chapter.rb +++ b/test/test_book_chapter.rb @@ -189,6 +189,26 @@ def test_footnote_index end end + def test_endnote_index + content = < Date: Sat, 4 Sep 2021 17:15:47 +0900 Subject: [PATCH 2/2] add test units --- lib/review/latexbuilder.rb | 1 + samples/syntax-book/ch02.re | 4 +-- test/assets/syntax_book_index_detail.txt | 18 ++++++----- test/test_htmlbuilder.rb | 39 ++++++++++++++++++++++++ test/test_latexbuilder.rb | 14 +++++++++ test/test_markdownbuilder.rb | 13 ++++++++ test/test_plaintextbuilder.rb | 16 ++++++++++ test/test_rstbuilder.rb | 13 ++++++++ test/test_topbuilder.rb | 18 +++++++++++ 9 files changed, 126 insertions(+), 10 deletions(-) diff --git a/lib/review/latexbuilder.rb b/lib/review/latexbuilder.rb index 46d6ba739..326052aed 100644 --- a/lib/review/latexbuilder.rb +++ b/lib/review/latexbuilder.rb @@ -1160,6 +1160,7 @@ def inline_endnote(id) end def printendnotes + @shown_endnotes = true blank puts '\theendnotes' blank diff --git a/samples/syntax-book/ch02.re b/samples/syntax-book/ch02.re index dbc5ea9fb..e1f995b0a 100644 --- a/samples/syntax-book/ch02.re +++ b/samples/syntax-book/ch02.re @@ -255,7 +255,7 @@ Tips。@{太字bold}@{italicイタ}@{等幅code} #@# doorquote、bpo、talk、graph、address、box、linebreak、pagebreak、hr、comment、abbr、acronym、dfn、kbd、q、samp、var、big、small、del、ins、recipe、dtp、raw、embed、include == 後注 -後注は脚注と同様の書式で、@{//endnote}で内容@{end1}、@{@}で参照します@{end2}。後注は@{//printendnotes}を書いた箇所にまとめて書き出されます。ここではファイル末尾に置いています。 +後注は脚注と同様の書式で、@{//endnote}で内容@{end1}、@{@}@{}で参照します@{end2}。後注は@{//printendnotes}を書いた箇所にまとめて書き出されます。ここではファイル末尾に置いています。 //endnote[end1][後注その1です。] //endnote[end2][後注その2です。] @@ -368,5 +368,5 @@ labelで定義したラベルへの参照の例です。EPUBだと@{#inlin idx, hidxいずれも=見出しの中には入れないようにし、後続の段落先頭にhidxで入れるように注意します(入れてしまうと目次などがおかしくなります)。 -===== 後注 +==== 後注 //printendnotes diff --git a/test/assets/syntax_book_index_detail.txt b/test/assets/syntax_book_index_detail.txt index 4fef570d2..90d8b08e4 100644 --- a/test/assets/syntax_book_index_detail.txt +++ b/test/assets/syntax_book_index_detail.txt @@ -26,7 +26,7 @@ ----------------------------- 169C 2L 0.2P 第II部 部見出し■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□ ============================= - 5652C 175L 10P ch02 + 5796C 180L 11P ch02 ----------------------------- 52C 1L 0.0P 第2章 長い章見出し■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□ 10C 1L 0.0P 2.1 ブロック命令 @@ -34,13 +34,15 @@ 338C 8L 0.5P 2.1.2 図 709C 22L 1.3P 2.1.3 表 1154C 56L 2.8P 2.1.4 囲み記事 - 523C 14L 0.8P 2.2 LaTeX式 - 11C 1L 0.0P 2.3 インライン命令 - 967C 17L 1.3P 2.3.1 書体 - 74C 1L 0.0P 2.3.2 見出し内 BOLD,ITALIC,TT,STRONG,EM,CODE,TTB,TTI,AMI,BOU,KW,UNDERLINE,INS、 - 797C 22L 1.3P 2.3.3 参照 - 39C 2L 0.1P 2.3.4 参考文献 - 194C 3L 0.3P 2.3.5 索引 + 110C 2L 0.2P 2.2 後注 + 523C 14L 0.8P 2.3 LaTeX式 + 11C 1L 0.0P 2.4 インライン命令 + 967C 17L 1.3P 2.4.1 書体 + 74C 1L 0.0P 2.4.2 見出し内 BOLD,ITALIC,TT,STRONG,EM,CODE,TTB,TTI,AMI,BOU,KW,UNDERLINE,INS、 + 797C 22L 1.3P 2.4.3 参照 + 39C 2L 0.1P 2.4.4 参考文献 + 194C 3L 0.3P 2.4.5 索引 + 34C 3L 0.1P 2.4.5.1 後注 ============================= 2255C 38L 4P ch03 ----------------------------- diff --git a/test/test_htmlbuilder.rb b/test/test_htmlbuilder.rb index 293ec3fec..6d080a5c2 100644 --- a/test/test_htmlbuilder.rb +++ b/test/test_htmlbuilder.rb @@ -2322,6 +2322,43 @@ def test_inline_fn assert_equal expected, fn end + def test_endnote + e = assert_raises(ReVIEW::ApplicationError) { compile_block("//endnote[foo][bar]\n\n@{foo}\n") } + assert_equal '//endnote is found but //printendnotes is not found.', e.message + + actual = compile_block("@{foo}\n//endnote[foo][bar]\n//printendnotes\n") + expected = <<-'EOS' +

(1)

+
+

(1) bar

+
+EOS + assert_equal expected, actual + + @book.config['epubmaker'] ||= {} + @book.config['epubmaker']['back_footnote'] = true + actual = compile_block("@{foo}\n//endnote[foo][bar]\n//printendnotes\n") + expected = <<-'EOS' +

(1)

+
+

(1) bar

+
+EOS + assert_equal expected, actual + + I18n.set('html_endnote_textmark', '+%s:') + I18n.set('html_endnote_refmark', '+%s:') + I18n.set('html_footnote_backmark', '←') + actual = compile_block("@{foo}\n//endnote[foo][bar]\n//printendnotes\n") + expected = <<-'EOS' +

+1:

+
+

+1:bar

+
+EOS + assert_equal expected, actual + end + def test_inline_hd book = ReVIEW::Book::Base.new book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re]) @@ -2868,6 +2905,8 @@ def test_inline_unknown assert_match(/unknown image: n/, @log_io.string) assert_raises(ReVIEW::ApplicationError) { compile_block("@{n}\n") } assert_match(/unknown footnote: n/, @log_io.string) + assert_raises(ReVIEW::ApplicationError) { compile_block("@{n}\n") } + assert_match(/unknown endnote: n/, @log_io.string) assert_raises(ReVIEW::ApplicationError) { compile_block("@{n}\n") } assert_match(/unknown headline: n/, @log_io.string) %w[list table column].each do |name| diff --git a/test/test_latexbuilder.rb b/test/test_latexbuilder.rb index 2d0a1ac14..0b063d079 100644 --- a/test/test_latexbuilder.rb +++ b/test/test_latexbuilder.rb @@ -257,6 +257,20 @@ def test_inline_ttb assert_equal 'test \\reviewttb{inline test} test2', actual end + def test_endnote + e = assert_raises(ReVIEW::ApplicationError) { compile_block("//endnote[foo][bar]\n\n@{foo}\n") } + assert_equal '//endnote is found but //printendnotes is not found.', e.message + + actual = compile_block("@{foo}\n//endnote[foo][bar]\n//printendnotes\n") + expected = <<-'EOS' + +\endnote{bar} + +\theendnotes +EOS + assert_equal expected, actual + end + def test_inline_hd_chap def @chapter.headline_index item = Book::Index::Item.new('chap1|test', [1, 1], 'te_st') diff --git a/test/test_markdownbuilder.rb b/test/test_markdownbuilder.rb index e8bcdaa6e..027aa0d90 100644 --- a/test/test_markdownbuilder.rb +++ b/test/test_markdownbuilder.rb @@ -106,6 +106,19 @@ def test_inline_comment_for_draft assert_equal %Q(test コメント test2), actual end + def test_endnote + e = assert_raises(ReVIEW::ApplicationError) { compile_block("//endnote[foo][bar]\n\n@{foo}\n") } + assert_equal '//endnote is found but //printendnotes is not found.', e.message + + actual = compile_block("@{foo}\n//endnote[foo][bar]\n//printendnotes\n") + expected = <<-'EOS' +(1) + +(1) bar +EOS + assert_equal expected, actual + end + def test_inline_hd_chap def @chapter.headline_index item = Book::Index::Item.new('chap1|test', [1, 1], 'te_st') diff --git a/test/test_plaintextbuilder.rb b/test/test_plaintextbuilder.rb index aaa489ed4..c72c75d52 100644 --- a/test/test_plaintextbuilder.rb +++ b/test/test_plaintextbuilder.rb @@ -762,6 +762,18 @@ def test_texequation assert_equal %Q(\\sin\n1^{2}\n\n), actual end + def test_endnote + e = assert_raises(ReVIEW::ApplicationError) { compile_block("//endnote[foo][bar]\n\n@{foo}\n") } + assert_equal '//endnote is found but //printendnotes is not found.', e.message + + actual = compile_block("@{foo}\n//endnote[foo][bar]\n//printendnotes\n") + expected = <<-'EOS' +(1) +(1) bar +EOS + assert_equal expected, actual + end + def test_inline_unknown assert_raises(ReVIEW::ApplicationError) { compile_block("@{n}\n") } assert_match(/unknown image: n/, @log_io.string) @@ -770,6 +782,10 @@ def test_inline_unknown assert_raises(ReVIEW::ApplicationError) { compile_block("@{n}\n") } assert_match(/unknown footnote: n/, @log_io.string) + @log_io.string = '' + assert_raises(ReVIEW::ApplicationError) { compile_block("@{n}\n") } + assert_match(/unknown endnote: n/, @log_io.string) + @log_io.string = '' assert_raises(ReVIEW::ApplicationError) { compile_block("@{n}\n") } assert_match(/unknown headline: n/, @log_io.string) diff --git a/test/test_rstbuilder.rb b/test/test_rstbuilder.rb index b1326ebcb..eed60dba1 100644 --- a/test/test_rstbuilder.rb +++ b/test/test_rstbuilder.rb @@ -513,6 +513,19 @@ def test_texequation \\sin 1^{2} +EOS + assert_equal expected, actual + end + + def test_endnote + e = assert_raises(ReVIEW::ApplicationError) { compile_block("//endnote[foo][bar]\n\n@{foo}\n") } + assert_equal '//endnote is found but //printendnotes is not found.', e.message + + actual = compile_block("@{foo}\n//endnote[foo][bar]\n//printendnotes\n") + expected = <<-'EOS' + [(1)]_ + +.. [(1)] bar EOS assert_equal expected, actual end diff --git a/test/test_topbuilder.rb b/test/test_topbuilder.rb index 0af665b7b..a52f0c53e 100644 --- a/test/test_topbuilder.rb +++ b/test/test_topbuilder.rb @@ -999,6 +999,20 @@ def test_inline_w end end + def test_endnote + e = assert_raises(ReVIEW::ApplicationError) { compile_block("//endnote[foo][bar]\n\n@{foo}\n") } + assert_equal '//endnote is found but //printendnotes is not found.', e.message + + actual = compile_block("@{foo}\n//endnote[foo][bar]\n//printendnotes\n") + expected = <<-'EOS' +【後注1】 +◆→開始:後注←◆ +【後注1】bar +◆→終了:後注←◆ +EOS + assert_equal expected, actual + end + def test_inline_unknown assert_raises(ReVIEW::ApplicationError) { compile_block("@{n}\n") } assert_match(/unknown image: n/, @log_io.string) @@ -1007,6 +1021,10 @@ def test_inline_unknown assert_raises(ReVIEW::ApplicationError) { compile_block("@{n}\n") } assert_match(/unknown footnote: n/, @log_io.string) + @log_io.string = '' + assert_raises(ReVIEW::ApplicationError) { compile_block("@{n}\n") } + assert_match(/unknown endnote: n/, @log_io.string) + @log_io.string = '' assert_raises(ReVIEW::ApplicationError) { compile_block("@{n}\n") } assert_match(/unknown headline: n/, @log_io.string)