diff --git a/lib/review/builder.rb b/lib/review/builder.rb index d00a3f4a1..9adc889f7 100644 --- a/lib/review/builder.rb +++ b/lib/review/builder.rb @@ -414,7 +414,12 @@ def inline_w(s) end def inline_wb(s) - inline_b(unescape(inline_w(s))) + translated = @dictionary[s] + if translated + inline_b(translated) + else + inline_b("[missing word: #{s}]") + end end def raw(str) @@ -433,9 +438,9 @@ def embed(lines, arg = nil) if arg builders = arg.gsub(/^\s*\|/, '').gsub(/\|\s*$/, '').gsub(/\s/, '').split(',') c = target_name - print lines.join if builders.include?(c) + print lines.join("\n") + "\n" if builders.include?(c) else - print lines.join + print lines.join("\n") + "\n" end end @@ -514,13 +519,13 @@ def graph(lines, id, command, caption = '') file = "#{id}.#{image_ext}" file_path = File.join(dir, file) - line = self.unescape(lines.join("\n")) + content = lines.join("\n") + "\n" tf = Tempfile.new('review_graph') - tf.puts line + tf.puts content tf.close begin - file_path = send("graph_#{command}".to_sym, id, file_path, line, tf.path) + file_path = send("graph_#{command}".to_sym, id, file_path, content, tf.path) ensure tf.unlink end @@ -644,9 +649,5 @@ def detab(str, num = nil) def escape(str) str end - - def unescape(str) - str - end end end # module ReVIEW diff --git a/lib/review/compiler.rb b/lib/review/compiler.rb index a0dd9ef41..62aca44d8 100644 --- a/lib/review/compiler.rb +++ b/lib/review/compiler.rb @@ -16,6 +16,9 @@ module ReVIEW class Compiler def initialize(strategy) @strategy = strategy + + ## commands which do not parse block lines in compiler + @non_parsed_commands = %i[embed texequation graph] end attr_reader :strategy @@ -422,7 +425,7 @@ def compile_paragraph(f) def read_command(f) line = f.gets name = line.slice(/[a-z]+/).to_sym - ignore_inline = (name == :embed) + ignore_inline = @non_parsed_commands.include?(name) args = parse_args(line.sub(%r{\A//[a-z]+}, '').rstrip.chomp('{'), name) @strategy.doc_status[name] = true lines = block_open?(line) ? read_block(f, ignore_inline) : nil @@ -439,7 +442,7 @@ def read_block(f, ignore_inline) buf = [] f.until_match(%r{\A//\}}) do |line| if ignore_inline - buf.push(line) + buf.push(line.chomp) elsif line !~ /\A\#@/ buf.push(text(line.rstrip)) end diff --git a/lib/review/htmlbuilder.rb b/lib/review/htmlbuilder.rb index 07f11a30e..d057ac04a 100644 --- a/lib/review/htmlbuilder.rb +++ b/lib/review/htmlbuilder.rb @@ -565,11 +565,11 @@ def texequation_body(lines) require 'math_ml' require 'math_ml/symbol/character_reference' p = MathML::LaTeX::Parser.new(symbol: MathML::Symbol::CharacterReference) - puts p.parse(unescape(lines.join("\n")), true) + print p.parse(lines.join("\n") + "\n", true) elsif @book.config['imgmath'] fontsize = @book.config['imgmath_options']['fontsize'].to_f lineheight = @book.config['imgmath_options']['lineheight'].to_f - math_str = "\\begin{equation*}\n\\fontsize{#{fontsize}}{#{lineheight}}\\selectfont\n#{unescape(lines.join("\n"))}\n\\end{equation*}\n" + math_str = "\\begin{equation*}\n\\fontsize{#{fontsize}}{#{lineheight}}\\selectfont\n#{lines.join("\n")}\n\\end{equation*}\n" key = Digest::SHA256.hexdigest(math_str) math_dir = File.join(@book.config['imagedir'], '_review_math') Dir.mkdir(math_dir) unless Dir.exist?(math_dir) diff --git a/lib/review/idgxmlbuilder.rb b/lib/review/idgxmlbuilder.rb index 8c5cce186..fde37d8b6 100644 --- a/lib/review/idgxmlbuilder.rb +++ b/lib/review/idgxmlbuilder.rb @@ -439,7 +439,7 @@ def texequation(lines, id = nil, caption = '') puts %Q() puts '
'
-      puts lines.join("\n")
+      print lines.join("\n")
       puts '
' puts '
' diff --git a/lib/review/latexbuilder.rb b/lib/review/latexbuilder.rb index fd1c78f0f..8e574ff9c 100644 --- a/lib/review/latexbuilder.rb +++ b/lib/review/latexbuilder.rb @@ -843,7 +843,7 @@ def texequation(lines, id = nil, caption = '') puts macro('begin', 'equation*') lines.each do |line| - puts unescape(line) + puts line end puts macro('end', 'equation*') diff --git a/lib/review/rstbuilder.rb b/lib/review/rstbuilder.rb index c2a88b7bd..5fdea23de 100644 --- a/lib/review/rstbuilder.rb +++ b/lib/review/rstbuilder.rb @@ -103,13 +103,13 @@ def headline(level, label, caption) blank end puts '=' * caption.size * 2 - when 2 then + when 2 p = '=' - when 3 then + when 3 p = '-' - when 4 then + when 4 p = '`' - when 5 then + when 5 p = '~' end diff --git a/lib/review/topbuilder.rb b/lib/review/topbuilder.rb index ca9d7b9f7..d799be126 100644 --- a/lib/review/topbuilder.rb +++ b/lib/review/topbuilder.rb @@ -184,7 +184,7 @@ def texequation(lines, id = nil, caption = '') if @book.config['imgmath'] fontsize = @book.config['imgmath_options']['fontsize'].to_f lineheight = @book.config['imgmath_options']['lineheight'].to_f - math_str = "\\begin{equation*}\n\\fontsize{#{fontsize}}{#{lineheight}}\\selectfont\n#{unescape(lines.join("\n"))}\n\\end{equation*}\n" + math_str = "\\begin{equation*}\n\\fontsize{#{fontsize}}{#{lineheight}}\\selectfont\n#{lines.join("\n")}\n\\end{equation*}\n" key = Digest::SHA256.hexdigest(math_str) math_dir = File.join(@book.config['imagedir'], '_review_math_text') Dir.mkdir(math_dir) unless Dir.exist?(math_dir)