Skip to content

Commit 42091bf

Browse files
authored
Merge pull request #949 from nobu/non-RD
Non-RD parts
2 parents fadc712 + e1679fa commit 42091bf

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

lib/rdoc/rd/block_parser.ry

+12-8
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,6 @@ end
230230

231231
# :stopdoc:
232232

233-
TMPFILE = ["rdtmp", $$, 0]
234-
235233
MARK_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

test/rdoc/test_rdoc_rd_block_parser.rb

+21
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,27 @@ def test_parse_include_subtree
168168
tf.close!
169169
end
170170

171+
=begin
172+
def test_parse_include_other_format
173+
@block_parser.include_path = [Dir.tmpdir]
174+
175+
expected =
176+
doc(
177+
blank_line,
178+
para("include ((*worked*))"),
179+
blank_line,
180+
blank_line)
181+
182+
str = <<~STR
183+
=begin nonrd
184+
<<< worked
185+
=end
186+
STR
187+
188+
assert_equal(expected, @block_parser.parse str.lines.to_a)
189+
end
190+
=end
191+
171192
def test_parse_heading
172193
assert_equal doc(head(1, "H")), parse("= H")
173194
assert_equal doc(head(2, "H")), parse("== H")

0 commit comments

Comments
 (0)