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

760 : m_t(t), m_relPath(relPath)
761{
762 //printf("%p:HtmlCodeGenerator()\n",(void*)this);
763}
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 754 of file htmlgen.cpp.

754 : m_t(t)
755{
756 //printf("%p:HtmlCodeGenerator()\n",(void*)this);
757}

References m_t.

Member Function Documentation

◆ _startOpenLine()

void HtmlCodeGenerator::_startOpenLine ( )
private

Definition at line 1117 of file htmlgen.cpp.

1118{
1119 //printf("_startOpenLine open=%d\n",m_lineOpen);
1120 *m_t << "<div class=\"line\">";
1121 bool wasHidden=m_hide;
1122 m_hide = false;
1123 m_lineOpen = true;
1125 m_lastLineInfo.fileName,
1126 m_lastLineInfo.anchor,
1127 m_lastLineInfo.line+1,
1128 m_lastLineInfo.writeAnchor);
1129 m_hide = wasHidden;
1130}
void writeLineNumber(const QCString &, const QCString &, const QCString &, int, bool) override
Definition htmlgen.cpp:877
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 925 of file htmlgen.cpp.

929{
930 m_col+=name.length();
931 if (m_hide) return;
932 if (!ref.isEmpty())
933 {
934 *m_t << "<a class=\"" << className << "Ref\" ";
936 }
937 else
938 {
939 *m_t << "<a class=\"" << className << "\" ";
940 }
941 *m_t << "href=\"";
942 QCString fn = f;
944 *m_t << createHtmlUrl(m_relPath,ref,true,
945 fileName()==fn,fn,anchor);
946 *m_t << "\"";
947 if (!tooltip.isEmpty()) *m_t << " title=\"" << convertToHtml(tooltip) << "\"";
948 *m_t << ">";
949 codify(name);
950 *m_t << "</a>";
951}
void codify(const QCString &text) override
Definition htmlgen.cpp:770
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:3884
QCString externalLinkTarget(const bool parent)
Definition util.cpp:5621
void addHtmlExtensionIfMissing(QCString &fName)
Definition util.cpp:4823
QCString createHtmlUrl(const QCString &relPath, const QCString &ref, bool href, bool isLocalFile, const QCString &targetFileName, const QCString &anchor)
Definition util.cpp:5632

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

771{
772 if (!str.isEmpty())
773 {
774 int tabSize = Config_getInt(TAB_SIZE);
775 const char *p=str.data();
776 if (m_hide) // only update column count
777 {
779 }
780 else // actually output content and keep track of m_col
781 {
782 while (*p)
783 {
784 char c=*p++;
785 switch(c)
786 {
787 case '\t': {
788 int spacesToNextTabStop = tabSize - (m_col%tabSize);
789 while (spacesToNextTabStop--)
790 {
791 if (m_col>=m_stripIndentAmount) *m_t << " ";
792 m_col++;
793 }
794 }
795 break;
796 case ' ': if (m_col>=m_stripIndentAmount) *m_t << " ";
797 m_col++;
798 break;
799 case '\n': *m_t << "\n"; m_col=0;
800 break;
801 case '\r': break;
802 case '<': *m_t << "&lt;"; m_col++;
803 break;
804 case '>': *m_t << "&gt;"; m_col++;
805 break;
806 case '&': *m_t << "&amp;"; m_col++;
807 break;
808 case '\'': *m_t << "&#39;"; m_col++; // &apos; is not valid XHTML
809 break;
810 case '"': *m_t << "&quot;"; m_col++;
811 break;
812 case '\\':
813 if (*p=='<')
814 { *m_t << "&lt;"; p++; }
815 else if (*p=='>')
816 { *m_t << "&gt;"; p++; }
817 else if (*p=='[')
818 { *m_t << "\\&zwj;["; m_col++;p++; }
819 else if (*p==']')
820 { *m_t << "\\&zwj;]"; m_col++;p++; }
821 else if (*p=='(')
822 { *m_t << "\\&zwj;("; m_col++;p++; }
823 else if (*p==')')
824 { *m_t << "\\&zwj;)"; m_col++;p++; }
825 else
826 *m_t << "\\";
827 m_col++;
828 break;
829 default:
830 {
831 uint8_t uc = static_cast<uint8_t>(c);
832 if (uc<32)
833 {
834 *m_t << "&#x24" << hex[uc>>4] << hex[uc&0xF] << ";";
835 m_col++;
836 }
837 else if (uc<0x80) // printable ASCII char
838 {
839 *m_t << c;
840 m_col++;
841 }
842 else // multibyte UTF-8 char
843 {
844 p=writeUTF8Char(*m_t,p-1);
845 m_col++;
846 }
847 }
848 break;
849 }
850 }
851 }
852 }
853}
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:6790

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

