Doxygen
Loading...
Searching...
No Matches
HtmlCodeGenerator Class Reference

Generator for HTML code fragments. More...

#include <src/htmlgen.h>

Inheritance diagram for HtmlCodeGenerator:
Collaboration diagram for HtmlCodeGenerator:

Classes

struct  LineInfo

Public Member Functions

 HtmlCodeGenerator (TextStream *t, const QCString &relPath)
 HtmlCodeGenerator (TextStream *t)
void setTextStream (TextStream *t)
void setFileName (const QCString fileName)
QCString fileName ()
OutputType type () const override
std::unique_ptr< OutputCodeIntfclone () override
void codify (const QCString &text) override
void stripCodeComments (bool b) override
void startSpecialComment () override
void endSpecialComment () override
void setStripIndentAmount (size_t amount) override
void writeCodeLink (CodeSymbolType type, const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name, const QCString &tooltip) override
void writeTooltip (const QCString &id, const DocLinkInfo &docInfo, const QCString &decl, const QCString &desc, const SourceLinkInfo &defInfo, const SourceLinkInfo &declInfo) override
void writeLineNumber (const QCString &, const QCString &, const QCString &, int, bool) override
void startCodeLine (int) override
void endCodeLine () override
void startFontClass (const QCString &s) override
void endFontClass () override
void writeCodeAnchor (const QCString &anchor) override
void startCodeFragment (const QCString &style) override
void endCodeFragment (const QCString &) override
void startFold (int, const QCString &, const QCString &) override
void endFold () override
void setRelativePath (const QCString &path)
Public Member Functions inherited from OutputCodeIntf
 OutputCodeIntf ()=default

Private Member Functions

void _writeCodeLink (const QCString &className, const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name, const QCString &tooltip)
void _startOpenLine ()

Private Attributes

TextStreamm_t
size_t m_col = 0
QCString m_relPath
QCString m_fileName
bool m_lineOpen = false
bool m_stripCodeComments = false
bool m_hide = false
LineInfo m_lastLineInfo
size_t m_stripIndentAmount = 0

Detailed Description

Generator for HTML code fragments.

Definition at line 25 of file htmlgen.h.

Constructor & Destructor Documentation

◆ HtmlCodeGenerator() [1/2]

HtmlCodeGenerator::HtmlCodeGenerator ( TextStream * t,
const QCString & relPath )

Definition at line 825 of file htmlgen.cpp.

826 : m_t(t), m_relPath(relPath)
827{
828 //printf("%p:HtmlCodeGenerator()\n",(void*)this);
829}
QCString m_relPath
Definition htmlgen.h:74
TextStream * m_t
Definition htmlgen.h:72

References m_relPath, and m_t.

◆ HtmlCodeGenerator() [2/2]

HtmlCodeGenerator::HtmlCodeGenerator ( TextStream * t)

Definition at line 820 of file htmlgen.cpp.

820 : m_t(t)
821{
822 //printf("%p:HtmlCodeGenerator()\n",(void*)this);
823}

References m_t.

Member Function Documentation

◆ _startOpenLine()

void HtmlCodeGenerator::_startOpenLine ( )
private

Definition at line 1183 of file htmlgen.cpp.

1184{
1185 //printf("_startOpenLine open=%d\n",m_lineOpen);
1186 *m_t << "<div class=\"line\">";
1187 bool wasHidden=m_hide;
1188 m_hide = false;
1189 m_lineOpen = true;
1191 m_lastLineInfo.fileName,
1192 m_lastLineInfo.anchor,
1193 m_lastLineInfo.line+1,
1194 m_lastLineInfo.writeAnchor);
1195 m_hide = wasHidden;
1196}
void writeLineNumber(const QCString &, const QCString &, const QCString &, int, bool) override
Definition htmlgen.cpp:943
LineInfo m_lastLineInfo
Definition htmlgen.h:90

References m_hide, m_lastLineInfo, m_lineOpen, m_t, and writeLineNumber().

Referenced by endFold().

◆ _writeCodeLink()

void HtmlCodeGenerator::_writeCodeLink ( const QCString & className,
const QCString & ref,
const QCString & file,
const QCString & anchor,
const QCString & name,
const QCString & tooltip )
private

Definition at line 991 of file htmlgen.cpp.

995{
996 m_col+=name.length();
997 if (m_hide) return;
998 if (!ref.isEmpty())
999 {
1000 *m_t << "<a class=\"" << className << "Ref\" ";
1001 *m_t << externalLinkTarget();
1002 }
1003 else
1004 {
1005 *m_t << "<a class=\"" << className << "\" ";
1006 }
1007 *m_t << "href=\"";
1008 QCString fn = f;
1010 *m_t << createHtmlUrl(m_relPath,ref,true,
1011 fileName()==fn,fn,anchor);
1012 *m_t << "\"";
1013 if (!tooltip.isEmpty()) *m_t << " title=\"" << convertToHtml(tooltip) << "\"";
1014 *m_t << ">";
1015 codify(name);
1016 *m_t << "</a>";
1017}
void codify(const QCString &text) override
Definition htmlgen.cpp:836
QCString fileName()
Definition htmlgen.h:33
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:166
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
QCString convertToHtml(const QCString &s, bool keepEntities)
Definition util.cpp:3984
QCString externalLinkTarget(const bool parent)
Definition util.cpp:5745
void addHtmlExtensionIfMissing(QCString &fName)
Definition util.cpp:4942
QCString createHtmlUrl(const QCString &relPath, const QCString &ref, bool href, bool isLocalFile, const QCString &targetFileName, const QCString &anchor)
Definition util.cpp:5756

References addHtmlExtensionIfMissing(), codify(), convertToHtml(), createHtmlUrl(), externalLinkTarget(), fileName(), QCString::isEmpty(), QCString::length(), m_col, m_hide, m_relPath, and m_t.

Referenced by writeCodeLink(), and writeLineNumber().

◆ clone()

std::unique_ptr< OutputCodeIntf > HtmlCodeGenerator::clone ( )
inlineoverridevirtual

Implements OutputCodeIntf.

Definition at line 36 of file htmlgen.h.

36{ return std::make_unique<HtmlCodeGenerator>(*this); }

◆ codify()

void HtmlCodeGenerator::codify ( const QCString & text)
overridevirtual

Implements OutputCodeIntf.

Definition at line 836 of file htmlgen.cpp.

837{
838 if (!str.isEmpty())
839 {
840 int tabSize = Config_getInt(TAB_SIZE);
841 const char *p=str.data();
842 if (m_hide) // only update column count
843 {
845 }
846 else // actually output content and keep track of m_col
847 {
848 while (*p)
849 {
850 char c=*p++;
851 switch(c)
852 {
853 case '\t': {
854 int spacesToNextTabStop = tabSize - (m_col%tabSize);
855 while (spacesToNextTabStop--)
856 {
857 if (m_col>=m_stripIndentAmount) *m_t << " ";
858 m_col++;
859 }
860 }
861 break;
862 case ' ': if (m_col>=m_stripIndentAmount) *m_t << " ";
863 m_col++;
864 break;
865 case '\n': *m_t << "\n"; m_col=0;
866 break;
867 case '\r': break;
868 case '<': *m_t << "&lt;"; m_col++;
869 break;
870 case '>': *m_t << "&gt;"; m_col++;
871 break;
872 case '&': *m_t << "&amp;"; m_col++;
873 break;
874 case '\'': *m_t << "&#39;"; m_col++; // &apos; is not valid XHTML
875 break;
876 case '"': *m_t << "&quot;"; m_col++;
877 break;
878 case '\\':
879 if (*p=='<')
880 { *m_t << "&lt;"; p++; }
881 else if (*p=='>')
882 { *m_t << "&gt;"; p++; }
883 else if (*p=='[')
884 { *m_t << "\\&zwj;["; m_col++;p++; }
885 else if (*p==']')
886 { *m_t << "\\&zwj;]"; m_col++;p++; }
887 else if (*p=='(')
888 { *m_t << "\\&zwj;("; m_col++;p++; }
889 else if (*p==')')
890 { *m_t << "\\&zwj;)"; m_col++;p++; }
891 else
892 *m_t << "\\";
893 m_col++;
894 break;
895 default:
896 {
897 uint8_t uc = static_cast<uint8_t>(c);
898 if (uc<32)
899 {
900 *m_t << "&#x24" << hex[uc>>4] << hex[uc&0xF] << ";";
901 m_col++;
902 }
903 else if (uc<0x80) // printable ASCII char
904 {
905 *m_t << c;
906 m_col++;
907 }
908 else // multibyte UTF-8 char
909 {
910 p=writeUTF8Char(*m_t,p-1);
911 m_col++;
912 }
913 }
914 break;
915 }
916 }
917 }
918 }
919}
size_t m_stripIndentAmount
Definition htmlgen.h:91
#define Config_getInt(name)
Definition config.h:34
static constexpr auto hex
const char * writeUTF8Char(TextStream &t, const char *s)
Writes the UTF8 character pointed to by s to stream t and returns a pointer to the next character.
Definition utf8.cpp:197
size_t updateColumnCount(const char *s, size_t col)
Definition util.cpp:6898

