diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index cae1a686266c..599b381cea60 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -103,6 +103,18 @@ static json::Value extractTextComments(Object *ParagraphComment) { return *ParagraphComment->get("Children"); } +static json::Value extractVerbatimComments(json::Array VerbatimLines) { + json::Value TextArray = json::Array(); + auto &TextArrayRef = *TextArray.getAsArray(); + for (auto &Line : VerbatimLines) + TextArrayRef.push_back(*Line.getAsObject() + ->get("VerbatimBlockLineComment") + ->getAsObject() + ->get("Text")); + + return TextArray; +} + static Object serializeComment(const CommentInfo &I, Object &Description) { // taken from PR #142273 Object Obj = Object(); @@ -157,13 +169,11 @@ static Object serializeComment(const CommentInfo &I, Object &Description) { } case CommentKind::CK_VerbatimBlockComment: { - Child.insert({"Text", I.Text}); - if (!I.CloseName.empty()) - Child.insert({"CloseName", I.CloseName}); - Child.insert({"Children", ChildArr}); - if (I.CloseName == "endcode") - insertComment(Description, ChildVal, "CodeComments"); - else if (I.CloseName == "endverbatim") + if (I.CloseName == "endcode") { + // We don't support \code language specification + auto TextCommentsArray = extractVerbatimComments(CARef); + insertComment(Description, TextCommentsArray, "CodeComments"); + } else if (I.CloseName == "endverbatim") insertComment(Description, ChildVal, "VerbatimComments"); return Obj; } diff --git a/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css b/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css index a885a36cb4a3..e555ee7c370f 100644 --- a/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css +++ b/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css @@ -469,3 +469,7 @@ a, a:visited, a:hover, a:active { text-decoration: none; color: inherit; } + +.code-block { + white-space: pre-line; +} diff --git a/clang-tools-extra/clang-doc/assets/comment-template.mustache b/clang-tools-extra/clang-doc/assets/comment-template.mustache index 89c48d26278c..4e38e5fb92d1 100644 --- a/clang-tools-extra/clang-doc/assets/comment-template.mustache +++ b/clang-tools-extra/clang-doc/assets/comment-template.mustache @@ -40,6 +40,20 @@ {{/.}} {{/ReturnComments}} {{/HasReturnComments}} +{{#HasCodeComments}} +

Code

+ {{#CodeComments}} +
+
+            
+            {{#.}}
+            {{.}}
+            {{/.}}
+            
+        
+
+ {{/CodeComments}} +{{/HasCodeComments}} {{#BlockCommandComment}}
diff --git a/clang-tools-extra/test/clang-doc/Inputs/basic-project/include/Circle.h b/clang-tools-extra/test/clang-doc/Inputs/basic-project/include/Circle.h index 7bee3ffa9253..74bffcdec993 100644 --- a/clang-tools-extra/test/clang-doc/Inputs/basic-project/include/Circle.h +++ b/clang-tools-extra/test/clang-doc/Inputs/basic-project/include/Circle.h @@ -26,6 +26,10 @@ public: /** * @brief Calculates the perimeter of the circle. * + * @code + * Circle circle(5.0); + * double perimeter = circle.perimeter(); + * @endcode * @return double The perimeter of the circle. */ double perimeter() const override; diff --git a/clang-tools-extra/test/clang-doc/basic-project.mustache.test b/clang-tools-extra/test/clang-doc/basic-project.mustache.test index 2c87fe253319..e2d9da60183f 100644 --- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test +++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test @@ -729,6 +729,15 @@ HTML-CIRCLE:

HTML-CIRCLE:
HTML-CIRCLE:

Returns

HTML-CIRCLE:

double The perimeter of the circle.

+HTML-CIRCLE:

Code

+HTML-CIRCLE:
+HTML-CIRCLE:
+HTML-CIRCLE:                            
+HTML-CIRCLE:                            Circle circle(5.0);
+HTML-CIRCLE:                            double perimeter = circle.perimeter();
+HTML-CIRCLE:                            
+HTML-CIRCLE:                        
+HTML-CIRCLE:
HTML-CIRCLE:
HTML-CIRCLE: HTML-CIRCLE: