[clang-tools-extra] [Clang-doc] Display values and comments in MD (PR #183754)

Samrudh Nelli via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 7 04:28:45 PST 2026


================
@@ -67,6 +70,46 @@ static void writeSourceFileRef(const ClangDocContext &CDCtx, const Location &L,
   OS << "\n\n";
 }
 
+static void extractCommentText(const CommentInfo &Comment,
+                               llvm::raw_ostream &OS) {
+
+  OS << Comment.Text;
+  bool FirstChild = true;
+
+  for (size_t Idx = 0, End = Comment.Children.size(); Idx < End; ++Idx) {
+    const auto &Child = Comment.Children[Idx];
+    llvm::SmallString<128> ChildBuffer;
+    llvm::raw_svector_ostream ChildOS(ChildBuffer);
+    extractCommentText(*Child, ChildOS);
+
+    if (ChildBuffer.empty())
+      continue;
+
+    if (Idx > 0 && Comment.Kind == CommentKind::CK_ParagraphComment &&
+        Comment.Children[Idx - 1]->Kind == CommentKind::CK_TextComment &&
+        Child->Kind == CommentKind::CK_TextComment)
+      OS << "<br>";
+
+    if (FirstChild)
+      FirstChild = false;
+    else if (Comment.Kind == CommentKind::CK_BlockCommandComment ||
+             Comment.Kind == CommentKind::CK_FullComment)
+      OS << "<br><br>";
+
+    OS << ChildBuffer;
----------------
SamrudhNelli wrote:

This approach is surely a lot more readable efficient than the previous one.. 
Thank you so much for helping me out with the approach.🙏

https://github.com/llvm/llvm-project/pull/183754


More information about the cfe-commits mailing list