References Config_getInt, QCString::data(), hex, QCString::isEmpty(), m_col, m_hide, m_stripIndentAmount, m_t, updateColumnCount(), and writeUTF8Char().

Referenced by _writeCodeLink(), writeLineNumber(), and writeTooltip().

◆ endCodeFragment()

void HtmlCodeGenerator::endCodeFragment ( const QCString & )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1150 of file htmlgen.cpp.

1151{
1152 //printf("endCodeFragment hide=%d open=%d\n",m_hide,m_lineOpen);
1153 bool wasHidden = m_hide;
1154 m_hide = false;
1155 //endCodeLine checks is there is still an open code line, if so closes it.
1156 endCodeLine();
1157 m_hide = wasHidden;
1158
1159 *m_t << "</div><!-- fragment -->";
1160}
void endCodeLine() override
Definition htmlgen.cpp:1111

References endCodeLine(), m_hide, and m_t.

◆ endCodeLine()

void HtmlCodeGenerator::endCodeLine ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1111 of file htmlgen.cpp.

1112{
1113 //printf("endCodeLine hide=%d open=%d\n",m_hide,m_lineOpen);
1114 if (m_hide) return;
1115 if (m_col == 0)
1116 {
1117 *m_t << " ";
1118 m_col++;
1119 }
1120 if (m_lineOpen)
1121 {
1122 *m_t << "</div>\n";
1123 m_lineOpen = FALSE;
1124 }
1125}
#define FALSE
Definition qcstring.h:34

References FALSE, m_col, m_hide, m_lineOpen, and m_t.

Referenced by endCodeFragment().

◆ endFold()

void HtmlCodeGenerator::endFold ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1198 of file htmlgen.cpp.

1199{
1200 //printf("endFold open=%d\n",m_lineOpen);
1201 if (m_lineOpen) // if we have a hidden comment in a code fold, we need to end the line
1202 {
1203 *m_t << "</div>\n";
1204 }
1205 *m_t << "</div>\n";
1206 if (m_lineOpen)
1207 {
1209 }
1210}

References _startOpenLine(), m_lineOpen, and m_t.

◆ endFontClass()

void HtmlCodeGenerator::endFontClass ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1133 of file htmlgen.cpp.

1134{
1135 if (m_hide) return;
1136 *m_t << "</span>";
1137}

References m_hide, and m_t.

◆ endSpecialComment()

void HtmlCodeGenerator::endSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 932 of file htmlgen.cpp.

933{
934 //*m_t << "[END]";
935 m_hide = false;
936}

References m_hide.

◆ fileName()

QCString HtmlCodeGenerator::fileName ( )
inline

Definition at line 33 of file htmlgen.h.

33{ return m_fileName; }
QCString m_fileName
Definition htmlgen.h:75

References m_fileName.

Referenced by _writeCodeLink(), setFileName(), and writeTooltip().

