From f923f26d602fd991577b7a6676d129bd1642f453 Mon Sep 17 00:00:00 2001 From: albert-github Date: Sat, 24 Nov 2018 18:18:01 +0100 Subject: Incorrect number of start / end paragraph tags for xhtml with htmlonly In case of `\htmlonly[block]` the a force closed paragraph is not always force opened again. Problem can be seen with the default doxygen test 20 (`[020_only.dox]: test the \*only and \*endonly commands`). --- src/htmldocvisitor.cpp | 33 +++++++++++++++++++-------------- src/htmldocvisitor.h | 4 ++-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/htmldocvisitor.cpp b/src/htmldocvisitor.cpp index ba10ca1..e1ac6d6 100644 --- a/src/htmldocvisitor.cpp +++ b/src/htmldocvisitor.cpp @@ -444,9 +444,12 @@ void HtmlDocVisitor::visit(DocVerbatim *s) forceStartParagraph(s); break; case DocVerbatim::HtmlOnly: - if (s->isBlock()) forceEndParagraph(s); - m_t << s->text(); - if (s->isBlock()) forceStartParagraph(s); + { + bool forced = false; + if (s->isBlock()) forced = forceEndParagraph(s); + m_t << s->text(); + if (s->isBlock()) forceStartParagraph(s, forced); + } break; case DocVerbatim::ManOnly: case DocVerbatim::LatexOnly: @@ -2277,7 +2280,7 @@ static bool insideStyleChangeThatIsOutsideParagraph(DocPara *para,int nodeIndex) * have to be outside of the paragraph. This method will forcefully end * the current paragraph and forceStartParagraph() will restart it. */ -void HtmlDocVisitor::forceEndParagraph(DocNode *n) +bool HtmlDocVisitor::forceEndParagraph(DocNode *n) { //printf("forceEndParagraph(%p) %d\n",n,n->kind()); if (n->parent() && n->parent()->kind()==DocNode::Kind_Para) @@ -2285,7 +2288,7 @@ void HtmlDocVisitor::forceEndParagraph(DocNode *n) DocPara *para = (DocPara*)n->parent(); int nodeIndex = para->children().findRef(n); nodeIndex--; - if (nodeIndex<0) return; // first node + if (nodeIndex<0) return false; // first node while (nodeIndex>=0 && para->children().at(nodeIndex)->kind()==DocNode::Kind_WhiteSpace ) @@ -2296,7 +2299,7 @@ void HtmlDocVisitor::forceEndParagraph(DocNode *n) { DocNode *n = para->children().at(nodeIndex); //printf("n=%p kind=%d outside=%d\n",n,n->kind(),mustBeOutsideParagraph(n)); - if (mustBeOutsideParagraph(n)) return; + if (mustBeOutsideParagraph(n)) return false; } nodeIndex--; bool styleOutsideParagraph=insideStyleChangeThatIsOutsideParagraph(para,nodeIndex); @@ -2304,18 +2307,20 @@ void HtmlDocVisitor::forceEndParagraph(DocNode *n) bool isLast; getParagraphContext(para,isFirst,isLast); //printf("forceEnd first=%d last=%d styleOutsideParagraph=%d\n",isFirst,isLast,styleOutsideParagraph); - if (isFirst && isLast) return; - if (styleOutsideParagraph) return; + if (isFirst && isLast) return false; + if (styleOutsideParagraph) return false; m_t << "

"; + return true; } + return false; } /** Used for items found inside a paragraph, which due to XHTML restrictions * have to be outside of the paragraph. This method will forcefully start * the paragraph, that was previously ended by forceEndParagraph(). */ -void HtmlDocVisitor::forceStartParagraph(DocNode *n) +void HtmlDocVisitor::forceStartParagraph(DocNode *n, bool forced) { //printf("forceStartParagraph(%p) %d\n",n,n->kind()); if (n->parent() && n->parent()->kind()==DocNode::Kind_Para) // if we are inside a paragraph @@ -2324,9 +2329,9 @@ void HtmlDocVisitor::forceStartParagraph(DocNode *n) int nodeIndex = para->children().findRef(n); int numNodes = para->children().count(); bool styleOutsideParagraph=insideStyleChangeThatIsOutsideParagraph(para,nodeIndex); - if (styleOutsideParagraph) return; + if (!forced && styleOutsideParagraph) return; nodeIndex++; - if (nodeIndex==numNodes) return; // last node + if (!forced && nodeIndex==numNodes) return; // last node while (nodeIndexchildren().at(nodeIndex)->kind()==DocNode::Kind_WhiteSpace ) @@ -2336,9 +2341,9 @@ void HtmlDocVisitor::forceStartParagraph(DocNode *n) if (nodeIndexchildren().at(nodeIndex); - if (mustBeOutsideParagraph(n)) return; + if (!forced && mustBeOutsideParagraph(n)) return; } - else + else if (!forced) { return; // only whitespace at the end! } @@ -2348,7 +2353,7 @@ void HtmlDocVisitor::forceStartParagraph(DocNode *n) bool isLast; getParagraphContext(para,isFirst,isLast); //printf("forceStart first=%d last=%d\n",isFirst,isLast); - if (isFirst && isLast) needsTag = FALSE; + if (!forced && isFirst && isLast) needsTag = FALSE; if (needsTag) m_t << ""; diff --git a/src/htmldocvisitor.h b/src/htmldocvisitor.h index 7184f0f..2f57739 100644 --- a/src/htmldocvisitor.h +++ b/src/htmldocvisitor.h @@ -159,8 +159,8 @@ class HtmlDocVisitor : public DocVisitor void pushEnabled(); void popEnabled(); - void forceEndParagraph(DocNode *n); - void forceStartParagraph(DocNode *n); + bool forceEndParagraph(DocNode *n); + void forceStartParagraph(DocNode *n, bool forced = false); //-------------------------------------- // state variables -- cgit v0.12