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

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

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

References m_t.

Member Function Documentation

◆ _startOpenLine()

void HtmlCodeGenerator::_startOpenLine ( )
private

Definition at line 1161 of file htmlgen.cpp.

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

973{
974 m_col+=name.length();
975 if (m_hide) return;
976 if (!ref.isEmpty())
977 {
978 *m_t << "<a class=\"" << className << "Ref\" ";
980 }
981 else
982 {
983 *m_t << "<a class=\"" << className << "\" ";
984 }
985 *m_t << "href=\"";
986 QCString fn = f;
988 *m_t << createHtmlUrl(m_relPath,ref,true,
989 fileName()==fn,fn,anchor);
990 *m_t << "\"";
991 if (!tooltip.isEmpty()) *m_t << " title=\"" << convertToHtml(tooltip) << "\"";
992 *m_t << ">";
993 codify(name);
994 *m_t << "</a>";
995}
void codify(const QCString &text) override
Definition htmlgen.cpp:814
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 814 of file htmlgen.cpp.

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

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

References endCodeLine(), m_hide, and m_t.

◆ endCodeLine()

void HtmlCodeGenerator::endCodeLine ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1089 of file htmlgen.cpp.

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

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

References _startOpenLine(), m_lineOpen, and m_t.

◆ endFontClass()

void HtmlCodeGenerator::endFontClass ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1111 of file htmlgen.cpp.

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

References m_hide, and m_t.

◆ endSpecialComment()

void HtmlCodeGenerator::endSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 910 of file htmlgen.cpp.

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

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

810{
811 m_relPath = path;
812}

References m_relPath.

◆ setStripIndentAmount()

void HtmlCodeGenerator::setStripIndentAmount ( size_t amount)
overridevirtual

Implements OutputCodeIntf.

Definition at line 916 of file htmlgen.cpp.

917{
918 m_stripIndentAmount = amount;
919}

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

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

References m_t.

◆ startCodeLine()

void HtmlCodeGenerator::startCodeLine ( int )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1077 of file htmlgen.cpp.

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

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

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

References m_hide, and m_t.

◆ startSpecialComment()

void HtmlCodeGenerator::startSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 904 of file htmlgen.cpp.

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

900{
902}

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

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

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

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

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

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

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