Skip to content

Commit 836c829

Browse files
authored
Merge pull request #847 from flavorjones/flavorjones-fix-default-format-for-c-files
fix: use the global format default for C file comments
2 parents 62ae528 + 4643b08 commit 836c829

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

lib/rdoc/parser/c.rb

Lines changed: 16 additions & 9 deletions
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

@@ -439,7 +441,7 @@ def do_includes
439441
next unless cls = @classes[c]
440442
m = @known_classes[m] || m
441443

442-
comment = RDoc::Comment.new '', @top_level, :c
444+
comment = new_comment '', @top_level, :c
443445
incl = cls.add_include RDoc::Include.new(m, comment)
444446
incl.record_location @top_level
445447
end
@@ -521,7 +523,7 @@ def find_alias_comment class_name, new_name, old_name
521523
\s*"#{Regexp.escape new_name}"\s*,
522524
\s*"#{Regexp.escape old_name}"\s*\);%xm
523525

524-
RDoc::Comment.new($1 || '', @top_level, :c)
526+
new_comment($1 || '', @top_level, :c)
525527
end
526528

527529
##
@@ -560,7 +562,7 @@ def find_attr_comment var_name, attr_name, read = nil, write = nil
560562
''
561563
end
562564

563-
RDoc::Comment.new comment, @top_level, :c
565+
new_comment comment, @top_level, :c
564566
end
565567

566568
##
@@ -600,7 +602,7 @@ def find_body class_name, meth_name, meth_obj, file_content, quiet = false
600602

601603
case type
602604
when :func_def
603-
comment = RDoc::Comment.new args[0], @top_level, :c
605+
comment = new_comment args[0], @top_level, :c
604606
body = args[1]
605607
offset, = args[2]
606608

@@ -630,7 +632,7 @@ def find_body class_name, meth_name, meth_obj, file_content, quiet = false
630632

631633
body
632634
when :macro_def
633-
comment = RDoc::Comment.new args[0], @top_level, :c
635+
comment = new_comment args[0], @top_level, :c
634636
body = args[1]
635637
offset, = args[2]
636638

@@ -737,7 +739,7 @@ def find_class_comment class_name, class_mod
737739
comment = ''
738740
end
739741

740-
comment = RDoc::Comment.new comment, @top_level, :c
742+
comment = new_comment comment, @top_level, :c
741743
comment.normalize
742744

743745
look_for_directives_in class_mod, comment
@@ -782,7 +784,7 @@ def find_const_comment(type, const_name, class_name = nil)
782784
table[const_name] ||
783785
''
784786

785-
RDoc::Comment.new comment, @top_level, :c
787+
new_comment comment, @top_level, :c
786788
end
787789

788790
##
@@ -813,7 +815,7 @@ def find_override_comment class_name, meth_obj
813815

814816
return unless comment
815817

816-
RDoc::Comment.new comment, @top_level, :c
818+
new_comment comment, @top_level, :c
817819
end
818820

819821
##
@@ -947,7 +949,7 @@ def handle_constants(type, var_name, const_name, definition)
947949

948950
new_comment = "#{$1}#{new_comment.lstrip}"
949951

950-
new_comment = RDoc::Comment.new new_comment, @top_level, :c
952+
new_comment = self.new_comment(new_comment, @top_level, :c)
951953

952954
con = RDoc::Constant.new const_name, new_definition, new_comment
953955
else
@@ -1222,4 +1224,9 @@ def scan
12221224
@top_level
12231225
end
12241226

1227+
def new_comment text = nil, location = nil, language = nil
1228+
RDoc::Comment.new(text, location, language).tap do |comment|
1229+
comment.format = @markup
1230+
end
1231+
end
12251232
end

test/rdoc/test_rdoc_parser_c.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,6 +1930,39 @@ def test_scan_order_dependent
19301930
@store.all_classes_and_modules.map { |m| m.full_name }.sort
19311931
end
19321932

1933+
def test_markup_format_default
1934+
content = <<-EOF
1935+
void Init_Blah(void) {
1936+
cBlah = rb_define_class("Blah", rb_cObject);
1937+
1938+
/*
1939+
* This should be interpreted in the default format.
1940+
*/
1941+
rb_attr(cBlah, rb_intern("default_format"), 1, 1, Qfalse);
1942+
}
1943+
EOF
1944+
1945+
klass = util_get_class content, 'cBlah'
1946+
assert_equal("rdoc", klass.attributes.find {|a| a.name == "default_format"}.comment.format)
1947+
end
1948+
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+
19331966
def util_get_class content, name = nil
19341967
@parser = util_parser content
19351968
@parser.scan

0 commit comments

Comments
 (0)