Skip to content

Commit

Permalink
Incorrect number of start / end paragraph tags for xhtml with htmlonly
Browse files Browse the repository at this point in the history
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`).
  • Loading branch information
albert-github committed Nov 24, 2018
1 parent 50879dd commit f923f26
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
33 changes: 19 additions & 14 deletions src/htmldocvisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -2277,15 +2280,15 @@ 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)
{
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
)
Expand All @@ -2296,26 +2299,28 @@ 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);
bool isFirst;
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 << "</p>";
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
Expand All @@ -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 (nodeIndex<numNodes &&
para->children().at(nodeIndex)->kind()==DocNode::Kind_WhiteSpace
)
Expand All @@ -2336,9 +2341,9 @@ void HtmlDocVisitor::forceStartParagraph(DocNode *n)
if (nodeIndex<numNodes)
{
DocNode *n = para->children().at(nodeIndex);
if (mustBeOutsideParagraph(n)) return;
if (!forced && mustBeOutsideParagraph(n)) return;
}
else
else if (!forced)
{
return; // only whitespace at the end!
}
Expand All @@ -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 << "<p" << getDirHtmlClassOfNode(getTextDirByConfig(para, nodeIndex)) << ">";
Expand Down
4 changes: 2 additions & 2 deletions src/htmldocvisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f923f26

Please sign in to comment.