230230
231231# :stopdoc:
232232
233- TMPFILE = ["rdtmp", $$, 0]
234-
235233MARK_TO_LEVEL = {
236234 '=' => 1,
237235 '==' => 2,
@@ -341,15 +339,19 @@ def next_token # :nodoc:
341339 # non-RD part begin
342340 when /^=begin\s+(\w+)/
343341 part = $1
342+ =begin # not imported to RDoc
344343 if @in_part # if in non-RD part
345344 @part_content.push(line)
346345 else
347346 @in_part = part if @tree.filter[part] # if filter exists
348347# p "BEGIN_PART: #{@in_part}" # DEBUG
349348 end
349+ =end
350+ @in_part = part
350351 # non-RD part end
351- when /^=end/
352+ when /^=end(?:$|[\s\0\C-d\C-z]) /
352353 if @in_part # if in non-RD part
354+ =begin # not imported to RDoc
353355# p "END_PART: #{@in_part}" # DEBUG
354356 # make Part-in object
355357 part = RDoc::RD::Part.new(@part_content.join(""), @tree, "r")
@@ -360,20 +362,22 @@ def next_token # :nodoc:
360362 if @tree.filter[@in_part].mode == :rd # if output is RD formatted
361363 subtree = parse_subtree(part_out.to_a)
362364 else # if output is target formatted
363- basename = TMPFILE.join('.')
364- TMPFILE[-1] += 1
365- tmpfile = open(@tree.tmp_dir + "/" + basename + ".#{@in_part}", "w")
366- tmpfile.print(part_out)
367- tmpfile.close
365+ basename = Tempfile.create(["rdtmp", ".#{@in_part}"], @tree.tmp_dir) do |tmpfile|
366+ tmpfile.print(part_out)
367+ File.basename(tmpfile.path)
368+ end
368369 subtree = parse_subtree(["=begin\n", "<<< #{basename}\n", "=end\n"])
369370 end
370371 @in_part = nil
371372 return [:SUBTREE, subtree]
373+ =end
372374 end
373375 else
376+ =begin # not imported to RDoc
374377 if @in_part # if in non-RD part
375378 @part_content.push(line)
376379 end
380+ =end
377381 end
378382 end
379383
0 commit comments