From ce51f1b6016402a07f85a303e28d95fd714de044 Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Sun, 5 Apr 2020 19:54:54 +0900 Subject: [PATCH] introduce //child op. Closes: #1492 --- lib/review/builder.rb | 34 +++- lib/review/compiler.rb | 1 + lib/review/htmlbuilder.rb | 18 +- lib/review/idgxmlbuilder.rb | 18 +- lib/review/latexbuilder.rb | 16 +- lib/review/plaintextbuilder.rb | 23 ++- lib/review/rstbuilder.rb | 4 +- test/test_htmlbuilder.rb | 275 +++++++++++++++++++++++++++++ test/test_idgxmlbuilder.rb | 182 +++++++++++++++++++ test/test_latexbuilder.rb | 307 +++++++++++++++++++++++++++++++++ test/test_plaintextbuilder.rb | 275 +++++++++++++++++++++++++++++ 11 files changed, 1142 insertions(+), 11 deletions(-) diff --git a/lib/review/builder.rb b/lib/review/builder.rb index 2d5e8805b..c1fadf8fd 100644 --- a/lib/review/builder.rb +++ b/lib/review/builder.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2002-2019 Minero Aoki, Kenshi Muto +# Copyright (c) 2002-2020 Minero Aoki, Kenshi Muto # # This program is free software. # You can distribute or modify this program under the terms of @@ -91,8 +91,19 @@ def highlight? false end + def solve_nest(s) + check_nest + s.gsub(/\x01→.+?←\x01/, '') + end + + def check_nest + if @children && !@children.empty? + error @children.reverse.map { |tag| "//child[#{tag}]" }.join(',') + ' miss close tag' + end + end + def result - @output.string + solve_nest(@output.string) end alias_method :raw_result, :result @@ -680,5 +691,24 @@ def detab(str, num = nil) def escape(str) str end + + def child(tag) + @children ||= [] + puts "\x01→#{tag}←\x01" + if tag.start_with?('/') + if @children.empty? + error "#{tag} is shown but there isn't any opened //child" + elsif @children[-1] != tag.sub('/', '') + error "#{tag} is shown but previous '#{@children[-1]}' is not closed yet" + else + @children.pop + end + else + unless %w[dl ol ul].include?(tag) + error "#{tag} is invalid value for //child (dl, ol, or ul)" + end + @children.push(tag) + end + end end end # module ReVIEW diff --git a/lib/review/compiler.rb b/lib/review/compiler.rb index 9278bbae7..d310d3f7f 100644 --- a/lib/review/compiler.rb +++ b/lib/review/compiler.rb @@ -159,6 +159,7 @@ def inline_defined?(name) defsingle :include, 1 defsingle :olnum, 1 defsingle :firstlinenum, 1 + defsingle :child, 1 definline :chapref definline :chap diff --git a/lib/review/htmlbuilder.rb b/lib/review/htmlbuilder.rb index 6ab59d335..fe3eb0c76 100644 --- a/lib/review/htmlbuilder.rb +++ b/lib/review/htmlbuilder.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2008-2019 Minero Aoki, Kenshi Muto, Masayoshi Takahashi, +# Copyright (c) 2008-2020 Minero Aoki, Kenshi Muto, Masayoshi Takahashi, # KADO Masanori # 2002-2007 Minero Aoki # @@ -92,7 +92,7 @@ def layoutfile def result # default XHTML header/footer @title = strip_html(compile_inline(@chapter.title)) - @body = @output.string + @body = solve_nest(@output.string) @language = @book.config['language'] @stylesheets = @book.config['stylesheet'] @next = @chapter.next_chapter @@ -107,6 +107,20 @@ def result ReVIEW::Template.load(layoutfile).result(binding) end + def solve_nest(s) + check_nest + s.gsub("\n\n\x01→dl←\x01", ''). + gsub("\x01→/dl←\x01", "\n←END\x01"). + gsub("\n\n\x01→ul←\x01", ''). + gsub("\x01→/ul←\x01", "\n←END\x01"). + gsub("\n\n\x01→ol←\x01", ''). + gsub("\x01→/ol←\x01", "\n←END\x01"). + gsub("←END\x01\n
", ''). + gsub("←END\x01\n
\x01→dl←\x01", ''). + gsub("\x01→/dl←\x01", "←END\x01"). + gsub("\x01→ul←\x01", ''). + gsub("\x01→/ul←\x01", "←END\x01"). + gsub("\x01→ol←\x01", ''). + gsub("\x01→/ol←\x01", "←END\x01"). + gsub("←END\x01
", ''). + gsub("←END\x01