Skip to content

Commit 4643b08

Browse files
committed
fix: comments in C files use the global markup option
Previously, Parser::C comments all defaulted to "rdoc" format, even when the user had set a different default with the `--markup=<choice>` option.
1 parent a3d366f commit 4643b08

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/rdoc/parser/c.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ def initialize top_level, file_name, content, options, stats
173173
@classes = load_variable_map :c_class_variables
174174
@singleton_classes = load_variable_map :c_singleton_class_variables
175175

176+
@markup = @options.markup
177+
176178
# class_variable => { function => [method, ...] }
177179
@methods = Hash.new { |h, f| h[f] = Hash.new { |i, m| i[m] = [] } }
178180

@@ -1223,6 +1225,8 @@ def scan
12231225
end
12241226

12251227
def new_comment text = nil, location = nil, language = nil
1226-
RDoc::Comment.new(text, location, language)
1228+
RDoc::Comment.new(text, location, language).tap do |comment|
1229+
comment.format = @markup
1230+
end
12271231
end
12281232
end

test/rdoc/test_rdoc_parser_c.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,23 @@ def test_markup_format_default
19461946
assert_equal("rdoc", klass.attributes.find {|a| a.name == "default_format"}.comment.format)
19471947
end
19481948

1949+
def test_markup_format_override
1950+
content = <<-EOF
1951+
void Init_Blah(void) {
1952+
cBlah = rb_define_class("Blah", rb_cObject);
1953+
1954+
/*
1955+
* This should be interpreted in the default format.
1956+
*/
1957+
rb_attr(cBlah, rb_intern("default_format"), 1, 1, Qfalse);
1958+
}
1959+
EOF
1960+
1961+
@options.markup = "markdown"
1962+
klass = util_get_class content, 'cBlah'
1963+
assert_equal("markdown", klass.attributes.find {|a| a.name == "default_format"}.comment.format)
1964+
end
1965+
19491966
def util_get_class content, name = nil
19501967
@parser = util_parser content
19511968
@parser.scan

0 commit comments

Comments
 (0)