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

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

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

References m_t.

Member Function Documentation

◆ _startOpenLine()

void HtmlCodeGenerator::_startOpenLine ( )
private

Definition at line 1060 of file htmlgen.cpp.

1061{
1062 *m_t << "<div class=\"line\">";
1063 bool wasHidden=m_hide;
1064 m_hide = false;
1065 m_lineOpen = true;
1067 m_lastLineInfo.fileName,
1068 m_lastLineInfo.anchor,
1069 m_lastLineInfo.line+1,
1070 m_lastLineInfo.writeAnchor);
1071 m_hide = wasHidden;
1072}
void writeLineNumber(const QCString &, const QCString &, const QCString &, int, bool) override
Definition htmlgen.cpp:828
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 875 of file htmlgen.cpp.

879{
880 m_col+=name.length();
881 if (m_hide) return;
882 if (!ref.isEmpty())
883 {
884 *m_t << "<a class=\"" << className << "Ref\" ";
886 }
887 else
888 {
889 *m_t << "<a class=\"" << className << "\" ";
890 }
891 *m_t << "href=\"";
892 QCString fn = f;
894 *m_t << createHtmlUrl(m_relPath,ref,true,
895 fileName()==fn,fn,anchor);
896 *m_t << "\"";
897 if (!tooltip.isEmpty()) *m_t << " title=\"" << convertToHtml(tooltip) << "\"";
898 *m_t << ">";
899 codify(name);
900 *m_t << "</a>";
901}
void codify(const QCString &text) override
Definition htmlgen.cpp:725
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:4317
QCString externalLinkTarget(const bool parent)
Definition util.cpp:6021
void addHtmlExtensionIfMissing(QCString &fName)
Definition util.cpp:5243
QCString createHtmlUrl(const QCString &relPath, const QCString &ref, bool href, bool isLocalFile, const QCString &targetFileName, const QCString &anchor)
Definition util.cpp:6032

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

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

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

1033{
1034 //endCodeLine checks is there is still an open code line, if so closes it.
1035 endCodeLine();
1036
1037 *m_t << "</div><!-- fragment -->";
1038}
void endCodeLine() override
Definition htmlgen.cpp:994

References endCodeLine(), and m_t.

◆ endCodeLine()

void HtmlCodeGenerator::endCodeLine ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 994 of file htmlgen.cpp.

995{
996 if (m_hide) return;
997 if (m_col == 0)
998 {
999 *m_t << " ";
1000 m_col++;
1001 }
1002 if (m_lineOpen)
1003 {
1004 *m_t << "</div>\n";
1005 m_lineOpen = FALSE;
1006 }
1007}
#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 1074 of file htmlgen.cpp.

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

References _startOpenLine(), m_lineOpen, and m_t.

◆ endFontClass()

void HtmlCodeGenerator::endFontClass ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 1015 of file htmlgen.cpp.

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

References m_hide, and m_t.

◆ endSpecialComment()

void HtmlCodeGenerator::endSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 817 of file htmlgen.cpp.

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

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

721{
722 m_relPath = path;
723}

References m_relPath.

◆ setStripIndentAmount()

void HtmlCodeGenerator::setStripIndentAmount ( size_t amount)
overridevirtual

Implements OutputCodeIntf.

Definition at line 823 of file htmlgen.cpp.

824{
825 m_stripIndentAmount = amount;
826}

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

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

References m_t.

◆ startCodeLine()

void HtmlCodeGenerator::startCodeLine ( int )
overridevirtual

Implements OutputCodeIntf.

Definition at line 983 of file htmlgen.cpp.

984{
985 m_col=0;
986 if (m_hide) return;
987 if (!m_lineOpen)
988 {
989 *m_t << "<div class=\"line\">";
991 }
992}
#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 1040 of file htmlgen.cpp.

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

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

References m_hide, and m_t.

◆ startSpecialComment()

void HtmlCodeGenerator::startSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 811 of file htmlgen.cpp.

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

807{
809}

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

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

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

863{
864 if (m_hide) return;
865 const char *hl = codeSymbolType2Str(type);
866 QCString hlClass = "code";
867 if (hl)
868 {
869 hlClass+=" hl_";
870 hlClass+=hl;
871 }
872 _writeCodeLink(hlClass,ref,f,anchor,name,tooltip);
873}
void _writeCodeLink(const QCString &className, const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name, const QCString &tooltip)
Definition htmlgen.cpp:875
OutputType type() const override
Definition htmlgen.h:34
constexpr const char * codeSymbolType2Str(CodeSymbolType type)
Definition types.h:353

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

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

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

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