Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-RD parts #949

Merged
merged 3 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 12 additions & 8 deletions lib/rdoc/rd/block_parser.ry
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ end

# :stopdoc:

TMPFILE = ["rdtmp", $$, 0]

MARK_TO_LEVEL = {
'=' => 1,
'==' => 2,
Expand Down Expand Up @@ -341,15 +339,19 @@ def next_token # :nodoc:
# non-RD part begin
when /^=begin\s+(\w+)/
part = $1
=begin # not imported to RDoc
if @in_part # if in non-RD part
@part_content.push(line)
else
@in_part = part if @tree.filter[part] # if filter exists
# p "BEGIN_PART: #{@in_part}" # DEBUG
end
=end
@in_part = part
# non-RD part end
when /^=end/
when /^=end(?:$|[\s\0\C-d\C-z])/
if @in_part # if in non-RD part
=begin # not imported to RDoc
# p "END_PART: #{@in_part}" # DEBUG
# make Part-in object
part = RDoc::RD::Part.new(@part_content.join(""), @tree, "r")
Expand All @@ -360,20 +362,22 @@ def next_token # :nodoc:
if @tree.filter[@in_part].mode == :rd # if output is RD formatted
subtree = parse_subtree(part_out.to_a)
else # if output is target formatted
basename = TMPFILE.join('.')
TMPFILE[-1] += 1
tmpfile = open(@tree.tmp_dir + "/" + basename + ".#{@in_part}", "w")
tmpfile.print(part_out)
tmpfile.close
basename = Tempfile.create(["rdtmp", ".#{@in_part}"], @tree.tmp_dir) do |tmpfile|
tmpfile.print(part_out)
File.basename(tmpfile.path)
end
subtree = parse_subtree(["=begin\n", "<<< #{basename}\n", "=end\n"])
end
@in_part = nil
return [:SUBTREE, subtree]
=end
end
else
=begin # not imported to RDoc
if @in_part # if in non-RD part
@part_content.push(line)
end
=end
end
end

Expand Down
21 changes: 21 additions & 0 deletions test/rdoc/test_rdoc_rd_block_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,27 @@ def test_parse_include_subtree
tf.close!
end

=begin
def test_parse_include_other_format
@block_parser.include_path = [Dir.tmpdir]

expected =
doc(
blank_line,
para("include ((*worked*))"),
blank_line,
blank_line)

str = <<~STR
=begin nonrd
<<< worked
=end
STR

assert_equal(expected, @block_parser.parse str.lines.to_a)
end
=end

def test_parse_heading
assert_equal doc(head(1, "H")), parse("= H")
assert_equal doc(head(2, "H")), parse("== H")
Expand Down