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

750 : m_t(t), m_relPath(relPath)
751{
752 //printf("%p:HtmlCodeGenerator()\n",(void*)this);
753}
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 744 of file htmlgen.cpp.

744 : m_t(t)
745{
746 //printf("%p:HtmlCodeGenerator()\n",(void*)this);
747}

References m_t.

Member Function Documentation

◆ _startOpenLine()

void HtmlCodeGenerator::_startOpenLine ( )
private

Definition at line 1107 of file htmlgen.cpp.

1108{
1109 //printf("_startOpenLine open=%d\n",m_lineOpen);
1110 *m_t << "<div class=\"line\">";
1111 bool wasHidden=m_hide;
1112 m_hide = false;
1113 m_lineOpen = true;
1115 m_lastLineInfo.fileName,
1116 m_lastLineInfo.anchor,
1117 m_lastLineInfo.line+1,
1118 m_lastLineInfo.writeAnchor);
1119 m_hide = wasHidden;
1120}
void writeLineNumber(const QCString &, const QCString &, const QCString &, int, bool) override
Definition htmlgen.cpp:867
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 915 of file htmlgen.cpp.

919{
920 m_col+=name.length();
921 if (m_hide) return;
922 if (!ref.isEmpty())
923 {
924 *m_t << "<a class=\"" << className << "Ref\" ";
926 }
927 else
928 {
929 *m_t << "<a class=\"" << className << "\" ";
930 }
931 *m_t << "href=\"";
932 QCString fn = f;
934 *m_t << createHtmlUrl(m_relPath,ref,true,
935 fileName()==fn,fn,anchor);
936 *m_t << "\"";
937 if (!tooltip.isEmpty()) *m_t << " title=\"" << convertToHtml(tooltip) << "\"";
938 *m_t << ">";
939 codify(name);
940 *m_t << "</a>";
941}
void codify(const QCString &text) override
Definition htmlgen.cpp:760
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:3905
QCString externalLinkTarget(const bool parent)
Definition util.cpp:5661
void addHtmlExtensionIfMissing(QCString &fName)
Definition util.cpp:4863
QCString createHtmlUrl(const QCString &relPath, const QCString &ref, bool href, bool isLocalFile, const QCString &targetFileName, const QCString &anchor)
Definition util.cpp:5672

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

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

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

1075{
1076 //printf("endCodeFragment hide=%d open=%d\n",m_hide,m_lineOpen);
1077 bool wasHidden = m_hide;
1078 m_hide = false;
1079 //endCodeLine checks is there is still an open code line, if so closes it.
1080 endCodeLine();
1081 m_hide = wasHidden;
1082
1083 *m_t << "</div><!-- fragment -->";
1084}
void endCodeLine() override
Definition htmlgen.cpp:1035

References endCodeLine(), m_hide, and m_t.

◆ endCodeLine()

void HtmlCodeGenerator::endCodeLine ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1035 of file htmlgen.cpp.

1036{
1037 //printf("endCodeLine hide=%d open=%d\n",m_hide,m_lineOpen);
1038 if (m_hide) return;
1039 if (m_col == 0)
1040 {
1041 *m_t << " ";
1042 m_col++;
1043 }
1044 if (m_lineOpen)
1045 {
1046 *m_t << "</div>\n";
1047 m_lineOpen = FALSE;
1048 }
1049}
#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 1122 of file htmlgen.cpp.

1123{
1124 //printf("endFold open=%d\n",m_lineOpen);
1125 if (m_lineOpen) // if we have a hidden comment in a code fold, we need to end the line
1126 {
1127 *m_t << "</div>\n";
1128 }
1129 *m_t << "</div>\n";
1130 if (m_lineOpen)
1131 {
1133 }
1134}

References _startOpenLine(), m_lineOpen, and m_t.

◆ endFontClass()

void HtmlCodeGenerator::endFontClass ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1057 of file htmlgen.cpp.

1058{
1059 if (m_hide) return;
1060 *m_t << "</span>";
1061}

References m_hide, and m_t.

◆ endSpecialComment()

void HtmlCodeGenerator::endSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 856 of file htmlgen.cpp.

857{
858 //*m_t << "[END]";
859 m_hide = false;
860}

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

756{
757 m_relPath = path;
758}

References m_relPath.

◆ setStripIndentAmount()

void HtmlCodeGenerator::setStripIndentAmount ( size_t amount)
overridevirtual

Implements OutputCodeIntf.

Definition at line 862 of file htmlgen.cpp.

863{
864 m_stripIndentAmount = amount;
865}

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

1070{
1071 *m_t << "<div class=\"fragment\">";
1072}

References m_t.

◆ startCodeLine()

void HtmlCodeGenerator::startCodeLine ( int )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1023 of file htmlgen.cpp.

1024{
1025 //printf("startCodeLine open=%d\n",m_lineOpen);
1026 m_col=0;
1027 if (m_hide) return;
1028 if (!m_lineOpen)
1029 {
1030 *m_t << "<div class=\"line\">";
1031 m_lineOpen = TRUE;
1032 }
1033}
#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 1086 of file htmlgen.cpp.

1087{
1088 //printf("startFold open=%d\n",m_lineOpen);
1089 if (m_lineOpen) // if we have a hidden comment in a code fold, we need to end the line
1090 {
1091 *m_t << "</div>\n";
1092 }
1093 const int maxLineNrStr = 10;
1094 char lineNumber[maxLineNrStr];
1095 qsnprintf(lineNumber,maxLineNrStr,"%05d",lineNr);
1096 *m_t << "<div class=\"foldopen\" id=\"foldopen" << lineNumber <<
1097 "\" data-start=\"" << startMarker <<
1098 "\" data-end=\"" << endMarker <<
1099 "\">\n";
1100 if (m_lineOpen) // if we have a hidden comment in a code fold, we need to restart the line
1101 {
1102 *m_t << "<div class=\"line\">";
1103 }
1104 m_hide=false;
1105}
#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 1051 of file htmlgen.cpp.

1052{
1053 if (m_hide) return;
1054 *m_t << "<span class=\"" << s << "\">";
1055}

References m_hide, and m_t.

◆ startSpecialComment()

void HtmlCodeGenerator::startSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 850 of file htmlgen.cpp.

851{
853 //*m_t << "[START]";
854}
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 845 of file htmlgen.cpp.

846{
848}

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

1064{
1065 if (m_hide) return;
1066 *m_t << "<a id=\"" << anchor << "\" name=\"" << anchor << "\"></a>";
1067}

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

903{
904 if (m_hide) return;
905 const char *hl = codeSymbolType2Str(type);
906 QCString hlClass = "code";
907 if (hl)
908 {
909 hlClass+=" hl_";
910 hlClass+=hl;
911 }
912 _writeCodeLink(hlClass,ref,f,anchor,name,tooltip);
913}
void _writeCodeLink(const QCString &className, const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name, const QCString &tooltip)
Definition htmlgen.cpp:915
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 867 of file htmlgen.cpp.

869{
870 m_lastLineInfo = LineInfo(ref,filename,anchor,l,writeLineAnchor);
871 if (m_hide) return;
872 const int maxLineNrStr = 10;
873 char lineNumber[maxLineNrStr];
874 char lineAnchor[maxLineNrStr];
875 qsnprintf(lineNumber,maxLineNrStr,"%5d",l);
876 qsnprintf(lineAnchor,maxLineNrStr,"l%05d",l);
877
878 //printf("writeLineNumber open=%d\n",m_lineOpen);
879 if (!m_lineOpen)
880 {
881 *m_t << "<div class=\"line\">";
883 }
884
885 if (writeLineAnchor) *m_t << "<a id=\"" << lineAnchor << "\" name=\"" << lineAnchor << "\"></a>";
886 *m_t << "<span class=\"lineno\">";
887 if (!filename.isEmpty())
888 {
889 _writeCodeLink("line",ref,filename,anchor,lineNumber,QCString());
890 }
891 else
892 {
893 codify(lineNumber);
894 }
895 *m_t << "</span>";
896 m_col=0;
897}

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

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