@@ -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+ size_t styleStackSizeAtStart = context.styleStack .size ();
630631 if (!tok.is (TokenRetval::TK_WHITESPACE ))
631632 {
632633 warn_doc_error (context.fileName ,tokenizer.getLineNr ()," expected whitespace after \\ {} command" ,
@@ -643,7 +644,11 @@ Token DocParser::handleStyleArgument(DocNodeVariant *parent,DocNodeList &childre
643644 reg::match (context.token ->name .str (),specialChar))
644645 {
645646 // special character that ends the markup command
646- AUTO_TRACE_ADD (" special character ending style argument: '{}'" ,context.token ->name );
647+ AUTO_TRACE_ADD (" special character ending style argument: '{}' styleStackSize {}->{}" ,context.token ->name ,styleStackSizeAtStart,context.styleStack .size ());
648+ if (context.styleStack .size () > styleStackSizeAtStart) // new styles opened inside command, but not closed
649+ {
650+ handlePendingStyleCommands (parent,children,context.styleStack .size ()-styleStackSizeAtStart);
651+ }
647652 return tok;
648653 }
649654 if (!defaultHandleToken (parent,tok,children))
@@ -739,9 +744,9 @@ void DocParser::handleStyleLeave(DocNodeVariant *parent,DocNodeList &children,
739744 * (e.g. a <b> without a </b>). The closed styles are pushed onto a stack
740745 * and entered again at the start of a new paragraph.
741746 */
742- void DocParser::handlePendingStyleCommands (DocNodeVariant *parent,DocNodeList &children)
747+ void DocParser::handlePendingStyleCommands (DocNodeVariant *parent,DocNodeList &children, size_t numberOfElementsNotToRestore )
743748{
744- AUTO_TRACE (" context.styleStack.size()={}" ,context.styleStack .size ());
749+ AUTO_TRACE (" context.styleStack.size()={} numberOfElementsNotToRestore={} " ,context.styleStack .size (),numberOfElementsNotToRestore );
745750 if (!context.styleStack .empty ())
746751 {
747752 const DocStyleChange *sc = &std::get<DocStyleChange>(*context.styleStack .top ());
@@ -750,7 +755,14 @@ void DocParser::handlePendingStyleCommands(DocNodeVariant *parent,DocNodeList &c
750755 AUTO_TRACE_ADD (" unclosed style at position {}" ,sc->position ());
751756 children.append <DocStyleChange>(this ,parent,context.nodeStack .size (),
752757 sc->style (),sc->tagName (),FALSE );
753- context.initialStyleStack .push (context.styleStack .top ());
758+ if (numberOfElementsNotToRestore>0 )
759+ {
760+ numberOfElementsNotToRestore--;
761+ }
762+ else // style needs to be restored
763+ {
764+ context.initialStyleStack .push (context.styleStack .top ());
765+ }
754766 context.styleStack .pop ();
755767 sc = !context.styleStack .empty () ? &std::get<DocStyleChange>(*context.styleStack .top ()) : nullptr ;
756768 }
0 commit comments