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}} +
+
+ {{#.}}
+ {{.}}
+ {{/.}}
+
+
+
Returns
HTML-CIRCLE:double The perimeter of the circle.
+HTML-CIRCLE:Code
+HTML-CIRCLE: