Skip to main content

The HtmlCodeGenerator Class Reference

Generator for HTML code fragments. More...

Declaration

class HtmlCodeGenerator { ... }

Included Headers

#include <src/htmlgen.h>

Base class

classOutputCodeIntf

Base class for code generators. More...

Public Constructors Index

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

Public Member Functions Index

voidsetTextStream (TextStream *t)
voidsetFileName (const QCString fileName)
QCStringfileName ()
OutputTypetype () const override
std::unique_ptr< OutputCodeIntf >clone () override
voidcodify (const QCString &text) override
voidstripCodeComments (bool b) override
voidstartSpecialComment () override
voidendSpecialComment () override
voidsetStripIndentAmount (size_t amount) override
voidwriteCodeLink (CodeSymbolType type, const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name, const QCString &tooltip) override
voidwriteTooltip (const QCString &id, const DocLinkInfo &docInfo, const QCString &decl, const QCString &desc, const SourceLinkInfo &defInfo, const SourceLinkInfo &declInfo) override
voidwriteLineNumber (const QCString &, const QCString &, const QCString &, int, bool) override
voidstartCodeLine (int) override
voidendCodeLine () override
voidstartFontClass (const QCString &s) override
voidendFontClass () override
voidwriteCodeAnchor (const QCString &anchor) override
voidstartCodeFragment (const QCString &style) override
voidendCodeFragment (const QCString &) override
voidstartFold (int, const QCString &, const QCString &) override
voidendFold () override
voidsetRelativePath (const QCString &path)

Private Member Functions Index

void_writeCodeLink (const QCString &className, const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name, const QCString &tooltip)
void_startOpenLine ()

Private Member Attributes Index

TextStream *m_t
size_tm_col = 0
QCStringm_relPath
QCStringm_fileName
boolm_lineOpen = false
boolm_stripCodeComments = false
boolm_hide = false
LineInfom_lastLineInfo
size_tm_stripIndentAmount = 0

Description

Generator for HTML code fragments.

Definition at line 25 of file htmlgen.h.

Public Constructors

HtmlCodeGenerator()

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

Declaration at line 28 of file htmlgen.h, definition at line 715 of file htmlgen.cpp.

716 : m_t(t), m_relPath(relPath)
717{
718 //printf("%p:HtmlCodeGenerator()\n",(void*)this);
719}

References m_relPath and m_t.

HtmlCodeGenerator()

HtmlCodeGenerator::HtmlCodeGenerator (TextStream * t)

Declaration at line 29 of file htmlgen.h, definition at line 710 of file htmlgen.cpp.

711{
712 //printf("%p:HtmlCodeGenerator()\n",(void*)this);
713}

Reference m_t.

Public Member Functions

clone()

std::unique_ptr< OutputCodeIntf > HtmlCodeGenerator::clone ()
inline virtual

Definition at line 36 of file htmlgen.h.

36 std::unique_ptr<OutputCodeIntf> clone() override { return std::make_unique<HtmlCodeGenerator>(*this); }

codify()

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

Declaration at line 37 of file htmlgen.h, definition at line 726 of file htmlgen.cpp.

727{
728 if (!str.isEmpty())
729 {
730 int tabSize = Config_getInt(TAB_SIZE);
731 const char *p=str.data();
732 if (m_hide) // only update column count
733 {
735 }
736 else // actually output content and keep track of m_col
737 {
738 while (*p)
739 {
740 char c=*p++;
741 switch(c)
742 {
743 case '\t': {
744 int spacesToNextTabStop = tabSize - (m_col%tabSize);
745 while (spacesToNextTabStop--)
746 {
747 if (m_col>=m_stripIndentAmount) *m_t << " ";
748 m_col++;
749 }
750 }
751 break;
752 case ' ': if (m_col>=m_stripIndentAmount) *m_t << " ";
753 m_col++;
754 break;
755 case '\n': *m_t << "\n"; m_col=0;
756 break;
757 case '\r': break;
758 case '<': *m_t << "&lt;"; m_col++;
759 break;
760 case '>': *m_t << "&gt;"; m_col++;
761 break;
762 case '&': *m_t << "&amp;"; m_col++;
763 break;
764 case '\'': *m_t << "&#39;"; m_col++; // &apos; is not valid XHTML
765 break;
766 case '"': *m_t << "&quot;"; m_col++;
767 break;
768 case '\\':
769 if (*p=='<')
770 { *m_t << "&lt;"; p++; }
771 else if (*p=='>')
772 { *m_t << "&gt;"; p++; }
773 else if (*p=='(')
774 { *m_t << "\\&zwj;("; m_col++;p++; }
775 else if (*p==')')
776 { *m_t << "\\&zwj;)"; m_col++;p++; }
777 else
778 *m_t << "\\";
779 m_col++;
780 break;
781 default:
782 {
783 uint8_t uc = static_cast<uint8_t>(c);
784 if (uc<32)
785 {
786 *m_t << "&#x24" << hex[uc>>4] << hex[uc&0xF] << ";";
787 m_col++;
788 }
789 else if (uc<0x80) // printable ASCII char
790 {
791 *m_t << c;
792 m_col++;
793 }
794 else // multibyte UTF-8 char
795 {
796 p=writeUTF8Char(*m_t,p-1);
797 m_col++;
798 }
799 }
800 break;
801 }
802 }
803 }
804 }
805}

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 &)
virtual

Declaration at line 60 of file htmlgen.h, definition at line 1033 of file htmlgen.cpp.

1034{
1035 //endCodeLine checks is there is still an open code line, if so closes it.
1036 endCodeLine();
1037
1038 *m_t << "</div><!-- fragment -->";
1039}

References endCodeLine and m_t.

endCodeLine()

void HtmlCodeGenerator::endCodeLine ()
virtual

Declaration at line 55 of file htmlgen.h, definition at line 995 of file htmlgen.cpp.

996{
997 if (m_hide) return;
998 if (m_col == 0)
999 {
1000 *m_t << " ";
1001 m_col++;
1002 }
1003 if (m_lineOpen)
1004 {
1005 *m_t << "</div>\n";
1007 }
1008}

References FALSE, m_col, m_hide, m_lineOpen and m_t.

Referenced by endCodeFragment.

endFold()

void HtmlCodeGenerator::endFold ()
virtual

Declaration at line 62 of file htmlgen.h, definition at line 1075 of file htmlgen.cpp.

1076{
1077 if (m_lineOpen) // if we have a hidden comment in a code fold, we need to end the line
1078 {
1079 *m_t << "</div>\n";
1080 }
1081 *m_t << "</div>\n";
1082 if (m_lineOpen)
1083 {
1085 }
1086}

References _startOpenLine, m_lineOpen and m_t.

endFontClass()

void HtmlCodeGenerator::endFontClass ()
virtual

Declaration at line 57 of file htmlgen.h, definition at line 1016 of file htmlgen.cpp.

1017{
1018 if (m_hide) return;
1019 *m_t << "</span>";
1020}

References m_hide and m_t.

endSpecialComment()

void HtmlCodeGenerator::endSpecialComment ()
virtual

Declaration at line 40 of file htmlgen.h, definition at line 818 of file htmlgen.cpp.

819{
820 //*m_t << "[END]";
821 m_hide = false;
822}

Reference m_hide.

fileName()

QCString HtmlCodeGenerator::fileName ()
inline

Definition at line 33 of file htmlgen.h.

Reference 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)

Declaration at line 64 of file htmlgen.h, definition at line 721 of file htmlgen.cpp.

722{
723 m_relPath = path;
724}

Reference m_relPath.

setStripIndentAmount()

void HtmlCodeGenerator::setStripIndentAmount (size_t amount)
virtual

Declaration at line 41 of file htmlgen.h, definition at line 824 of file htmlgen.cpp.

825{
826 m_stripIndentAmount = amount;
827}

Reference m_stripIndentAmount.

setTextStream()

void HtmlCodeGenerator::setTextStream (TextStream * t)
inline

Definition at line 31 of file htmlgen.h.

31 void setTextStream(TextStream *t) { m_t = t; }

Reference m_t.

startCodeFragment()

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

Declaration at line 59 of file htmlgen.h, definition at line 1028 of file htmlgen.cpp.

1029{
1030 *m_t << "<div class=\"fragment\">";
1031}

Reference m_t.

startCodeLine()

void HtmlCodeGenerator::startCodeLine (int)
virtual

Declaration at line 54 of file htmlgen.h, definition at line 984 of file htmlgen.cpp.

985{
986 m_col=0;
987 if (m_hide) return;
988 if (!m_lineOpen)
989 {
990 *m_t << "<div class=\"line\">";
992 }
993}

References m_col, m_hide, m_lineOpen, m_t and TRUE.

startFold()

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

Declaration at line 61 of file htmlgen.h, definition at line 1041 of file htmlgen.cpp.

1041void HtmlCodeGenerator::startFold(int lineNr,const QCString &startMarker,const QCString &endMarker)
1042{
1043 if (m_lineOpen) // if we have a hidden comment in a code fold, we need to end the line
1044 {
1045 *m_t << "</div>\n";
1046 }
1047 const int maxLineNrStr = 10;
1048 char lineNumber[maxLineNrStr];
1049 qsnprintf(lineNumber,maxLineNrStr,"%05d",lineNr);
1050 *m_t << "<div class=\"foldopen\" id=\"foldopen" << lineNumber <<
1051 "\" data-start=\"" << startMarker <<
1052 "\" data-end=\"" << endMarker <<
1053 "\">\n";
1054 if (m_lineOpen) // if we have a hidden comment in a code fold, we need to restart the line
1055 {
1056 *m_t << "<div class=\"line\">";
1057 }
1058 m_hide=false;
1059}

References m_hide, m_lineOpen, m_t and qsnprintf.

startFontClass()

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

Declaration at line 56 of file htmlgen.h, definition at line 1010 of file htmlgen.cpp.

1011{
1012 if (m_hide) return;
1013 *m_t << "<span class=\"" << s << "\">";
1014}

References m_hide and m_t.

startSpecialComment()

void HtmlCodeGenerator::startSpecialComment ()
virtual

Declaration at line 39 of file htmlgen.h, definition at line 812 of file htmlgen.cpp.

813{
815 //*m_t << "[START]";
816}

References m_hide and m_stripCodeComments.

stripCodeComments()

void HtmlCodeGenerator::stripCodeComments (bool b)
virtual

Declaration at line 38 of file htmlgen.h, definition at line 807 of file htmlgen.cpp.

Reference m_stripCodeComments.

type()

OutputType HtmlCodeGenerator::type ()
inline virtual

Definition at line 35 of file htmlgen.h.

35 OutputType type() const override { return OutputType::Html; }

Reference Html.

Referenced by writeCodeLink.

writeCodeAnchor()

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

Declaration at line 58 of file htmlgen.h, definition at line 1022 of file htmlgen.cpp.

1023{
1024 if (m_hide) return;
1025 *m_t << "<a id=\"" << anchor << "\" name=\"" << anchor << "\"></a>";
1026}

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)
virtual

Declaration at line 42 of file htmlgen.h, definition at line 860 of file htmlgen.cpp.

861 const QCString &ref,const QCString &f,
862 const QCString &anchor, const QCString &name,
863 const QCString &tooltip)
864{
865 if (m_hide) return;
866 const char *hl = codeSymbolType2Str(type);
867 QCString hlClass = "code";
868 if (hl)
869 {
870 hlClass+=" hl_";
871 hlClass+=hl;
872 }
873 _writeCodeLink(hlClass,ref,f,anchor,name,tooltip);
874}

References _writeCodeLink, codeSymbolType2Str, m_hide and type.

writeLineNumber()

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

Declaration at line 53 of file htmlgen.h, definition at line 829 of file htmlgen.cpp.

830 const QCString &anchor,int l,bool writeLineAnchor)
831{
832 m_lastLineInfo = LineInfo(ref,filename,anchor,l,writeLineAnchor);
833 if (m_hide) return;
834 const int maxLineNrStr = 10;
835 char lineNumber[maxLineNrStr];
836 char lineAnchor[maxLineNrStr];
837 qsnprintf(lineNumber,maxLineNrStr,"%5d",l);
838 qsnprintf(lineAnchor,maxLineNrStr,"l%05d",l);
839
840 if (!m_lineOpen)
841 {
842 *m_t << "<div class=\"line\">";
844 }
845
846 if (writeLineAnchor) *m_t << "<a id=\"" << lineAnchor << "\" name=\"" << lineAnchor << "\"></a>";
847 *m_t << "<span class=\"lineno\">";
848 if (!filename.isEmpty())
849 {
850 _writeCodeLink("line",ref,filename,anchor,lineNumber,QCString());
851 }
852 else
853 {
854 codify(lineNumber);
855 }
856 *m_t << "</span>";
857 m_col=0;
858}

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)
virtual

Declaration at line 46 of file htmlgen.h, definition at line 904 of file htmlgen.cpp.

905 const QCString &decl, const QCString &desc,
906 const SourceLinkInfo &defInfo,
907 const SourceLinkInfo &declInfo)
908{
909 if (m_hide) return;
910 *m_t << "<div class=\"ttc\" id=\"" << id << "\">";
911 *m_t << "<div class=\"ttname\">";
912 if (!docInfo.url.isEmpty())
913 {
914 *m_t << "<a href=\"";
915 QCString fn = docInfo.url;
917 *m_t << createHtmlUrl(m_relPath,docInfo.ref,true,
918 fileName()==fn,fn,docInfo.anchor);
919 *m_t << "\">";
920 }
921 codify(docInfo.name);
922 if (!docInfo.url.isEmpty())
923 {
924 *m_t << "</a>";
925 }
926 *m_t << "</div>";
927
928 if (!decl.isEmpty())
929 {
930 *m_t << "<div class=\"ttdeci\">";
931 codify(decl);
932 *m_t << "</div>";
933 }
934
935 if (!desc.isEmpty())
936 {
937 *m_t << "<div class=\"ttdoc\">";
938 codify(desc);
939 *m_t << "</div>";
940 }
941
942 if (!defInfo.file.isEmpty())
943 {
944 *m_t << "<div class=\"ttdef\"><b>" << theTranslator->trDefinition() << "</b> ";
945 if (!defInfo.url.isEmpty())
946 {
947 *m_t << "<a href=\"";
948 QCString fn = defInfo.url;
950 *m_t << createHtmlUrl(m_relPath,defInfo.ref,true,
951 fileName()==fn,fn,defInfo.anchor);
952 *m_t << "\">";
953 }
954 *m_t << defInfo.file << ":" << defInfo.line;
955 if (!defInfo.url.isEmpty())
956 {
957 *m_t << "</a>";
958 }
959 *m_t << "</div>";
960 }
961 if (!declInfo.file.isEmpty())
962 {
963 *m_t << "<div class=\"ttdecl\"><b>" << theTranslator->trDeclaration() << "</b> ";
964 if (!declInfo.url.isEmpty())
965 {
966 *m_t << "<a href=\"";
967 QCString fn = declInfo.url;
969 *m_t << createHtmlUrl(m_relPath,declInfo.ref,true,
970 fileName()==fn,fn,declInfo.anchor);
971 *m_t << "\">";
972 }
973 *m_t << declInfo.file << ":" << declInfo.line;
974 if (!declInfo.url.isEmpty())
975 {
976 *m_t << "</a>";
977 }
978 *m_t << "</div>";
979 }
980 *m_t << "</div>\n";
981}

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.

Private Member Functions

_startOpenLine()

void HtmlCodeGenerator::_startOpenLine ()

Declaration at line 70 of file htmlgen.h, definition at line 1061 of file htmlgen.cpp.

1062{
1063 *m_t << "<div class=\"line\">";
1064 bool wasHidden=m_hide;
1065 m_hide = false;
1066 m_lineOpen = true;
1068 m_lastLineInfo.fileName,
1069 m_lastLineInfo.anchor,
1070 m_lastLineInfo.line+1,
1071 m_lastLineInfo.writeAnchor);
1072 m_hide = wasHidden;
1073}

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)

Declaration at line 66 of file htmlgen.h, definition at line 876 of file htmlgen.cpp.

877 const QCString &ref,const QCString &f,
878 const QCString &anchor, const QCString &name,
879 const QCString &tooltip)
880{
881 m_col+=name.length();
882 if (m_hide) return;
883 if (!ref.isEmpty())
884 {
885 *m_t << "<a class=\"" << className << "Ref\" ";
887 }
888 else
889 {
890 *m_t << "<a class=\"" << className << "\" ";
891 }
892 *m_t << "href=\"";
893 QCString fn = f;
895 *m_t << createHtmlUrl(m_relPath,ref,true,
896 fileName()==fn,fn,anchor);
897 *m_t << "\"";
898 if (!tooltip.isEmpty()) *m_t << " title=\"" << convertToHtml(tooltip) << "\"";
899 *m_t << ">";
900 codify(name);
901 *m_t << "</a>";
902}

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.

Private Member Attributes

m_col

size_t HtmlCodeGenerator::m_col = 0

Definition at line 73 of file htmlgen.h.

73 size_t m_col = 0;

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

m_fileName

QCString HtmlCodeGenerator::m_fileName

Definition at line 75 of file htmlgen.h.

Referenced by fileName and setFileName.

m_hide

m_lastLineInfo

LineInfo HtmlCodeGenerator::m_lastLineInfo

Definition at line 90 of file htmlgen.h.

Referenced by _startOpenLine and writeLineNumber.

m_lineOpen

bool HtmlCodeGenerator::m_lineOpen = false

Definition at line 76 of file htmlgen.h.

76 bool m_lineOpen = false;

Referenced by _startOpenLine, endCodeLine, endFold, startCodeLine, startFold and writeLineNumber.

m_relPath

QCString HtmlCodeGenerator::m_relPath

Definition at line 74 of file htmlgen.h.

Referenced by _writeCodeLink, HtmlCodeGenerator, setRelativePath and writeTooltip.

m_stripCodeComments

bool HtmlCodeGenerator::m_stripCodeComments = false

Definition at line 77 of file htmlgen.h.

77 bool m_stripCodeComments = false;

Referenced by startSpecialComment and stripCodeComments.

m_stripIndentAmount

size_t HtmlCodeGenerator::m_stripIndentAmount = 0

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:


Generated via doxygen2docusaurus by Doxygen 1.14.0.