clang-tools  9.0.0
FormattedString.h
Go to the documentation of this file.
1 //===--- FormattedString.h ----------------------------------*- C++-*------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // A simple intermediate representation of formatted text that could be
10 // converted to plaintext or markdown.
11 //
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_FORMATTEDSTRING_H
14 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_FORMATTEDSTRING_H
15 
16 #include <string>
17 #include <vector>
18 
19 namespace clang {
20 namespace clangd {
21 
22 /// A structured string representation that could be converted to markdown or
23 /// plaintext upon requrest.
25 public:
26  /// Append plain text to the end of the string.
27  void appendText(std::string Text);
28  /// Append a block of C++ code. This translates to a ``` block in markdown.
29  /// In a plain text representation, the code block will be surrounded by
30  /// newlines.
31  void appendCodeBlock(std::string Code, std::string Language = "cpp");
32  /// Append an inline block of C++ code. This translates to the ` block in
33  /// markdown.
34  void appendInlineCode(std::string Code);
35 
36  std::string renderAsMarkdown() const;
37  std::string renderAsPlainText() const;
38  std::string renderForTests() const;
39 
40 private:
41  enum class ChunkKind {
42  PlainText, /// A plain text paragraph.
43  CodeBlock, /// A block of code.
44  InlineCodeBlock, /// An inline block of code.
45  };
46  struct Chunk {
47  ChunkKind Kind = ChunkKind::PlainText;
48  std::string Contents;
49  /// Language for code block chunks. Ignored for other chunks.
50  std::string Language;
51  };
52  std::vector<Chunk> Chunks;
53 };
54 
55 } // namespace clangd
56 } // namespace clang
57 
58 #endif
llvm::StringRef Contents
std::string renderForTests() const
void appendText(std::string Text)
Append plain text to the end of the string.
std::string renderAsMarkdown() const
A structured string representation that could be converted to markdown or plaintext upon requrest...
BindArgumentKind Kind
void appendInlineCode(std::string Code)
Append an inline block of C++ code.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::string renderAsPlainText() const
void appendCodeBlock(std::string Code, std::string Language="cpp")
Append a block of C++ code.