1085{
1086 //printf("endCodeFragment hide=%d open=%d\n",m_hide,m_lineOpen);
1087 bool wasHidden = m_hide;
1088 m_hide = false;
1089 //endCodeLine checks is there is still an open code line, if so closes it.
1090 endCodeLine();
1091 m_hide = wasHidden;
1092
1093 *m_t << "</div><!-- fragment -->";
1094}
void endCodeLine() override
Definition htmlgen.cpp:1045

References endCodeLine(), m_hide, and m_t.

◆ endCodeLine()

void HtmlCodeGenerator::endCodeLine ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1045 of file htmlgen.cpp.

1046{
1047 //printf("endCodeLine hide=%d open=%d\n",m_hide,m_lineOpen);
1048 if (m_hide) return;
1049 if (m_col == 0)
1050 {
1051 *m_t << " ";
1052 m_col++;
1053 }
1054 if (m_lineOpen)
1055 {
1056 *m_t << "</div>\n";
1057 m_lineOpen = FALSE;
1058 }
1059}
#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 1132 of file htmlgen.cpp.

1133{
1134 //printf("endFold open=%d\n",m_lineOpen);
1135 if (m_lineOpen) // if we have a hidden comment in a code fold, we need to end the line
1136 {
1137 *m_t << "</div>\n";
1138 }
1139 *m_t << "</div>\n";
1140 if (m_lineOpen)
1141 {
1143 }
1144}

References _startOpenLine(), m_lineOpen, and m_t.

◆ endFontClass()

void HtmlCodeGenerator::endFontClass ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1067 of file htmlgen.cpp.

1068{
1069 if (m_hide) return;
1070 *m_t << "</span>";
1071}

References m_hide, and m_t.

◆ endSpecialComment()

void HtmlCodeGenerator::endSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 866 of file htmlgen.cpp.

867{
868 //*m_t << "[END]";
869 m_hide = false;
870}

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

766{
767 m_relPath = path;
768}

References m_relPath.

◆ setStripIndentAmount()

void HtmlCodeGenerator::setStripIndentAmount ( size_t amount)
overridevirtual

Implements OutputCodeIntf.

Definition at line 872 of file htmlgen.cpp.

873{
874 m_stripIndentAmount = amount;
875}

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

1080{
1081 *m_t << "<div class=\"fragment\">";
1082}

References m_t.

◆ startCodeLine()

void HtmlCodeGenerator::startCodeLine ( int )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1033 of file htmlgen.cpp.

1034{
1035 //printf("startCodeLine open=%d\n",m_lineOpen);
1036 m_col=0;
1037 if (m_hide) return;
1038 if (!m_lineOpen)
1039 {
1040 *m_t << "<div class=\"line\">";
1041 m_lineOpen = TRUE;
1042 }
1043}
#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 1096 of file htmlgen.cpp.

1097{
1098 //printf("startFold open=%d\n",m_lineOpen);
1099 if (m_lineOpen) // if we have a hidden comment in a code fold, we need to end the line
1100 {
1101 *m_t << "</div>\n";
1102 }
1103 const int maxLineNrStr = 10;
1104 char lineNumber[maxLineNrStr];
1105 qsnprintf(lineNumber,maxLineNrStr,"%05d",lineNr);
1106 *m_t << "<div class=\"foldopen\" id=\"foldopen" << lineNumber <<
1107 "\" data-start=\"" << startMarker <<
1108 "\" data-end=\"" << endMarker <<
1109 "\">\n";
1110 if (m_lineOpen) // if we have a hidden comment in a code fold, we need to restart the line
1111 {
1112 *m_t << "<div class=\"line\">";
1113 }
1114 m_hide=false;
1115}
#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 1061 of file htmlgen.cpp.

1062{
1063 if (m_hide) return;
1064 *m_t << "<span class=\"" << s << "\">";
1065}

References m_hide, and m_t.

◆ startSpecialComment()

void HtmlCodeGenerator::startSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 860 of file htmlgen.cpp.

861{
863 //*m_t << "[START]";
864}
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 855 of file htmlgen.cpp.

856{
858}

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

