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

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 804 of file htmlgen.cpp.

805 : m_t(t), m_relPath(relPath)
806{
807 //printf("%p:HtmlCodeGenerator()\n",(void*)this);
808}
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 799 of file htmlgen.cpp.

799 : m_t(t)
800{
801 //printf("%p:HtmlCodeGenerator()\n",(void*)this);
802}

References m_t.

Member Function Documentation

◆ _startOpenLine()

void HtmlCodeGenerator::_startOpenLine ( )
private

Definition at line 1162 of file htmlgen.cpp.

1163{
1164 //printf("_startOpenLine open=%d\n",m_lineOpen);
1165 *m_t << "<div class=\"line\">";
1166 bool wasHidden=m_hide;
1167 m_hide = false;
1168 m_lineOpen = true;
1170 m_lastLineInfo.fileName,
1171 m_lastLineInfo.anchor,
1172 m_lastLineInfo.line+1,
1173 m_lastLineInfo.writeAnchor);
1174 m_hide = wasHidden;
1175}
void writeLineNumber(const QCString &, const QCString &, const QCString &, int, bool) override
Definition htmlgen.cpp:922
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 970 of file htmlgen.cpp.

974{
975 m_col+=name.length();
976 if (m_hide) return;
977 if (!ref.isEmpty())
978 {
979 *m_t << "<a class=\"" << className << "Ref\" ";
981 }
982 else
983 {
984 *m_t << "<a class=\"" << className << "\" ";
985 }
986 *m_t << "href=\"";
987 QCString fn = f;
989 *m_t << createHtmlUrl(m_relPath,ref,true,
990 fileName()==fn,fn,anchor);
991 *m_t << "\"";
992 if (!tooltip.isEmpty()) *m_t << " title=\"" << convertToHtml(tooltip) << "\"";
993 *m_t << ">";
994 codify(name);
995 *m_t << "</a>";
996}
void codify(const QCString &text) override
Definition htmlgen.cpp:815
QCString fileName()
Definition htmlgen.h:33
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:170
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:167
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 815 of file htmlgen.cpp.

816{
817 if (!str.isEmpty())
818 {
819 int tabSize = Config_getInt(TAB_SIZE);
820 const char *p=str.data();
821 if (m_hide) // only update column count
822 {
824 }
825 else // actually output content and keep track of m_col
826 {
827 while (*p)
828 {
829 char c=*p++;
830 switch(c)
831 {
832 case '\t': {
833 int spacesToNextTabStop = tabSize - (m_col%tabSize);
834 while (spacesToNextTabStop--)
835 {
836 if (m_col>=m_stripIndentAmount) *m_t << " ";
837 m_col++;
838 }
839 }
840 break;
841 case ' ': if (m_col>=m_stripIndentAmount) *m_t << " ";
842 m_col++;
843 break;
844 case '\n': *m_t << "\n"; m_col=0;
845 break;
846 case '\r': break;
847 case '<': *m_t << "&lt;"; m_col++;
848 break;
849 case '>': *m_t << "&gt;"; m_col++;
850 break;
851 case '&': *m_t << "&amp;"; m_col++;
852 break;
853 case '\'': *m_t << "&#39;"; m_col++; // &apos; is not valid XHTML
854 break;
855 case '"': *m_t << "&quot;"; m_col++;
856 break;
857 case '\\':
858 if (*p=='<')
859 { *m_t << "&lt;"; p++; }
860 else if (*p=='>')
861 { *m_t << "&gt;"; p++; }
862 else if (*p=='[')
863 { *m_t << "\\&zwj;["; m_col++;p++; }
864 else if (*p==']')
865 { *m_t << "\\&zwj;]"; m_col++;p++; }
866 else if (*p=='(')
867 { *m_t << "\\&zwj;("; m_col++;p++; }
868 else if (*p==')')
869 { *m_t << "\\&zwj;)"; m_col++;p++; }
870 else
871 *m_t << "\\";
872 m_col++;
873 break;
874 default:
875 {
876 uint8_t uc = static_cast<uint8_t>(c);
877 if (uc<32)
878 {
879 *m_t << "&#x24" << hex[uc>>4] << hex[uc&0xF] << ";";
880 m_col++;
881 }
882 else if (uc<0x80) // printable ASCII char
883 {
884 *m_t << c;
885 m_col++;
886 }
887 else // multibyte UTF-8 char
888 {
889 p=writeUTF8Char(*m_t,p-1);
890 m_col++;
891 }
892 }
893 break;
894 }
895 }
896 }
897 }
898}
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 1129 of file htmlgen.cpp.

1130{
1131 //printf("endCodeFragment hide=%d open=%d\n",m_hide,m_lineOpen);
1132 bool wasHidden = m_hide;
1133 m_hide = false;
1134 //endCodeLine checks is there is still an open code line, if so closes it.
1135 endCodeLine();
1136 m_hide = wasHidden;
1137
1138 *m_t << "</div><!-- fragment -->";
1139}
void endCodeLine() override
Definition htmlgen.cpp:1090

References endCodeLine(), m_hide, and m_t.

◆ endCodeLine()

void HtmlCodeGenerator::endCodeLine ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1090 of file htmlgen.cpp.

1091{
1092 //printf("endCodeLine hide=%d open=%d\n",m_hide,m_lineOpen);
1093 if (m_hide) return;
1094 if (m_col == 0)
1095 {
1096 *m_t << " ";
1097 m_col++;
1098 }
1099 if (m_lineOpen)
1100 {
1101 *m_t << "</div>\n";
1102 m_lineOpen = FALSE;
1103 }
1104}
#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 1177 of file htmlgen.cpp.

1178{
1179 //printf("endFold open=%d\n",m_lineOpen);
1180 if (m_lineOpen) // if we have a hidden comment in a code fold, we need to end the line
1181 {
1182 *m_t << "</div>\n";
1183 }
1184 *m_t << "</div>\n";
1185 if (m_lineOpen)
1186 {
1188 }
1189}

References _startOpenLine(), m_lineOpen, and m_t.

◆ endFontClass()

void HtmlCodeGenerator::endFontClass ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1112 of file htmlgen.cpp.

1113{
1114 if (m_hide) return;
1115 *m_t << "</span>";
1116}

References m_hide, and m_t.

◆ endSpecialComment()

void HtmlCodeGenerator::endSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 911 of file htmlgen.cpp.

912{
913 //*m_t << "[END]";
914 m_hide = false;
915}

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 810 of file htmlgen.cpp.

811{
812 m_relPath = path;
813}

References m_relPath.

◆ setStripIndentAmount()

void HtmlCodeGenerator::setStripIndentAmount ( size_t amount)
overridevirtual

Implements OutputCodeIntf.

Definition at line 917 of file htmlgen.cpp.

918{
919 m_stripIndentAmount = amount;
920}

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 1124 of file htmlgen.cpp.

1125{
1126 *m_t << "<div class=\"fragment\">";
1127}

References m_t.

◆ startCodeLine()

void HtmlCodeGenerator::startCodeLine ( int )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1078 of file htmlgen.cpp.

1079{
1080 //printf("startCodeLine open=%d\n",m_lineOpen);
1081 m_col=0;
1082 if (m_hide) return;
1083 if (!m_lineOpen)
1084 {
1085 *m_t << "<div class=\"line\">";
1086 m_lineOpen = TRUE;
1087 }
1088}
#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 1141 of file htmlgen.cpp.

1142{
1143 //printf("startFold open=%d\n",m_lineOpen);
1144 if (m_lineOpen) // if we have a hidden comment in a code fold, we need to end the line
1145 {
1146 *m_t << "</div>\n";
1147 }
1148 const int maxLineNrStr = 10;
1149 char lineNumber[maxLineNrStr];
1150 qsnprintf(lineNumber,maxLineNrStr,"%05d",lineNr);
1151 *m_t << "<div class=\"foldopen\" id=\"foldopen" << lineNumber <<
1152 "\" data-start=\"" << startMarker <<
1153 "\" data-end=\"" << endMarker <<
1154 "\">\n";
1155 if (m_lineOpen) // if we have a hidden comment in a code fold, we need to restart the line
1156 {
1157 *m_t << "<div class=\"line\">";
1158 }
1159 m_hide=false;
1160}
#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 1106 of file htmlgen.cpp.

1107{
1108 if (m_hide) return;
1109 *m_t << "<span class=\"" << s << "\">";
1110}

References m_hide, and m_t.

◆ startSpecialComment()

void HtmlCodeGenerator::startSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 905 of file htmlgen.cpp.

906{
908 //*m_t << "[START]";
909}
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 900 of file htmlgen.cpp.

901{
903}

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 1118 of file htmlgen.cpp.

