clang 19.0.0git
Classes | Typedefs | Functions
clang::html Namespace Reference

Classes

struct  RelexRewriteCache
 

Typedefs

using RelexRewriteCacheRef = std::shared_ptr< RelexRewriteCache >
 

Functions

RelexRewriteCacheRef instantiateRelexRewriteCache ()
 If you need to rewrite the same file multiple times, you can instantiate a RelexRewriteCache and refer functions such as SyntaxHighlight() and HighlightMacros() to it so that to avoid re-lexing the file each time.
 
void HighlightRange (Rewriter &R, SourceLocation B, SourceLocation E, const char *StartTag, const char *EndTag, bool IsTokenRange=true)
 HighlightRange - Highlight a range in the source code with the specified start/end tags.
 
void HighlightRange (Rewriter &R, SourceRange Range, const char *StartTag, const char *EndTag)
 HighlightRange - Highlight a range in the source code with the specified start/end tags.
 
void HighlightRange (RewriteBuffer &RB, unsigned B, unsigned E, const char *BufferStart, const char *StartTag, const char *EndTag)
 HighlightRange - This is the same as the above method, but takes decomposed file locations.
 
void EscapeText (Rewriter &R, FileID FID, bool EscapeSpaces=false, bool ReplaceTabs=false)
 EscapeText - HTMLize a specified file so that special characters are are translated so that they are not interpreted as HTML tags.
 
std::string EscapeText (StringRef s, bool EscapeSpaces=false, bool ReplaceTabs=false)
 EscapeText - HTMLized the provided string so that special characters in 's' are not interpreted as HTML tags.
 
void AddLineNumbers (Rewriter &R, FileID FID)
 
void AddHeaderFooterInternalBuiltinCSS (Rewriter &R, FileID FID, StringRef title)
 
void SyntaxHighlight (Rewriter &R, FileID FID, const Preprocessor &PP, RelexRewriteCacheRef Cache=nullptr)
 SyntaxHighlight - Relex the specified FileID and annotate the HTML with information about keywords, comments, etc.
 
void HighlightMacros (Rewriter &R, FileID FID, const Preprocessor &PP, RelexRewriteCacheRef Cache=nullptr)
 HighlightMacros - This uses the macro table state from the end of the file, to reexpand macros and insert (into the HTML) information about the macro expansions.
 

Typedef Documentation

◆ RelexRewriteCacheRef

using clang::html::RelexRewriteCacheRef = typedef std::shared_ptr<RelexRewriteCache>

Definition at line 28 of file HTMLRewrite.h.

Function Documentation

◆ AddHeaderFooterInternalBuiltinCSS()

void clang::html::AddHeaderFooterInternalBuiltinCSS ( Rewriter R,
FileID  FID,
StringRef  title 
)

◆ AddLineNumbers()

void clang::html::AddLineNumbers ( Rewriter R,
FileID  FID 
)

◆ EscapeText() [1/2]

void clang::html::EscapeText ( Rewriter R,
FileID  FID,
bool  EscapeSpaces = false,
bool  ReplaceTabs = false 
)

EscapeText - HTMLize a specified file so that special characters are are translated so that they are not interpreted as HTML tags.

Definition at line 135 of file HTMLRewrite.cpp.

References clang::C, clang::SourceManager::getBufferOrFake(), clang::Rewriter::getEditBuffer(), clang::Rewriter::getSourceMgr(), and clang::RewriteBuffer::ReplaceText().

Referenced by AddHeaderFooterInternalBuiltinCSS().

◆ EscapeText() [2/2]

std::string clang::html::EscapeText ( StringRef  s,
bool  EscapeSpaces = false,
bool  ReplaceTabs = false 
)

EscapeText - HTMLized the provided string so that special characters in 's' are not interpreted as HTML tags.

Unlike the version of EscapeText that rewrites a file, this version by default replaces tabs with spaces.

Definition at line 196 of file HTMLRewrite.cpp.

References c, and s.

◆ HighlightMacros()

void clang::html::HighlightMacros ( Rewriter R,
FileID  FID,
const Preprocessor PP,
RelexRewriteCacheRef  Cache = nullptr 
)

HighlightMacros - This uses the macro table state from the end of the file, to reexpand macros and insert (into the HTML) information about the macro expansions.

HighlightMacros - This uses the macro table state from the end of the file, to re-expand macros and insert (into the HTML) information about the macro expansions.

This won't be perfectly perfect, but it will be reasonably close.

Definition at line 600 of file HTMLRewrite.cpp.

◆ HighlightRange() [1/3]

void clang::html::HighlightRange ( RewriteBuffer RB,
unsigned  B,
unsigned  E,
const char *  BufferStart,
const char *  StartTag,
const char *  EndTag 
)

HighlightRange - This is the same as the above method, but takes decomposed file locations.

Definition at line 60 of file HTMLRewrite.cpp.

References E, clang::RewriteBuffer::InsertTextAfter(), and clang::RewriteBuffer::InsertTextBefore().

◆ HighlightRange() [2/3]

void clang::html::HighlightRange ( Rewriter R,
SourceLocation  B,
SourceLocation  E,
const char *  StartTag,
const char *  EndTag,
bool  IsTokenRange = true 
)

HighlightRange - Highlight a range in the source code with the specified start/end tags.

B/E must be in the same file. This ensures that start/end tags are placed at the start/end of each line if the range is multiline.

Definition at line 33 of file HTMLRewrite.cpp.

References E, clang::Rewriter::getEditBuffer(), clang::Rewriter::getLangOpts(), clang::Rewriter::getSourceMgr(), HighlightRange(), clang::Invalid, clang::Lexer::MeasureTokenLength(), and SM.

Referenced by HighlightRange().

◆ HighlightRange() [3/3]

void clang::html::HighlightRange ( Rewriter R,
SourceRange  Range,
const char *  StartTag,
const char *  EndTag 
)
inline

HighlightRange - Highlight a range in the source code with the specified start/end tags.

The Start/end of the range must be in the same file. This ensures that start/end tags are placed at the start/end of each line if the range is multiline.

Definition at line 49 of file HTMLRewrite.h.

References HighlightRange(), and Range.

◆ instantiateRelexRewriteCache()

html::RelexRewriteCacheRef clang::html::instantiateRelexRewriteCache ( )

If you need to rewrite the same file multiple times, you can instantiate a RelexRewriteCache and refer functions such as SyntaxHighlight() and HighlightMacros() to it so that to avoid re-lexing the file each time.

The cache may outlive the rewriter as long as cached FileIDs and source locations continue to make sense for the translation unit as a whole.

Definition at line 131 of file HTMLRewrite.cpp.

◆ SyntaxHighlight()

void clang::html::SyntaxHighlight ( Rewriter R,
FileID  FID,
const Preprocessor PP,
RelexRewriteCacheRef  Cache = nullptr 
)

SyntaxHighlight - Relex the specified FileID and annotate the HTML with information about keywords, comments, etc.

Definition at line 423 of file HTMLRewrite.cpp.