Skip to content

Commit

Permalink
fix: comments in C files use the global markup option
Browse files Browse the repository at this point in the history
Previously, Parser::C comments all defaulted to "rdoc" format, even
when the user had set a different default with the `--markup=<choice>`
option.
  • Loading branch information
flavorjones committed Oct 11, 2021
1 parent a3d366f commit 4643b08
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rdoc/parser/c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ def initialize top_level, file_name, content, options, stats
@classes = load_variable_map :c_class_variables
@singleton_classes = load_variable_map :c_singleton_class_variables

@markup = @options.markup

# class_variable => { function => [method, ...] }
@methods = Hash.new { |h, f| h[f] = Hash.new { |i, m| i[m] = [] } }

Expand Down Expand Up @@ -1223,6 +1225,8 @@ def scan
end

def new_comment text = nil, location = nil, language = nil
RDoc::Comment.new(text, location, language)
RDoc::Comment.new(text, location, language).tap do |comment|
comment.format = @markup
end
end
end
17 changes: 17 additions & 0 deletions test/rdoc/test_rdoc_parser_c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,23 @@ def test_markup_format_default
assert_equal("rdoc", klass.attributes.find {|a| a.name == "default_format"}.comment.format)
end

def test_markup_format_override
content = <<-EOF
void Init_Blah(void) {
cBlah = rb_define_class("Blah", rb_cObject);
/*
* This should be interpreted in the default format.
*/
rb_attr(cBlah, rb_intern("default_format"), 1, 1, Qfalse);
}
EOF

@options.markup = "markdown"
klass = util_get_class content, 'cBlah'
assert_equal("markdown", klass.attributes.find {|a| a.name == "default_format"}.comment.format)
end

def util_get_class content, name = nil
@parser = util_parser content
@parser.scan
Expand Down

0 comments on commit 4643b08

Please sign in to comment.