◆ setFileName()

void HtmlCodeGenerator::setFileName ( const QCString fileName)
inline

Definition at line 32 of file htmlgen.h.

References fileName(), and m_fileName.

◆ setRelativePath()

void HtmlCodeGenerator::setRelativePath ( const QCString & path)

Definition at line 831 of file htmlgen.cpp.

832{
833 m_relPath = path;
834}

References m_relPath.

◆ setStripIndentAmount()

void HtmlCodeGenerator::setStripIndentAmount ( size_t amount)
overridevirtual

Implements OutputCodeIntf.

Definition at line 938 of file htmlgen.cpp.

939{
940 m_stripIndentAmount = amount;
941}

References m_stripIndentAmount.

◆ setTextStream()

void HtmlCodeGenerator::setTextStream ( TextStream * t)
inline

Definition at line 31 of file htmlgen.h.

31{ m_t = t; }

References m_t.

◆ startCodeFragment()

void HtmlCodeGenerator::startCodeFragment ( const QCString & style)
overridevirtual

Implements OutputCodeIntf.

Definition at line 1145 of file htmlgen.cpp.

1146{
1147 *m_t << "<div class=\"fragment\">";
1148}

References m_t.

◆ startCodeLine()

void HtmlCodeGenerator::startCodeLine ( int )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1099 of file htmlgen.cpp.

1100{
1101 //printf("startCodeLine open=%d\n",m_lineOpen);
1102 m_col=0;
1103 if (m_hide) return;
1104 if (!m_lineOpen)
1105 {
1106 *m_t << "<div class=\"line\">";
1107 m_lineOpen = TRUE;
1108 }
1109}
#define TRUE
Definition qcstring.h:37

References m_col, m_hide, m_lineOpen, m_t, and TRUE.

◆ startFold()

void HtmlCodeGenerator::startFold ( int lineNr,
const QCString & startMarker,
const QCString & endMarker )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1162 of file htmlgen.cpp.

1163{
1164 //printf("startFold open=%d\n",m_lineOpen);
1165 if (m_lineOpen) // if we have a hidden comment in a code fold, we need to end the line
1166 {
1167 *m_t << "</div>\n";
1168 }
1169 const int maxLineNrStr = 10;
1170 char lineNumber[maxLineNrStr];
1171 qsnprintf(lineNumber,maxLineNrStr,"%05d",lineNr);
1172 *m_t << "<div class=\"foldopen\" id=\"foldopen" << lineNumber <<
1173 "\" data-start=\"" << startMarker <<
1174 "\" data-end=\"" << endMarker <<
1175 "\">\n";
1176 if (m_lineOpen) // if we have a hidden comment in a code fold, we need to restart the line
1177 {
1178 *m_t << "<div class=\"line\">";
1179 }
1180 m_hide=false;
1181}
#define qsnprintf
Definition qcstring.h:49

References m_hide, m_lineOpen, m_t, and qsnprintf.

◆ startFontClass()

void HtmlCodeGenerator::startFontClass ( const QCString & s)
overridevirtual

Implements OutputCodeIntf.

Definition at line 1127 of file htmlgen.cpp.

1128{
1129 if (m_hide) return;
1130 *m_t << "<span class=\"" << s << "\">";
1131}

References m_hide, and m_t.

◆ startSpecialComment()

void HtmlCodeGenerator::startSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 926 of file htmlgen.cpp.

927{
929 //*m_t << "[START]";
930}
bool m_stripCodeComments
Definition htmlgen.h:77

References m_hide, and m_stripCodeComments.

◆ stripCodeComments()

void HtmlCodeGenerator::stripCodeComments ( bool b)
overridevirtual

Implements OutputCodeIntf.

Definition at line 921 of file htmlgen.cpp.

922{
924}

References m_stripCodeComments.

◆ type()

OutputType HtmlCodeGenerator::type ( ) const
inlineoverridevirtual

Implements OutputCodeIntf.

Definition at line 35 of file htmlgen.h.

35{ return OutputType::Html; }

