Skip to content

Commit b4bc7b1

Browse files
authored
[clang-doc] add support for comments for members in HTML output (#101255)
currently the HTML output does not support comments attached to class members, this patch modifies the HTMLGenerator to add comments for the output.
1 parent b6448a0 commit b4bc7b1

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

clang-tools-extra/clang-doc/HTMLGenerator.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx);
352352
static std::vector<std::unique_ptr<TagNode>>
353353
genHTML(const FunctionInfo &I, const ClangDocContext &CDCtx,
354354
StringRef ParentInfoDir);
355+
static std::unique_ptr<TagNode> genHTML(const std::vector<CommentInfo> &C);
355356

356357
static std::vector<std::unique_ptr<TagNode>>
357358
genEnumsBlock(const std::vector<EnumInfo> &Enums,
@@ -418,9 +419,13 @@ genRecordMembersBlock(const llvm::SmallVector<MemberTypeInfo, 4> &Members,
418419
if (Access != "")
419420
Access = Access + " ";
420421
auto LIBody = std::make_unique<TagNode>(HTMLTag::TAG_LI);
421-
LIBody->Children.emplace_back(std::make_unique<TextNode>(Access));
422-
LIBody->Children.emplace_back(genReference(M.Type, ParentInfoDir));
423-
LIBody->Children.emplace_back(std::make_unique<TextNode>(" " + M.Name));
422+
auto MemberDecl = std::make_unique<TagNode>(HTMLTag::TAG_DIV);
423+
MemberDecl->Children.emplace_back(std::make_unique<TextNode>(Access));
424+
MemberDecl->Children.emplace_back(genReference(M.Type, ParentInfoDir));
425+
MemberDecl->Children.emplace_back(std::make_unique<TextNode>(" " + M.Name));
426+
if (!M.Description.empty())
427+
LIBody->Children.emplace_back(genHTML(M.Description));
428+
LIBody->Children.emplace_back(std::move(MemberDecl));
424429
ULBody->Children.emplace_back(std::move(LIBody));
425430
}
426431
return Out;

clang-tools-extra/test/clang-doc/basic-project.test

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@
9191
// HTML-RECTANGLE: <a href="Shape.html">Shape</a>
9292
// HTML-RECTANGLE: </p>
9393
// HTML-RECTANGLE: <h2 id="Members">Members</h2>
94-
// HTML-RECTANGLE: <li>private double width_</li>
95-
// HTML-RECTANGLE: <li>private double height_</li>
94+
// HTML-RECTANGLE: <p> Width of the rectangle.</p>
95+
// HTML-RECTANGLE: <div>private double width_</div>
96+
// HTML-RECTANGLE: <p> Height of the rectangle.</p>
97+
// HTML-RECTANGLE: <div>private double height_</div>
9698
// HTML-RECTANGLE: <h2 id="Functions">Functions</h2>
9799
// HTML-RECTANGLE: <h3 id="{{([0-9A-F]{40})}}">Rectangle</h3>
98100
// HTML-RECTANGLE: <p>public void Rectangle(double width, double height)</p>
@@ -112,7 +114,8 @@
112114
// HTML-CIRCLE: <a href="Shape.html">Shape</a>
113115
// HTML-CIRCLE: </p>
114116
// HTML-CIRCLE: <h2 id="Members">Members</h2>
115-
// HTML-CIRCLE: <li>private double radius_</li>
117+
// HTML-CIRCLE: <p> Radius of the circle.</p>
118+
// HTML-CIRCLE: <div>private double radius_</div>
116119
// HTML-CIRCLE: <h2 id="Functions">Functions</h2>
117120
// HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">Circle</h3>
118121
// HTML-CIRCLE: <p>public void Circle(double radius)</p>

clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ TEST(HTMLGeneratorTest, emitRecordHTML) {
197197
</p>
198198
<h2 id="Members">Members</h2>
199199
<ul>
200-
<li>private int X</li>
200+
<li>
201+
<div>private int X</div>
202+
</li>
201203
</ul>
202204
<h2 id="Records">Records</h2>
203205
<ul>

0 commit comments

Comments
 (0)