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

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

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

References m_t.

Member Function Documentation

◆ _startOpenLine()

void HtmlCodeGenerator::_startOpenLine ( )
private

Definition at line 1066 of file htmlgen.cpp.

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

885{
886 m_col+=name.length();
887 if (m_hide) return;
888 if (!ref.isEmpty())
889 {
890 *m_t << "<a class=\"" << className << "Ref\" ";
892 }
893 else
894 {
895 *m_t << "<a class=\"" << className << "\" ";
896 }
897 *m_t << "href=\"";
898 QCString fn = f;
900 *m_t << createHtmlUrl(m_relPath,ref,true,
901 fileName()==fn,fn,anchor);
902 *m_t << "\"";
903 if (!tooltip.isEmpty()) *m_t << " title=\"" << convertToHtml(tooltip) << "\"";
904 *m_t << ">";
905 codify(name);
906 *m_t << "</a>";
907}
void codify(const QCString &text) override
Definition htmlgen.cpp:731
QCString fileName()
Definition htmlgen.h:33
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:4480
QCString externalLinkTarget(const bool parent)
Definition util.cpp:6227
void addHtmlExtensionIfMissing(QCString &fName)
Definition util.cpp:5416
QCString createHtmlUrl(const QCString &relPath, const QCString &ref, bool href, bool isLocalFile, const QCString &targetFileName, const QCString &anchor)
Definition util.cpp:6238

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

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

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

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

References endCodeLine(), and m_t.

◆ endCodeLine()

void HtmlCodeGenerator::endCodeLine ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1000 of file htmlgen.cpp.

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

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

References _startOpenLine(), m_lineOpen, and m_t.

◆ endFontClass()

void HtmlCodeGenerator::endFontClass ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1021 of file htmlgen.cpp.

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

References m_hide, and m_t.

◆ endSpecialComment()

void HtmlCodeGenerator::endSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 823 of file htmlgen.cpp.

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

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

727{
728 m_relPath = path;
729}

References m_relPath.

◆ setStripIndentAmount()

void HtmlCodeGenerator::setStripIndentAmount ( size_t amount)
overridevirtual

Implements OutputCodeIntf.

Definition at line 829 of file htmlgen.cpp.

830{
831 m_stripIndentAmount = amount;
832}

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

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

References m_t.

◆ startCodeLine()

void HtmlCodeGenerator::startCodeLine ( int )
overridevirtual

Implements OutputCodeIntf.

Definition at line 989 of file htmlgen.cpp.

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

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

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

References m_hide, and m_t.

◆ startSpecialComment()

void HtmlCodeGenerator::startSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 817 of file htmlgen.cpp.

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

813{
815}

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

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

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

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

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

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

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