From b81d5b4c799e1180f5570ab8c8626ff46f3aa84a Mon Sep 17 00:00:00 2001 From: albert-github Date: Mon, 17 Jun 2019 14:23:28 +0200 Subject: Incorrect (X)HTML code when generating source code. When having the example: ``` /*! \file * \brief * Prerequisite header file */ //! \cond #ifdef HAVE_CONFIG_H #include "gmxpre-config.h" #endif //! \endcond ``` and we run xmllint on it: ``` xmllint --path .../testing/dtd --noout --nonet --postvalid html/*.html ``` we get the messages: ``` html/aa_8h_source.html:75: parser error : Opening and ending tag mismatch: div line 67 and body ^ html/aa_8h_source.html:76: parser error : Opening and ending tag mismatch: body line 17 and html ^ html/aa_8h_source.html:77: parser error : Premature end of data in tag html line 2 ^ ``` It looks like the problematic part in this case is the doxygen type comment at the end of the file. In the past similar situations were present in LaTeX (related to maximum line length correction), but it was only fixed for LaTeX. Besides the change for HTML also small changes were necessary for RTF and docbook. --- src/docbookgen.cpp | 10 ++++++++-- src/htmlgen.cpp | 35 +++++++++++++++++++++++++++++++---- src/htmlgen.h | 4 ++-- src/rtfgen.cpp | 21 +++++++++++++++++++++ src/rtfgen.h | 6 +++--- 5 files changed, 65 insertions(+), 11 deletions(-) diff --git a/src/docbookgen.cpp b/src/docbookgen.cpp index c6bd1c0..7fe849a 100644 --- a/src/docbookgen.cpp +++ b/src/docbookgen.cpp @@ -185,7 +185,7 @@ void DocbookCodeGenerator::startCodeLine(bool) } void DocbookCodeGenerator::endCodeLine() { - m_t << endl; + if (m_insideCodeLine) m_t << endl; Docbook_DB(("(endCodeLine)\n")); m_lineNumber = -1; m_refId.resize(0); @@ -243,7 +243,7 @@ void DocbookCodeGenerator::addWord(const char *,bool) } void DocbookCodeGenerator::finish() { - if (m_insideCodeLine) endCodeLine(); + endCodeLine(); } void DocbookCodeGenerator::startCodeFragment() { @@ -251,6 +251,9 @@ void DocbookCodeGenerator::startCodeFragment() } void DocbookCodeGenerator::endCodeFragment() { + //endCodeLine checks is there is still an open code line, if so closes it. + endCodeLine(); + m_t << "" << endl; } @@ -1007,6 +1010,9 @@ DB_GEN_C void DocbookGenerator::endCodeFragment() { DB_GEN_C + //endCodeLine checks is there is still an open code line, if so closes it. + endCodeLine(); + t << ""; } void DocbookGenerator::startMemberTemplateParams() diff --git a/src/htmlgen.cpp b/src/htmlgen.cpp index d25dafc..b3abd09 100644 --- a/src/htmlgen.cpp +++ b/src/htmlgen.cpp @@ -57,6 +57,7 @@ static QCString g_header; static QCString g_footer; static QCString g_mathjax_code; +static bool DoxyCodeLineOpen = FALSE; // note: this is only active if DISABLE_INDEX=YES, if DISABLE_INDEX is disabled, this // part will be rendered inside menu.js @@ -530,7 +531,12 @@ void HtmlCodeGenerator::writeLineNumber(const char *ref,const char *filename, qsnprintf(lineNumber,maxLineNrStr,"%5d",l); qsnprintf(lineAnchor,maxLineNrStr,"l%05d",l); - m_t << "
"; + if (!DoxyCodeLineOpen) + { + m_t << "
"; + DoxyCodeLineOpen = TRUE; + } + m_t << ""; if (filename) { @@ -661,12 +667,16 @@ void HtmlCodeGenerator::writeTooltip(const char *id, const DocLinkInfo &docInfo, } -void HtmlCodeGenerator::startCodeLine(bool hasLineNumbers) +void HtmlCodeGenerator::startCodeLine(bool) { if (m_streamSet) { - if (!hasLineNumbers) m_t << "
"; m_col=0; + if (!DoxyCodeLineOpen) + { + m_t << "
"; + DoxyCodeLineOpen = TRUE; + } } } @@ -679,7 +689,11 @@ void HtmlCodeGenerator::endCodeLine() m_t << " "; m_col++; } - m_t << "
"; + if (DoxyCodeLineOpen) + { + m_t << "
\n"; + DoxyCodeLineOpen = FALSE; + } } } @@ -2640,6 +2654,19 @@ void HtmlGenerator::endConstraintList() t << "
" << endl; } +void HtmlGenerator::startCodeFragment() +{ + t << PREFRAG_START; +} + +void HtmlGenerator::endCodeFragment() +{ + //endCodeLine checks is there is still an open code line, if so closes it. + endCodeLine(); + + t << PREFRAG_END; +} + void HtmlGenerator::lineBreak(const char *style) { if (style) diff --git a/src/htmlgen.h b/src/htmlgen.h index ebecc81..2db5b74 100644 --- a/src/htmlgen.h +++ b/src/htmlgen.h @@ -212,8 +212,8 @@ class HtmlGenerator : public OutputGenerator void writeRuler() { t << "
"; } void writeAnchor(const char *,const char *name) { t << ""; } - void startCodeFragment() { t << PREFRAG_START; } - void endCodeFragment() { t << PREFRAG_END; } + void startCodeFragment(); + void endCodeFragment(); void startEmphasis() { t << ""; } void endEmphasis() { t << ""; } void startBold() { t << ""; } diff --git a/src/rtfgen.cpp b/src/rtfgen.cpp index 8139784..2f24ca7 100644 --- a/src/rtfgen.cpp +++ b/src/rtfgen.cpp @@ -48,6 +48,8 @@ #include "filename.h" #include "namespacedef.h" +static bool DoxyCodeLineOpen = FALSE; + //#define DBG_RTF(x) x; #define DBG_RTF(x) @@ -1952,6 +1954,9 @@ void RTFGenerator::endCodeFragment() //styleStack.pop(); //printf("RTFGenerator::endCodeFrament() top=%s\n",styleStack.top()); //t << rtf_Style_Reset << styleStack.top() << endl; + //endCodeLine checks is there is still an open code line, if so closes it. + endCodeLine(); + DBG_RTF(t << "{\\comment (endCodeFragment) }" << endl) t << "}" << endl; m_omitParagraph = TRUE; @@ -3041,6 +3046,22 @@ void RTFGenerator::endInlineMemberDoc() t << "\\cell }{\\row }" << endl; } +void RTFGenerator::writeLineNumber(const char *,const char *,const char *,int l) +{ + DoxyCodeLineOpen = TRUE; + t << QString("%1").arg(l,5) << " "; +} +void RTFGenerator::startCodeLine(bool) +{ + DoxyCodeLineOpen = TRUE; + col=0; +} +void RTFGenerator::endCodeLine() +{ + if (DoxyCodeLineOpen) lineBreak(); + DoxyCodeLineOpen = FALSE; +} + void RTFGenerator::startLabels() { } diff --git a/src/rtfgen.h b/src/rtfgen.h index fe3e753..b5f06f0 100644 --- a/src/rtfgen.h +++ b/src/rtfgen.h @@ -127,9 +127,9 @@ class RTFGenerator : public OutputGenerator void writeAnchor(const char *fileName,const char *name); void startCodeFragment(); void endCodeFragment(); - void writeLineNumber(const char *,const char *,const char *,int l) { t << QString("%1").arg(l,5) << " "; } - void startCodeLine(bool) { col=0; } - void endCodeLine() { lineBreak(); } + void writeLineNumber(const char *,const char *,const char *,int l); + void startCodeLine(bool); + void endCodeLine(); void startEmphasis() { t << "{\\i "; } void endEmphasis() { t << "}"; } void startBold() { t << "{\\b "; } -- cgit v0.12