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

Constructor & Destructor Documentation

◆ HtmlCodeGenerator() [1/2]

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

Definition at line 719 of file htmlgen.cpp.

720 : m_t(t), m_relPath(relPath)
721{
722 //printf("%p:HtmlCodeGenerator()\n",(void*)this);
723}
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 714 of file htmlgen.cpp.

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

References m_t.

Member Function Documentation

◆ _startOpenLine()

void HtmlCodeGenerator::_startOpenLine ( )
private

Definition at line 1065 of file htmlgen.cpp.

1066{
1067 *m_t << "<div class=\"line\">";
1068 bool wasHidden=m_hide;
1069 m_hide = false;
1070 m_lineOpen = true;
1072 m_lastLineInfo.fileName,
1073 m_lastLineInfo.anchor,
1074 m_lastLineInfo.line+1,
1075 m_lastLineInfo.writeAnchor);
1076 m_hide = wasHidden;
1077}
void writeLineNumber(const QCString &, const QCString &, const QCString &, int, bool) override
Definition htmlgen.cpp:833
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 880 of file htmlgen.cpp.

884{
885 m_col+=name.length();
886 if (m_hide) return;
887 if (!ref.isEmpty())
888 {
889 *m_t << "<a class=\"" << className << "Ref\" ";
891 }
892 else
893 {
894 *m_t << "<a class=\"" << className << "\" ";
895 }
896 *m_t << "href=\"";
897 QCString fn = f;
899 *m_t << createHtmlUrl(m_relPath,ref,true,
900 fileName()==fn,fn,anchor);
901 *m_t << "\"";
902 if (!tooltip.isEmpty()) *m_t << " title=\"" << convertToHtml(tooltip) << "\"";
903 *m_t << ">";
904 codify(name);
905 *m_t << "</a>";
906}
void codify(const QCString &text) override
Definition htmlgen.cpp:730
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:6187
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:6198

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

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

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

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

References endCodeLine(), and m_t.

◆ endCodeLine()

void HtmlCodeGenerator::endCodeLine ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 999 of file htmlgen.cpp.

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

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

References _startOpenLine(), m_lineOpen, and m_t.

◆ endFontClass()

void HtmlCodeGenerator::endFontClass ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1020 of file htmlgen.cpp.

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

References m_hide, and m_t.

◆ endSpecialComment()

void HtmlCodeGenerator::endSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 822 of file htmlgen.cpp.

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

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

726{
727 m_relPath = path;
728}

References m_relPath.

◆ setStripIndentAmount()

void HtmlCodeGenerator::setStripIndentAmount ( size_t amount)
overridevirtual

Implements OutputCodeIntf.

Definition at line 828 of file htmlgen.cpp.

829{
830 m_stripIndentAmount = amount;
831}

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

1033{
1034 *m_t << "<div class=\"fragment\">";
1035}

References m_t.

◆ startCodeLine()

void HtmlCodeGenerator::startCodeLine ( int )
overridevirtual

Implements OutputCodeIntf.

Definition at line 988 of file htmlgen.cpp.

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

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

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

References m_hide, and m_t.

◆ startSpecialComment()

void HtmlCodeGenerator::startSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 816 of file htmlgen.cpp.

817{
819 //*m_t << "[START]";
820}
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 811 of file htmlgen.cpp.

812{
814}

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

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

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

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

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

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

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