1074{
1075 if (m_hide) return;
1076 *m_t << "<a id=\"" << anchor << "\" name=\"" << anchor << "\"></a>";
1077}

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

913{
914 if (m_hide) return;
915 const char *hl = codeSymbolType2Str(type);
916 QCString hlClass = "code";
917 if (hl)
918 {
919 hlClass+=" hl_";
920 hlClass+=hl;
921 }
922 _writeCodeLink(hlClass,ref,f,anchor,name,tooltip);
923}
void _writeCodeLink(const QCString &className, const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name, const QCString &tooltip)
Definition htmlgen.cpp:925
OutputType type() const override
Definition htmlgen.h:35
constexpr const char * codeSymbolType2Str(CodeSymbolType type)
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 877 of file htmlgen.cpp.

879{
880 m_lastLineInfo = LineInfo(ref,filename,anchor,l,writeLineAnchor);
881 if (m_hide) return;
882 const int maxLineNrStr = 10;
883 char lineNumber[maxLineNrStr];
884 char lineAnchor[maxLineNrStr];
885 qsnprintf(lineNumber,maxLineNrStr,"%5d",l);
886 qsnprintf(lineAnchor,maxLineNrStr,"l%05d",l);
887
888 //printf("writeLineNumber open=%d\n",m_lineOpen);
889 if (!m_lineOpen)
890 {
891 *m_t << "<div class=\"line\">";
893 }
894
895 if (writeLineAnchor) *m_t << "<a id=\"" << lineAnchor << "\" name=\"" << lineAnchor << "\"></a>";
896 *m_t << "<span class=\"lineno\">";
897 if (!filename.isEmpty())
898 {
899 _writeCodeLink("line",ref,filename,anchor,lineNumber,QCString());
900 }
901 else
902 {
903 codify(lineNumber);
904 }
905 *m_t << "</span>";
906 m_col=0;
907}

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

957{
958 if (m_hide) return;
959 *m_t << "<div class=\"ttc\" id=\"" << id << "\">";
960 *m_t << "<div class=\"ttname\">";
961 if (!docInfo.url.isEmpty())
962 {
963 *m_t << "<a href=\"";
964 QCString fn = docInfo.url;
966 *m_t << createHtmlUrl(m_relPath,docInfo.ref,true,
967 fileName()==fn,fn,docInfo.anchor);
968 *m_t << "\">";
969 }
970 codify(docInfo.name);
971 if (!docInfo.url.isEmpty())
972 {
973 *m_t << "</a>";
974 }
975 *m_t << "</div>";
976
977 if (!decl.isEmpty())
978 {
979 *m_t << "<div class=\"ttdeci\">";
980 codify(decl);
981 *m_t << "</div>";
982 }
983
984 if (!desc.isEmpty())
985 {
986 *m_t << "<div class=\"ttdoc\">";
987 codify(desc);
988 *m_t << "</div>";
989 }
990
991 if (!defInfo.file.isEmpty())
992 {
993 *m_t << "<div class=\"ttdef\"><b>" << theTranslator->trDefinition() << "</b> ";
994 if (!defInfo.url.isEmpty())
995 {
996 *m_t << "<a href=\"";
997 QCString fn = defInfo.url;
999 *m_t << createHtmlUrl(m_relPath,defInfo.ref,true,
1000 fileName()==fn,fn,defInfo.anchor);
1001 *m_t << "\">";
1002 }
1003 *m_t << defInfo.file << ":" << defInfo.line;
1004 if (!defInfo.url.isEmpty())
1005 {
1006 *m_t << "</a>";
1007 }
1008 *m_t << "</div>";
1009 }
1010 if (!declInfo.file.isEmpty())
1011 {
1012 *m_t << "<div class=\"ttdecl\"><b>" << theTranslator->trDeclaration() << "</b> ";
1013 if (!declInfo.url.isEmpty())
1014 {
1015 *m_t << "<a href=\"";
1016 QCString fn = declInfo.url;
1018 *m_t << createHtmlUrl(m_relPath,declInfo.ref,true,
1019 fileName()==fn,fn,declInfo.anchor);
1020 *m_t << "\">";
1021 }
1022 *m_t << declInfo.file << ":" << declInfo.line;
1023 if (!declInfo.url.isEmpty())
1024 {
1025 *m_t << "</a>";
1026 }
1027 *m_t << "</div>";
1028 }
1029 *m_t << "</div>\n";
1030}
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: