clang-tools 22.0.0git
clang::clangd::markup::Paragraph Class Reference

Represents parts of the markup that can contain strings, like inline code, code block or plain text. More...

#include <Markup.h>

Inheritance diagram for clang::clangd::markup::Paragraph:
[legend]

Public Member Functions

void renderEscapedMarkdown (llvm::raw_ostream &OS) const override
void renderMarkdown (llvm::raw_ostream &OS) const override
void renderPlainText (llvm::raw_ostream &OS) const override
std::unique_ptr< Blockclone () const override
ParagraphappendText (llvm::StringRef Text)
 Append plain text to the end of the string.
ParagraphappendEmphasizedText (llvm::StringRef Text)
 Append emphasized text, this translates to the * block in markdown.
ParagraphappendBoldText (llvm::StringRef Text)
 Append bold text, this translates to the ** block in markdown.
void addCodeBlock (std::string Code, std::string Language="cpp")
 Append inline code, this translates to the ` block in markdown.
ParagraphaddHeading (size_t Level)
 Heading is a special type of paragraph that will be prepended with Level many '#'s in markdown.
BulletList & addBulletList ()
std::string asEscapedMarkdown () const
 Doesn't contain any trailing newlines and escaped markdown syntax.
std::string asMarkdown () const
 Doesn't contain any trailing newlines.
std::string asPlainText () const
 Doesn't contain any trailing newlines.
Public Member Functions inherited from clang::clangd::markup::Block
std::string asEscapedMarkdown () const
std::string asMarkdown () const
std::string asPlainText () const
virtual bool isRuler () const
virtual ~Block ()=default

Detailed Description

Represents parts of the markup that can contain strings, like inline code, code block or plain text.

One must introduce different paragraphs to create separate blocks.

Definition at line 45 of file Markup.h.

Member Function Documentation

◆ addBulletList()

BulletList & clang::clangd::markup::Paragraph::addBulletList ( )

◆ addCodeBlock()

void clang::clangd::markup::Paragraph::addCodeBlock ( std::string Code,
std::string Language = "cpp" )

Append inline code, this translates to the ` block in markdown.

/ Preserve indicates the code span must be apparent even in plaintext. Paragraph &appendCode(llvm::StringRef Code, bool Preserve = false);

/ Ensure there is space between the surrounding chunks. / Has no effect at the beginning or end of a paragraph. Paragraph &appendSpace();

private: enum ChunkKind { PlainText, InlineCode, Bold, Emphasized }; struct Chunk { ChunkKind Kind = PlainText; Preserve chunk markers in plaintext. bool Preserve = false; std::string Contents; Whether this chunk should be surrounded by whitespace. Consecutive SpaceAfter and SpaceBefore will be collapsed into one space. Code spans don't usually set this: their spaces belong "inside" the span. bool SpaceBefore = false; bool SpaceAfter = false; }; std::vector<Chunk> Chunks;

/ Estimated size of the string representation of this paragraph. / Used to reserve space in the output string. / Each time paragraph content is added, this value is updated. / This is an estimate, so it may not be accurate but can help / reducing dynamically reallocating string memory. unsigned EstimatedStringSize = 0;

Paragraph &appendChunk(llvm::StringRef Contents, ChunkKind K);

llvm::StringRef chooseMarker(llvm::ArrayRef<llvm::StringRef> Options, llvm::StringRef Text) const; bool punctuationIndicatesLineBreak(llvm::StringRef Line) const; bool isHardLineBreakIndicator(llvm::StringRef Rest) const; bool isHardLineBreakAfter(llvm::StringRef Line, llvm::StringRef Rest) const; };

/ Represents a sequence of one or more documents. Knows how to print them in a / list like format, e.g. by prepending with "- " and indentation. class BulletList : public Block { public: BulletList(); ~BulletList();

A BulletList rendered in markdown is a tight list if it is not a nested list and no item contains multiple paragraphs. Otherwise, it is a loose list. void renderEscapedMarkdown(llvm::raw_ostream &OS) const override; void renderMarkdown(llvm::raw_ostream &OS) const override; void renderPlainText(llvm::raw_ostream &OS) const override; std::unique_ptr<Block> clone() const override;

class Document &addItem();

private: std::vector<class Document> Items; };

/ A format-agnostic representation for structured text. Allows rendering into / markdown and plaintext. class Document { public: Document() = default; Document(const Document &Other) { *this = Other; } Document &operator=(const Document &); Document(Document &&) = default; Document &operator=(Document &&) = default;

void append(Document Other);

/ Adds a semantical block that will be separate from others. Paragraph &addParagraph(); / Inserts a horizontal separator to the document. void addRuler(); / Adds a block of code. This translates to a ``` block in markdown. In plain text representation, the code block will be surrounded by newlines.

◆ addHeading()

Paragraph & clang::clangd::markup::Paragraph::addHeading ( size_t Level)

Heading is a special type of paragraph that will be prepended with Level many '#'s in markdown.

◆ appendBoldText()

Paragraph & Paragraph::appendBoldText ( llvm::StringRef Text)

Append bold text, this translates to the ** block in markdown.

Definition at line 710 of file Markup.cpp.

References clang::canonicalizeSpaces(), and clang::clangd::Text.

◆ appendEmphasizedText()

Paragraph & Paragraph::appendEmphasizedText ( llvm::StringRef Text)

Append emphasized text, this translates to the * block in markdown.

Definition at line 705 of file Markup.cpp.

References clang::canonicalizeSpaces(), and clang::clangd::Text.

◆ appendText()

Paragraph & Paragraph::appendText ( llvm::StringRef Text)

Append plain text to the end of the string.

Definition at line 696 of file Markup.cpp.

References clang::clangd::Text.

Referenced by clang::clangd::parseDocumentationParagraph().

◆ asEscapedMarkdown()

std::string clang::clangd::markup::Paragraph::asEscapedMarkdown ( ) const

Doesn't contain any trailing newlines and escaped markdown syntax.

It is expected that the result of this function is rendered as markdown.

◆ asMarkdown()

std::string clang::clangd::markup::Paragraph::asMarkdown ( ) const

Doesn't contain any trailing newlines.

It is expected that the result of this function is rendered as markdown.

◆ asPlainText()

std::string clang::clangd::markup::Paragraph::asPlainText ( ) const

Doesn't contain any trailing newlines.

◆ clone()

std::unique_ptr< Block > Paragraph::clone ( ) const
overridevirtual

Implements clang::clangd::markup::Block.

Definition at line 511 of file Markup.cpp.

◆ renderEscapedMarkdown()

void Paragraph::renderEscapedMarkdown ( llvm::raw_ostream & OS) const
overridevirtual

Implements clang::clangd::markup::Block.

Definition at line 453 of file Markup.cpp.

◆ renderMarkdown()

void Paragraph::renderMarkdown ( llvm::raw_ostream & OS) const
overridevirtual

Implements clang::clangd::markup::Block.

Definition at line 482 of file Markup.cpp.

◆ renderPlainText()

void Paragraph::renderPlainText ( llvm::raw_ostream & OS) const
overridevirtual

Implements clang::clangd::markup::Block.

Definition at line 562 of file Markup.cpp.

References clang::canonicalizeSpaces().


The documentation for this class was generated from the following files: