Doxygen
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 24 of file htmlgen.h.

Constructor & Destructor Documentation

◆ HtmlCodeGenerator() [1/2]

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

Definition at line 721 of file htmlgen.cpp.

722 : m_t(t), m_relPath(relPath)
723{
724 //printf("%p:HtmlCodeGenerator()\n",(void*)this);
725}
QCString m_relPath
Definition htmlgen.h:73
TextStream * m_t
Definition htmlgen.h:71

References m_relPath, and m_t.

◆ HtmlCodeGenerator() [2/2]

HtmlCodeGenerator::HtmlCodeGenerator ( TextStream * t)

Definition at line 716 of file htmlgen.cpp.

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

References m_t.

Member Function Documentation

◆ _startOpenLine()

void HtmlCodeGenerator::_startOpenLine ( )
private

Definition at line 1067 of file htmlgen.cpp.

1068{
1069 *m_t << "<div class=\"line\">";
1070 bool wasHidden=m_hide;
1071 m_hide = false;
1072 m_lineOpen = true;
1074 m_lastLineInfo.fileName,
1075 m_lastLineInfo.anchor,
1076 m_lastLineInfo.line+1,
1077 m_lastLineInfo.writeAnchor);
1078 m_hide = wasHidden;
1079}
void writeLineNumber(const QCString &, const QCString &, const QCString &, int, bool) override
Definition htmlgen.cpp:835
LineInfo m_lastLineInfo
Definition htmlgen.h:89

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

886{
887 m_col+=name.length();
888 if (m_hide) return;
889 if (!ref.isEmpty())
890 {
891 *m_t << "<a class=\"" << className << "Ref\" ";
893 }
894 else
895 {
896 *m_t << "<a class=\"" << className << "\" ";
897 }
898 *m_t << "href=\"";
899 QCString fn = f;
901 *m_t << createHtmlUrl(m_relPath,ref,true,
902 fileName()==fn,fn,anchor);
903 *m_t << "\"";
904 if (!tooltip.isEmpty()) *m_t << " title=\"" << convertToHtml(tooltip) << "\"";
905 *m_t << ">";
906 codify(name);
907 *m_t << "</a>";
908}
void codify(const QCString &text) override
Definition htmlgen.cpp:732
QCString fileName()
Definition htmlgen.h:32
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:153
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
QCString convertToHtml(const QCString &s, bool keepEntities)
Definition util.cpp:4472
QCString externalLinkTarget(const bool parent)
Definition util.cpp:6181
void addHtmlExtensionIfMissing(QCString &fName)
Definition util.cpp:5408
QCString createHtmlUrl(const QCString &relPath, const QCString &ref, bool href, bool isLocalFile, const QCString &targetFileName, const QCString &anchor)
Definition util.cpp:6192

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 35 of file htmlgen.h.

35{ return std::make_unique<HtmlCodeGenerator>(*this); }

◆ codify()

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

Implements OutputCodeIntf.

Definition at line 732 of file htmlgen.cpp.

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

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

1040{
1041 //endCodeLine checks is there is still an open code line, if so closes it.
1042 endCodeLine();
1043
1044 *m_t << "</div><!-- fragment -->";
1045}
void endCodeLine() override
Definition htmlgen.cpp:1001

References endCodeLine(), and m_t.

◆ endCodeLine()

void HtmlCodeGenerator::endCodeLine ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1001 of file htmlgen.cpp.

1002{
1003 if (m_hide) return;
1004 if (m_col == 0)
1005 {
1006 *m_t << " ";
1007 m_col++;
1008 }
1009 if (m_lineOpen)
1010 {
1011 *m_t << "</div>\n";
1012 m_lineOpen = FALSE;
1013 }
1014}
#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 1081 of file htmlgen.cpp.

1082{
1083 if (m_lineOpen) // if we have a hidden comment in a code fold, we need to end the line
1084 {
1085 *m_t << "</div>\n";
1086 }
1087 *m_t << "</div>\n";
1088 if (m_lineOpen)
1089 {
1091 }
1092}

References _startOpenLine(), m_lineOpen, and m_t.

◆ endFontClass()

void HtmlCodeGenerator::endFontClass ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1022 of file htmlgen.cpp.

1023{
1024 if (m_hide) return;
1025 *m_t << "</span>";
1026}

References m_hide, and m_t.

◆ endSpecialComment()

void HtmlCodeGenerator::endSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 824 of file htmlgen.cpp.

825{
826 //*m_t << "[END]";
827 m_hide = false;
828}

References m_hide.

◆ fileName()

QCString HtmlCodeGenerator::fileName ( )
inline

Definition at line 32 of file htmlgen.h.

32{ return m_fileName; }
QCString m_fileName
Definition htmlgen.h:74

References m_fileName.

Referenced by _writeCodeLink(), setFileName(), and writeTooltip().

◆ setFileName()

void HtmlCodeGenerator::setFileName ( const QCString fileName)
inline

Definition at line 31 of file htmlgen.h.

References fileName(), and m_fileName.

◆ setRelativePath()

void HtmlCodeGenerator::setRelativePath ( const QCString & path)

Definition at line 727 of file htmlgen.cpp.

728{
729 m_relPath = path;
730}

References m_relPath.

◆ setStripIndentAmount()

void HtmlCodeGenerator::setStripIndentAmount ( size_t amount)
overridevirtual

Implements OutputCodeIntf.

Definition at line 830 of file htmlgen.cpp.

831{
832 m_stripIndentAmount = amount;
833}

References m_stripIndentAmount.

◆ setTextStream()

void HtmlCodeGenerator::setTextStream ( TextStream * t)
inline

Definition at line 30 of file htmlgen.h.

30{ m_t = t; }

References m_t.

◆ startCodeFragment()

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

Implements OutputCodeIntf.

Definition at line 1034 of file htmlgen.cpp.

1035{
1036 *m_t << "<div class=\"fragment\">";
1037}

References m_t.

◆ startCodeLine()

void HtmlCodeGenerator::startCodeLine ( int )
overridevirtual

Implements OutputCodeIntf.

Definition at line 990 of file htmlgen.cpp.

991{
992 m_col=0;
993 if (m_hide) return;
994 if (!m_lineOpen)
995 {
996 *m_t << "<div class=\"line\">";
998 }
999}
#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 1047 of file htmlgen.cpp.

1048{
1049 if (m_lineOpen) // if we have a hidden comment in a code fold, we need to end the line
1050 {
1051 *m_t << "</div>\n";
1052 }
1053 const int maxLineNrStr = 10;
1054 char lineNumber[maxLineNrStr];
1055 qsnprintf(lineNumber,maxLineNrStr,"%05d",lineNr);
1056 *m_t << "<div class=\"foldopen\" id=\"foldopen" << lineNumber <<
1057 "\" data-start=\"" << startMarker <<
1058 "\" data-end=\"" << endMarker <<
1059 "\">\n";
1060 if (m_lineOpen) // if we have a hidden comment in a code fold, we need to restart the line
1061 {
1062 *m_t << "<div class=\"line\">";
1063 }
1064 m_hide=false;
1065}
#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 1016 of file htmlgen.cpp.

1017{
1018 if (m_hide) return;
1019 *m_t << "<span class=\"" << s << "\">";
1020}

References m_hide, and m_t.

◆ startSpecialComment()

void HtmlCodeGenerator::startSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 818 of file htmlgen.cpp.

819{
821 //*m_t << "[START]";
822}
bool m_stripCodeComments
Definition htmlgen.h:76

References m_hide, and m_stripCodeComments.

◆ stripCodeComments()

void HtmlCodeGenerator::stripCodeComments ( bool b)
overridevirtual

Implements OutputCodeIntf.

Definition at line 813 of file htmlgen.cpp.

814{
816}

References m_stripCodeComments.

◆ type()

OutputType HtmlCodeGenerator::type ( ) const
inlineoverridevirtual

Implements OutputCodeIntf.

Definition at line 34 of file htmlgen.h.

34{ return OutputType::Html; }

References Html.

Referenced by writeCodeLink().

◆ writeCodeAnchor()

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

Implements OutputCodeIntf.

Definition at line 1028 of file htmlgen.cpp.

1029{
1030 if (m_hide) return;
1031 *m_t << "<a id=\"" << anchor << "\" name=\"" << anchor << "\"></a>";
1032}

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

870{
871 if (m_hide) return;
872 const char *hl = codeSymbolType2Str(type);
873 QCString hlClass = "code";
874 if (hl)
875 {
876 hlClass+=" hl_";
877 hlClass+=hl;
878 }
879 _writeCodeLink(hlClass,ref,f,anchor,name,tooltip);
880}
void _writeCodeLink(const QCString &className, const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name, const QCString &tooltip)
Definition htmlgen.cpp:882
OutputType type() const override
Definition htmlgen.h:34
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 835 of file htmlgen.cpp.

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

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

914{
915 if (m_hide) return;
916 *m_t << "<div class=\"ttc\" id=\"" << id << "\">";
917 *m_t << "<div class=\"ttname\">";
918 if (!docInfo.url.isEmpty())
919 {
920 *m_t << "<a href=\"";
921 QCString fn = docInfo.url;
923 *m_t << createHtmlUrl(m_relPath,docInfo.ref,true,
924 fileName()==fn,fn,docInfo.anchor);
925 *m_t << "\">";
926 }
927 codify(docInfo.name);
928 if (!docInfo.url.isEmpty())
929 {
930 *m_t << "</a>";
931 }
932 *m_t << "</div>";
933
934 if (!decl.isEmpty())
935 {
936 *m_t << "<div class=\"ttdeci\">";
937 codify(decl);
938 *m_t << "</div>";
939 }
940
941 if (!desc.isEmpty())
942 {
943 *m_t << "<div class=\"ttdoc\">";
944 codify(desc);
945 *m_t << "</div>";
946 }
947
948 if (!defInfo.file.isEmpty())
949 {
950 *m_t << "<div class=\"ttdef\"><b>" << theTranslator->trDefinition() << "</b> ";
951 if (!defInfo.url.isEmpty())
952 {
953 *m_t << "<a href=\"";
954 QCString fn = defInfo.url;
956 *m_t << createHtmlUrl(m_relPath,defInfo.ref,true,
957 fileName()==fn,fn,defInfo.anchor);
958 *m_t << "\">";
959 }
960 *m_t << defInfo.file << ":" << defInfo.line;
961 if (!defInfo.url.isEmpty())
962 {
963 *m_t << "</a>";
964 }
965 *m_t << "</div>";
966 }
967 if (!declInfo.file.isEmpty())
968 {
969 *m_t << "<div class=\"ttdecl\"><b>" << theTranslator->trDeclaration() << "</b> ";
970 if (!declInfo.url.isEmpty())
971 {
972 *m_t << "<a href=\"";
973 QCString fn = declInfo.url;
975 *m_t << createHtmlUrl(m_relPath,declInfo.ref,true,
976 fileName()==fn,fn,declInfo.anchor);
977 *m_t << "\">";
978 }
979 *m_t << declInfo.file << ":" << declInfo.line;
980 if (!declInfo.url.isEmpty())
981 {
982 *m_t << "</a>";
983 }
984 *m_t << "</div>";
985 }
986 *m_t << "</div>\n";
987}
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 72 of file htmlgen.h.

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

◆ m_fileName

QCString HtmlCodeGenerator::m_fileName
private

Definition at line 74 of file htmlgen.h.

Referenced by fileName(), and setFileName().

◆ m_hide

◆ m_lastLineInfo

LineInfo HtmlCodeGenerator::m_lastLineInfo
private

Definition at line 89 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 73 of file htmlgen.h.

Referenced by _writeCodeLink(), HtmlCodeGenerator(), setRelativePath(), and writeTooltip().

◆ m_stripCodeComments

bool HtmlCodeGenerator::m_stripCodeComments = false
private

Definition at line 76 of file htmlgen.h.

Referenced by startSpecialComment(), and stripCodeComments().

◆ m_stripIndentAmount

size_t HtmlCodeGenerator::m_stripIndentAmount = 0
private

Definition at line 90 of file htmlgen.h.

Referenced by codify(), and setStripIndentAmount().

◆ m_t


The documentation for this class was generated from the following files: