Skip to content

Commit

Permalink
Respect modeline to detect parser
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Jan 11, 2024
1 parent 281e70b commit 485468f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/rdoc/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ def self.can_parse_by_name file_name
return parser if ext_name.empty?

if parser == RDoc::Parser::Simple and ext_name !~ /txt|rdoc/ then
case check_modeline file_name
case mode = check_modeline(file_name)
when nil, 'rdoc' then # continue
else return nil
else
RDoc::Parser.parsers.find { |_, p| return p if mode.casecmp?(p.name[/\w+\z/]) }
return nil
end
end

Expand Down
15 changes: 14 additions & 1 deletion test/rdoc/test_rdoc_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,23 @@ def test_can_parse_modeline
end

assert_equal RDoc::Parser::Simple, @RP.can_parse(readme_ext)
end

def test_can_parse_modeline_c
readme_inc = File.join Dir.tmpdir, "README.inc.#{$$}"

File.open readme_inc, 'w' do |io|
io.puts "/* README.inc - -*- c -*- created at: Mon Aug 7 16:45:54 JST 1995 */"
io.puts
io.puts "/* This document explains how to make extension libraries for Ruby. */"
end

assert_equal RDoc::Parser::C, @RP.can_parse(readme_inc)
ensure
File.unlink readme_ext
File.unlink readme_inc
end


##
# Selenium hides a .jar file using a .txt extension.

Expand Down

0 comments on commit 485468f

Please sign in to comment.