Skip to content

Commit e3a5da5

Browse files
committed
issue doxygen#12113 Doxygen generates ill-formed XML when \p is at the end of a line
In case of an unclosed tag at the end of a comment block this was already handled but due to the adding of an artificial tag (In this case a pair `<em>` / `</em>` for the markdown handling of `*...*`) the matching of the tags was artificially corrupted. The later should not be the case. Now correct output is generated although a warning still is given (for the `</em>` tag but this is correct as here the usage of the markdown replacement is not correct).
1 parent d81868b commit e3a5da5

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/docparser.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ Token DocParser::handleStyleArgument(DocNodeVariant *parent,DocNodeList &childre
627627
AUTO_TRACE("cmdName={}",cmdName);
628628
QCString saveCmdName = cmdName;
629629
Token tok=tokenizer.lex();
630+
auto siz = context.styleStack.size();
630631
if (!tok.is(TokenRetval::TK_WHITESPACE))
631632
{
632633
warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after \\{} command",
@@ -643,6 +644,7 @@ Token DocParser::handleStyleArgument(DocNodeVariant *parent,DocNodeList &childre
643644
reg::match(context.token->name.str(),specialChar))
644645
{
645646
// special character that ends the markup command
647+
if (siz != context.styleStack.size()) handlePendingStyleCommands(parent,children,siz);
646648
return tok;
647649
}
648650
if (!defaultHandleToken(parent,tok,children))
@@ -738,17 +740,25 @@ void DocParser::handleStyleLeave(DocNodeVariant *parent,DocNodeList &children,
738740
* (e.g. a <b> without a </b>). The closed styles are pushed onto a stack
739741
* and entered again at the start of a new paragraph.
740742
*/
741-
void DocParser::handlePendingStyleCommands(DocNodeVariant *parent,DocNodeList &children)
743+
void DocParser::handlePendingStyleCommands(DocNodeVariant *parent,DocNodeList &children, int oldStackSize)
742744
{
743745
AUTO_TRACE();
744746
if (!context.styleStack.empty())
745747
{
748+
int locOldStackSize = (oldStackSize==-1?0:context.styleStack.size() - oldStackSize);
746749
const DocStyleChange *sc = &std::get<DocStyleChange>(*context.styleStack.top());
747750
while (sc && sc->position()>=context.nodeStack.size())
748751
{ // there are unclosed style modifiers in the paragraph
749752
children.append<DocStyleChange>(this,parent,context.nodeStack.size(),
750753
sc->style(),sc->tagName(),FALSE);
751-
context.initialStyleStack.push(context.styleStack.top());
754+
if (locOldStackSize)
755+
{
756+
locOldStackSize--;
757+
}
758+
else
759+
{
760+
context.initialStyleStack.push(context.styleStack.top());
761+
}
752762
context.styleStack.pop();
753763
sc = !context.styleStack.empty() ? &std::get<DocStyleChange>(*context.styleStack.top()) : nullptr;
754764
}

src/docparser_p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class DocParser : public IDocParser
134134
const QCString &tagName,const HtmlAttribList *attribs);
135135
void handleStyleLeave(DocNodeVariant *parent,DocNodeList &children, DocStyleChange::Style s,
136136
const QCString &tagName);
137-
void handlePendingStyleCommands(DocNodeVariant *parent,DocNodeList &children);
137+
void handlePendingStyleCommands(DocNodeVariant *parent,DocNodeList &children, int oldStackSize = -1);
138138
void handleInitialStyleCommands(DocNodeVariant *parent,DocNodeList &children);
139139
Token handleAHref(DocNodeVariant *parent,DocNodeList &children,const HtmlAttribList &tagHtmlAttribs);
140140
void handleUnclosedStyleCommands();

0 commit comments

Comments
 (0)