1119{
1120 if (m_hide) return;
1121 *m_t << "<a id=\"" << anchor << "\" name=\"" << anchor << "\"></a>";
1122}

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 954 of file htmlgen.cpp.

958{
959 if (m_hide) return;
960 const char *hl = codeSymbolType2Str(type);
961 QCString hlClass = "code";
962 if (hl)
963 {
964 hlClass+=" hl_";
965 hlClass+=hl;
966 }
967 _writeCodeLink(hlClass,ref,f,anchor,name,tooltip);
968}
void _writeCodeLink(const QCString &className, const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name, const QCString &tooltip)
Definition htmlgen.cpp:970
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 922 of file htmlgen.cpp.

924{
925 m_lastLineInfo = LineInfo(ref,filename,anchor,l,writeLineAnchor);
926 if (m_hide) return;
927 const int maxLineNrStr = 10;
928 char lineNumber[maxLineNrStr];
929 char lineAnchor[maxLineNrStr];
930 qsnprintf(lineNumber,maxLineNrStr,"%5d",l);
931 qsnprintf(lineAnchor,maxLineNrStr,"l%05d",l);
932
933 //printf("writeLineNumber open=%d\n",m_lineOpen);
934 if (!m_lineOpen)
935 {
936 *m_t << "<div class=\"line\">";
938 }
939
940 if (writeLineAnchor) *m_t << "<a id=\"" << lineAnchor << "\" name=\"" << lineAnchor << "\"></a>";
941 *m_t << "<span class=\"lineno\">";
942 if (!filename.isEmpty())
943 {
944 _writeCodeLink("line",ref,filename,anchor,lineNumber,QCString());
945 }
946 else
947 {
948 codify(lineNumber);
949 }
950 *m_t << "</span>";
951 m_col=0;
952}

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 998 of file htmlgen.cpp.

1002{
1003 if (m_hide) return;
1004 *m_t << "<div class=\"ttc\" id=\"" << id << "\">";
1005 *m_t << "<div class=\"ttname\">";
1006 if (!docInfo.url.isEmpty())
1007 {
1008 *m_t << "<a href=\"";
1009 QCString fn = docInfo.url;
1011 *m_t << createHtmlUrl(m_relPath,docInfo.ref,true,
1012 fileName()==fn,fn,docInfo.anchor);
1013 *m_t << "\">";
1014 }
1015 codify(docInfo.name);
1016 if (!docInfo.url.isEmpty())
1017 {
1018 *m_t << "</a>";
1019 }
1020 *m_t << "</div>";
1021
1022 if (!decl.isEmpty())
1023 {
1024 *m_t << "<div class=\"ttdeci\">";
1025 codify(decl);
1026 *m_t << "</div>";
1027 }
1028
1029 if (!desc.isEmpty())
1030 {
1031 *m_t << "<div class=\"ttdoc\">";
1032 codify(desc);
1033 *m_t << "</div>";
1034 }
1035
1036 if (!defInfo.file.isEmpty())
1037 {
1038 *m_t << "<div class=\"ttdef\"><b>" << theTranslator->trDefinition() << "</b> ";
1039 if (!defInfo.url.isEmpty())
1040 {
1041 *m_t << "<a href=\"";
1042 QCString fn = defInfo.url;
1044 *m_t << createHtmlUrl(m_relPath,defInfo.ref,true,
1045 fileName()==fn,fn,defInfo.anchor);
1046 *m_t << "\">";
1047 }
1048 *m_t << defInfo.file << ":" << defInfo.line;
1049 if (!defInfo.url.isEmpty())
1050 {
1051 *m_t << "</a>";
1052 }
1053 *m_t << "</div>";
1054 }
1055 if (!declInfo.file.isEmpty())
1056 {
1057 *m_t << "<div class=\"ttdecl\"><b>" << theTranslator->trDeclaration() << "</b> ";
1058 if (!declInfo.url.isEmpty())
1059 {
1060 *m_t << "<a href=\"";
1061 QCString fn = declInfo.url;
1063 *m_t << createHtmlUrl(m_relPath,declInfo.ref,true,
1064 fileName()==fn,fn,declInfo.anchor);
1065 *m_t << "\">";
1066 }
1067 *m_t << declInfo.file << ":" << declInfo.line;
1068 if (!declInfo.url.isEmpty())
1069 {
1070 *m_t << "</a>";
1071 }
1072 *m_t << "</div>";
1073 }
1074 *m_t << "</div>\n";
1075}
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: