Skip to content

Commit c29aba7

Browse files
authored
[clang-doc] add support for block commands in clang-doc html output (#101108)
1 parent d48b807 commit c29aba7

File tree

2 files changed

+81
-16
lines changed

2 files changed

+81
-16
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,19 @@ static std::unique_ptr<HTMLNode> genHTML(const CommentInfo &I) {
678678
return std::move(ParagraphComment);
679679
}
680680

681+
if (I.Kind == "BlockCommandComment") {
682+
auto BlockComment = std::make_unique<TagNode>(HTMLTag::TAG_DIV);
683+
BlockComment->Children.emplace_back(
684+
std::make_unique<TagNode>(HTMLTag::TAG_DIV, I.Name));
685+
for (const auto &Child : I.Children) {
686+
std::unique_ptr<HTMLNode> Node = genHTML(*Child);
687+
if (Node)
688+
BlockComment->Children.emplace_back(std::move(Node));
689+
}
690+
if (BlockComment->Children.empty())
691+
return nullptr;
692+
return std::move(BlockComment);
693+
}
681694
if (I.Kind == "TextComment") {
682695
if (I.Text == "")
683696
return nullptr;

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

Lines changed: 68 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,62 @@
5656

5757
// HTML-SHAPE: <h1>class Shape</h1>
5858
// HTML-SHAPE: <p>Defined at line 8 of file {{.*}}Shape.h</p>
59+
// HTML-SHAPE: <div>brief</div>
60+
// HTML-SHAPE: <p> Abstract base class for shapes.</p>
5961
// HTML-SHAPE: <p> Provides a common interface for different types of shapes.</p>
6062
// HTML-SHAPE: <h2 id="Functions">Functions</h2>
6163
// HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
6264
// HTML-SHAPE: <p>public double area()</p>
65+
// HTML-SHAPE: <div>brief</div>
66+
// HTML-SHAPE: <p> Calculates the area of the shape.</p>
6367
// HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">perimeter</h3>
6468
// HTML-SHAPE: <p>public double perimeter()</p>
69+
// HTML-SHAPE: <div>brief</div>
70+
// HTML-SHAPE: <p> Calculates the perimeter of the shape.</p>
71+
// HTML-SHAPE: <div>return</div>
72+
// HTML-SHAPE: <p> double The perimeter of the shape.</p>
6573
// HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">~Shape</h3>
6674
// HTML-SHAPE: <p>public void ~Shape()</p>
6775
// HTML-SHAPE: <p>Defined at line 13 of file {{.*}}Shape.h</p>
76+
// HTML-SHAPE: <div>brief</div>
77+
// HTML-SHAPE: <p> Virtual destructor.</p>
6878

69-
// HTML-CALC: <h1>class Calculator</h1>
70-
// HTML-CALC: <p>Defined at line 8 of file {{.*}}Calculator.h</p>
71-
// HTML-CALC: <p> Provides basic arithmetic operations.</p>
72-
// HTML-CALC: <h2 id="Functions">Functions</h2>
73-
// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">add</h3>
74-
// HTML-CALC: <p>public int add(int a, int b)</p>
75-
// HTML-CALC: <p>Defined at line 3 of file {{.*}}Calculator.cpp</p>
76-
// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">subtract</h3>
77-
// HTML-CALC: <p>public int subtract(int a, int b)</p>
78-
// HTML-CALC: <p>Defined at line 7 of file {{.*}}Calculator.cpp</p>
79-
// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">multiply</h3>
80-
// HTML-CALC: <p>public int multiply(int a, int b)</p>
81-
// HTML-CALC: <p>Defined at line 11 of file {{.*}}Calculator.cpp</p>
82-
// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">divide</h3>
83-
// HTML-CALC: <p>public double divide(int a, int b)</p>
84-
// HTML-CALC: <p>Defined at line 15 of file {{.*}}Calculator.cpp</p>
79+
// HTML-CALC: <h1>class Calculator</h1>
80+
// HTML-CALC: <p>Defined at line 8 of file {{.*}}Calculator.h</p>
81+
// HTML-CALC: <div>brief</div>
82+
// HTML-CALC: <p> A simple calculator class.</p>
83+
// HTML-CALC: <p> Provides basic arithmetic operations.</p>
84+
// HTML-CALC: <h2 id="Functions">Functions</h2>
85+
// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">add</h3>
86+
// HTML-CALC: <p>public int add(int a, int b)</p>
87+
// HTML-CALC: <p>Defined at line 3 of file {{.*}}Calculator.cpp</p>
88+
// HTML-CALC: <div>brief</div>
89+
// HTML-CALC: <p> Adds two integers.</p>
90+
// HTML-CALC: <div>return</div>
91+
// HTML-CALC: <p> int The sum of a and b.</p>
92+
// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">subtract</h3>
93+
// HTML-CALC: <p>public int subtract(int a, int b)</p>
94+
// HTML-CALC: <p>Defined at line 7 of file {{.*}}Calculator.cpp</p>
95+
// HTML-CALC: <div>brief</div>
96+
// HTML-CALC: <p> Subtracts the second integer from the first.</p>
97+
// HTML-CALC: <div>return</div>
98+
// HTML-CALC: <p> int The result of a - b.</p>
99+
// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">multiply</h3>
100+
// HTML-CALC: <p>public int multiply(int a, int b)</p>
101+
// HTML-CALC: <p>Defined at line 11 of file {{.*}}Calculator.cpp</p>
102+
// HTML-CALC: <div>brief</div>
103+
// HTML-CALC: <p> Multiplies two integers.</p>
104+
// HTML-CALC: <div>return</div>
105+
// HTML-CALC: <p> int The product of a and b.</p>
106+
// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">divide</h3>
107+
// HTML-CALC: <p>public double divide(int a, int b)</p>
108+
// HTML-CALC: <p>Defined at line 15 of file {{.*}}Calculator.cpp</p>
109+
// HTML-CALC: <div>brief</div>
110+
// HTML-CALC: <p> Divides the first integer by the second.</p>
111+
// HTML-CALC: <div>return</div>
112+
// HTML-CALC: <p> double The result of a / b.</p>
113+
// HTML-CALC: <div>throw</div>
114+
// HTML-CALC: <p>if b is zero.</p>
85115

86116
// HTML-RECTANGLE: <h1>class Rectangle</h1>
87117
// HTML-RECTANGLE: <p>Defined at line 10 of file {{.*}}Rectangle.h</p>
@@ -99,15 +129,27 @@
99129
// HTML-RECTANGLE: <h3 id="{{([0-9A-F]{40})}}">Rectangle</h3>
100130
// HTML-RECTANGLE: <p>public void Rectangle(double width, double height)</p>
101131
// HTML-RECTANGLE: <p>Defined at line 3 of file {{.*}}Rectangle.cpp</p>
132+
// HTML-RECTANGLE: <div>brief</div>
133+
// HTML-RECTANGLE: <p> Constructs a new Rectangle object.</p>
102134
// HTML-RECTANGLE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
103135
// HTML-RECTANGLE: <p>public double area()</p>
104136
// HTML-RECTANGLE: <p>Defined at line 6 of file {{.*}}Rectangle.cpp</p>
137+
// HTML-RECTANGLE: <div>brief</div>
138+
// HTML-RECTANGLE: <p> Calculates the area of the rectangle.</p>
139+
// HTML-RECTANGLE: <div>return</div>
140+
// HTML-RECTANGLE: <p> double The area of the rectangle.</p>
105141
// HTML-RECTANGLE: <h3 id="{{([0-9A-F]{40})}}">perimeter</h3>
106142
// HTML-RECTANGLE: <p>public double perimeter()</p>
107143
// HTML-RECTANGLE: <p>Defined at line 10 of file {{.*}}Rectangle.cpp</p>
144+
// HTML-RECTANGLE: <div>brief</div>
145+
// HTML-RECTANGLE: <p> Calculates the perimeter of the rectangle.</p>
146+
// HTML-RECTANGLE: <div>return</div>
147+
// HTML-RECTANGLE: <p> double The perimeter of the rectangle.</p>
108148

109149
// HTML-CIRCLE: <h1>class Circle</h1>
110150
// HTML-CIRCLE: <p>Defined at line 10 of file {{.*}}Circle.h</p>
151+
// HTML-CIRCLE: <div>brief</div>
152+
// HTML-CIRCLE: <p> Circle class derived from Shape.</p>
111153
// HTML-CIRCLE: <p> Represents a circle with a given radius.</p>
112154
// HTML-CIRCLE: <p>
113155
// HTML-CIRCLE: Inherits from
@@ -120,12 +162,22 @@
120162
// HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">Circle</h3>
121163
// HTML-CIRCLE: <p>public void Circle(double radius)</p>
122164
// HTML-CIRCLE: <p>Defined at line 3 of file {{.*}}Circle.cpp</p>
165+
// HTML-CIRCLE: <div>brief</div>
166+
// HTML-CIRCLE: <p> Constructs a new Circle object.</p>
123167
// HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
124168
// HTML-CIRCLE: <p>public double area()</p>
125169
// HTML-CIRCLE: <p>Defined at line 5 of file {{.*}}Circle.cpp</p>
170+
// HTML-CIRCLE: <div>brief</div>
171+
// HTML-CIRCLE: <p> Calculates the area of the circle.</p>
172+
// HTML-CIRCLE: <div>return</div>
173+
// HTML-CIRCLE: <p> double The area of the circle.</p>
126174
// HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">perimeter</h3>
127175
// HTML-CIRCLE: <p>public double perimeter()</p>
128176
// HTML-CIRCLE: <p>Defined at line 9 of file {{.*}}Circle.cpp</p>
177+
// HTML-CIRCLE: <div>brief</div>
178+
// HTML-CIRCLE: <p> Calculates the perimeter of the circle.</p>
179+
// HTML-CIRCLE: <div>return</div>
180+
// HTML-CIRCLE: <p> double The perimeter of the circle.</p>
129181

130182
// MD-CALC: # class Calculator
131183
// MD-CALC: *Defined at .{{[\/]}}include{{[\/]}}Calculator.h#8*

0 commit comments

Comments
 (0)