@@ -744,27 +744,22 @@ void DocParser::handleStyleLeave(DocNodeVariant *parent,DocNodeList &children,
744744 * (e.g. a <b> without a </b>). The closed styles are pushed onto a stack
745745 * and entered again at the start of a new paragraph.
746746 */
747- void DocParser::handlePendingStyleCommands (DocNodeVariant *parent,DocNodeList &children, size_t numberOfElementsNotToRestore )
747+ void DocParser::handlePendingStyleCommands (DocNodeVariant *parent,DocNodeList &children, size_t numberOfElementsToClose )
748748{
749- AUTO_TRACE (" context.styleStack.size()={} numberOfElementsNotToRestore ={}" ,context.styleStack .size (),numberOfElementsNotToRestore );
749+ AUTO_TRACE (" context.styleStack.size()={} numberOfElementsToClose ={}" ,context.styleStack .size (),numberOfElementsToClose );
750750 if (!context.styleStack .empty ())
751751 {
752+ if (numberOfElementsToClose==0 ) numberOfElementsToClose = context.styleStack .size (); // 0 is special value for "close all"
752753 const DocStyleChange *sc = &std::get<DocStyleChange>(*context.styleStack .top ());
753- while (sc && sc->position ()>=context.nodeStack .size ())
754+ while (sc && sc->position ()>=context.nodeStack .size () && numberOfElementsToClose> 0 )
754755 { // there are unclosed style modifiers in the paragraph
755- AUTO_TRACE_ADD (" unclosed style at position {}" ,sc->position ());
756+ AUTO_TRACE_ADD (" unclosed style {} at position {}" ,sc-> styleString () ,sc->position ());
756757 children.append <DocStyleChange>(this ,parent,context.nodeStack .size (),
757758 sc->style (),sc->tagName (),FALSE );
758- if (numberOfElementsNotToRestore>0 )
759- {
760- numberOfElementsNotToRestore--;
761- }
762- else // style needs to be restored
763- {
764- context.initialStyleStack .push (context.styleStack .top ());
765- }
759+ context.initialStyleStack .push (context.styleStack .top ());
766760 context.styleStack .pop ();
767761 sc = !context.styleStack .empty () ? &std::get<DocStyleChange>(*context.styleStack .top ()) : nullptr ;
762+ numberOfElementsToClose--;
768763 }
769764 }
770765}
0 commit comments