References Html.

Referenced by writeCodeLink().

◆ writeCodeAnchor()

void HtmlCodeGenerator::writeCodeAnchor ( const QCString & anchor)
overridevirtual

Implements OutputCodeIntf.

Definition at line 1139 of file htmlgen.cpp.

1140{
1141 if (m_hide) return;
1142 *m_t << "<a id=\"" << anchor << "\" name=\"" << anchor << "\"></a>";
1143}

References m_hide, and m_t.

◆ writeCodeLink()

void HtmlCodeGenerator::writeCodeLink ( CodeSymbolType type,
const QCString & ref,
const QCString & file,
const QCString & anchor,
const QCString & name,
const QCString & tooltip )
overridevirtual

Implements OutputCodeIntf.

Definition at line 975 of file htmlgen.cpp.

979{
980 if (m_hide) return;
981 const char *hl = codeSymbolType2Str(type);
982 QCString hlClass = "code";
983 if (hl)
984 {
985 hlClass+=" hl_";
986 hlClass+=hl;
987 }
988 _writeCodeLink(hlClass,ref,f,anchor,name,tooltip);
989}
void _writeCodeLink(const QCString &className, const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name, const QCString &tooltip)
Definition htmlgen.cpp:991
OutputType type() const override
Definition htmlgen.h:35
constexpr const char * codeSymbolType2Str(CodeSymbolType type) noexcept
Definition types.h:515

References _writeCodeLink(), codeSymbolType2Str(), m_hide, and type().

◆ writeLineNumber()

void HtmlCodeGenerator::writeLineNumber ( const QCString & ref,
const QCString & filename,
const QCString & anchor,
int l,
bool writeLineAnchor )
overridevirtual

Implements OutputCodeIntf.

Definition at line 943 of file htmlgen.cpp.

945{
946 m_lastLineInfo = LineInfo(ref,filename,anchor,l,writeLineAnchor);
947 if (m_hide) return;
948 const int maxLineNrStr = 10;
949 char lineNumber[maxLineNrStr];
950 char lineAnchor[maxLineNrStr];
951 qsnprintf(lineNumber,maxLineNrStr,"%5d",l);
952 qsnprintf(lineAnchor,maxLineNrStr,"l%05d",l);
953
954 //printf("writeLineNumber open=%d\n",m_lineOpen);
955 if (!m_lineOpen)
956 {
957 *m_t << "<div class=\"line\">";
959 }
960
961 if (writeLineAnchor) *m_t << "<a id=\"" << lineAnchor << "\" name=\"" << lineAnchor << "\"></a>";
962 *m_t << "<span class=\"lineno\">";
963 if (!filename.isEmpty())
964 {
965 _writeCodeLink("line",ref,filename,anchor,lineNumber,QCString());
966 }
967 else
968 {
969 codify(lineNumber);
970 }
971 *m_t << "</span>";
972 m_col=0;
973}

References _writeCodeLink(), codify(), QCString::isEmpty(), m_col, m_hide, m_lastLineInfo, m_lineOpen, m_t, qsnprintf, and TRUE.

Referenced by _startOpenLine().

◆ writeTooltip()

void HtmlCodeGenerator::writeTooltip ( const QCString & id,
const DocLinkInfo & docInfo,
const QCString & decl,
const QCString & desc,
const SourceLinkInfo & defInfo,
const SourceLinkInfo & declInfo )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1019 of file htmlgen.cpp.

