*** lib/hikidoc.rb.orig Sat Aug 8 03:10:47 2009 --- lib/hikidoc.rb Mon Aug 10 22:26:39 2009 *************** *** 58,63 **** --- 58,64 ---- @options = default_options.merge(options) @header_re = nil @level = options[:level] || 1 + @plugin_blocks = [] @plugin_syntax = options[:plugin_syntax] || method(:valid_plugin_syntax?) end *************** *** 96,102 **** def escape_plugin_blocks(text) s = StringScanner.new(text) buf = "" - @plugin_blocks = [] while chunk = s.scan_until(/\{\{/) tail = chunk[-2, 2] chunk[-2, 2] = "" --- 97,102 ---- *************** *** 328,337 **** INDENTED_PRE_RE = /\A[ \t]/ def compile_indented_pre(f) ! lines = f.span(INDENTED_PRE_RE)\ ! .map {|line| rstrip(line.sub(INDENTED_PRE_RE, "")) } ! text = restore_plugin_block(lines.join("\n")) @output.preformatted(@output.text(text)) end --- 328,359 ---- INDENTED_PRE_RE = /\A[ \t]/ + def backtrack(str, f) + escape_plugin_blocks(str) { |escaped| + escaped.split(/\r?\n/)\ + .reverse_each { |l| f.ungets(l) } + } + end + def compile_indented_pre(f) ! text = "" ! rev = "" ! inpre = true ! while inpre && f.next? ! restore_plugin_block(f.gets).each_line do |l| ! if inpre ! if l.match(INDENTED_PRE_RE) ! text << rstrip(l.sub(INDENTED_PRE_RE, "")) + "\n" ! next ! else ! inpre = false ! end ! end ! rev << l ! end ! end ! text.chomp! ! backtrack(rev, f) unless rev.empty? @output.preformatted(@output.text(text)) end *************** *** 340,347 **** def compile_block_pre(f) m = BLOCK_PRE_OPEN_RE.match(f.gets) or raise UnexpectedError, "must not happen" ! str = restore_plugin_block(f.break(BLOCK_PRE_CLOSE_RE).join.chomp) ! f.gets @output.block_preformatted(str, m[1]) end --- 362,385 ---- def compile_block_pre(f) m = BLOCK_PRE_OPEN_RE.match(f.gets) or raise UnexpectedError, "must not happen" ! str = "" ! rev = "" ! inpre = true ! while inpre && f.next? ! restore_plugin_block(f.gets).each_line do |l| ! if inpre ! if l.match(BLOCK_PRE_CLOSE_RE) ! inpre = false ! else ! str << l ! end ! else ! rev << l ! end ! end ! end ! str.chomp! ! backtrack(rev, f) unless rev.empty? @output.block_preformatted(str, m[1]) end