1023{
1024 if (m_hide) return;
1025 *m_t << "<div class=\"ttc\" id=\"" << id << "\">";
1026 *m_t << "<div class=\"ttname\">";
1027 if (!docInfo.url.isEmpty())
1028 {
1029 *m_t << "<a href=\"";
1030 QCString fn = docInfo.url;
1032 *m_t << createHtmlUrl(m_relPath,docInfo.ref,true,
1033 fileName()==fn,fn,docInfo.anchor);
1034 *m_t << "\">";
1035 }
1036 codify(docInfo.name);
1037 if (!docInfo.url.isEmpty())
1038 {
1039 *m_t << "</a>";
1040 }
1041 *m_t << "</div>";
1042
1043 if (!decl.isEmpty())
1044 {
1045 *m_t << "<div class=\"ttdeci\">";
1046 codify(decl);
1047 *m_t << "</div>";
1048 }
1049
1050 if (!desc.isEmpty())
1051 {
1052 *m_t << "<div class=\"ttdoc\">";
1053 codify(desc);
1054 *m_t << "</div>";
1055 }
1056
1057 if (!defInfo.file.isEmpty())
1058 {
1059 *m_t << "<div class=\"ttdef\"><b>" << theTranslator->trDefinition() << "</b> ";
1060 if (!defInfo.url.isEmpty())
1061 {
1062 *m_t << "<a href=\"";
1063 QCString fn = defInfo.url;
1065 *m_t << createHtmlUrl(m_relPath,defInfo.ref,true,
1066 fileName()==fn,fn,defInfo.anchor);
1067 *m_t << "\">";
1068 }
1069 *m_t << defInfo.file << ":" << defInfo.line;
1070 if (!defInfo.url.isEmpty())
1071 {
1072 *m_t << "</a>";
1073 }
1074 *m_t << "</div>";
1075 }
1076 if (!declInfo.file.isEmpty())
1077 {
1078 *m_t << "<div class=\"ttdecl\"><b>" << theTranslator->trDeclaration() << "</b> ";
1079 if (!declInfo.url.isEmpty())
1080 {
1081 *m_t << "<a href=\"";
1082 QCString fn = declInfo.url;
1084 *m_t << createHtmlUrl(m_relPath,declInfo.ref,true,
1085 fileName()==fn,fn,declInfo.anchor);
1086 *m_t << "\">";
1087 }
1088 *m_t << declInfo.file << ":" << declInfo.line;
1089 if (!declInfo.url.isEmpty())
1090 {
1091 *m_t << "</a>";
1092 }
1093 *m_t << "</div>";
1094 }
1095 *m_t << "</div>\n";
1096}
virtual QCString trDeclaration()=0
virtual QCString trDefinition()=0
Translator * theTranslator
Definition language.cpp:71

References addHtmlExtensionIfMissing(), DocLinkInfo::anchor, SourceLinkInfo::anchor, codify(), createHtmlUrl(), SourceLinkInfo::file, fileName(), QCString::isEmpty(), SourceLinkInfo::line, m_hide, m_relPath, m_t, DocLinkInfo::name, DocLinkInfo::ref, SourceLinkInfo::ref, theTranslator, DocLinkInfo::url, and SourceLinkInfo::url.

Member Data Documentation

◆ m_col

size_t HtmlCodeGenerator::m_col = 0
private

Definition at line 73 of file htmlgen.h.

Referenced by _writeCodeLink(), codify(), endCodeLine(), startCodeLine(), and writeLineNumber().

◆ m_fileName

QCString HtmlCodeGenerator::m_fileName
private

Definition at line 75 of file htmlgen.h.

Referenced by fileName(), and setFileName().

◆ m_hide

◆ m_lastLineInfo

LineInfo HtmlCodeGenerator::m_lastLineInfo
private

Definition at line 90 of file htmlgen.h.

Referenced by _startOpenLine(), and writeLineNumber().

◆ m_lineOpen

bool HtmlCodeGenerator::m_lineOpen = false
private

◆ m_relPath

QCString HtmlCodeGenerator::m_relPath
private

Definition at line 74 of file htmlgen.h.

Referenced by _writeCodeLink(), HtmlCodeGenerator(), setRelativePath(), and writeTooltip().

◆ m_stripCodeComments

bool HtmlCodeGenerator::m_stripCodeComments = false
private

Definition at line 77 of file htmlgen.h.

Referenced by startSpecialComment(), and stripCodeComments().

◆ m_stripIndentAmount

size_t HtmlCodeGenerator::m_stripIndentAmount = 0
private

Definition at line 91 of file htmlgen.h.

Referenced by codify(), and setStripIndentAmount().

◆ m_t


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