@@ -3486,11 +3486,14 @@ void HtmlGenerator::writeLocalToc(const SectionRefs §ionRefs,const LocalToc
34863486{
34873487 if (localToc.isHtmlEnabled ())
34883488 {
3489- int maxLevel = localToc.htmlLevel ();
3489+ int level=0 ;
3490+ int indent=0 ;
3491+ auto writeIndent = [&]() { for (int i=0 ;i<indent*2 ;i++) m_t << " " ; };
3492+ auto incIndent = [&](const QCString &text) { writeIndent (); m_t << text << " \n " ; indent++; };
3493+ auto decIndent = [&](const QCString &text) { indent--; writeIndent (); m_t << text << " \n " ; };
34903494 m_t << " <div class=\" toc\" >" ;
34913495 m_t << " <h3>" << theTranslator->trRTFTableOfContents () << " </h3>\n " ;
3492- m_t << " <ul>" ;
3493- int level=1 ;
3496+ int maxLevel = localToc.htmlLevel ();
34943497 char cs[2 ];
34953498 cs[1 ]=' \0 ' ;
34963499 BoolVector inLi (maxLevel+1 ,false );
@@ -3506,50 +3509,54 @@ void HtmlGenerator::writeLocalToc(const SectionRefs §ionRefs,const LocalToc
35063509 {
35073510 for (int l=level;l<nextLevel;l++)
35083511 {
3509- if (l < maxLevel) m_t << " <ul>" ;
3512+ if (l < maxLevel)
3513+ {
3514+ incIndent (" <ul>" );
3515+ cs[0 ]=static_cast <char >(' 0' +l+1 );
3516+ incIndent (" <li class=\" level" + QCString (cs) + " \" >" );
3517+ }
35103518 }
35113519 }
35123520 else if (nextLevel<level)
35133521 {
35143522 for (int l=level;l>nextLevel;l--)
35153523 {
3516- if (l <= maxLevel && inLi[l]) m_t << " </li>\n " ;
3517- inLi[l]= false ;
3518- if (l <= maxLevel) m_t << " </ul>\n " ;
3524+ if (l <= maxLevel) decIndent ( " </li>" ) ;
3525+ inLi[nextLevel] = false ;
3526+ if (l <= maxLevel) decIndent ( " </ul>" ) ;
35193527 }
35203528 }
3521- cs[0 ]=static_cast <char >(' 0' +nextLevel);
3522- if (nextLevel <= maxLevel && inLi[nextLevel])
3523- {
3524- m_t << " </li>\n " ;
3525- }
3526- QCString titleDoc = si->title ();
3527- QCString label = si->label ();
3528- if (titleDoc.isEmpty ()) titleDoc = label;
35293529 if (nextLevel <= maxLevel)
35303530 {
3531- m_t << " <li class=\" level" +QCString (cs)+" \" >"
3532- << " <a href=\" #" +label+" \" >"
3533- << convertToHtml (filterTitle (titleDoc))
3534- << " </a>" ;
3531+ if (inLi[nextLevel] || level>nextLevel)
3532+ {
3533+ decIndent (" </li>" );
3534+ cs[0 ]=static_cast <char >(' 0' +nextLevel);
3535+ incIndent (" <li class=\" level" + QCString (cs) + " \" >" );
3536+ }
3537+ QCString titleDoc = si->title ();
3538+ QCString label = si->label ();
3539+ if (titleDoc.isEmpty ()) titleDoc = label;
3540+ writeIndent ();
3541+ m_t << " <a href=\" #" +label+" \" >"
3542+ << convertToHtml (filterTitle (titleDoc))
3543+ << " </a>\n " ;
3544+ inLi[nextLevel]=true ;
3545+ level = nextLevel;
35353546 }
3536- inLi[nextLevel]=true ;
3537- level = nextLevel;
35383547 }
35393548 }
35403549 if (level > maxLevel) level = maxLevel;
35413550 while (level>1 && level <= maxLevel)
35423551 {
3543- if (inLi[level])
3544- {
3545- m_t << " </li>\n " ;
3546- }
3547- inLi[level]=FALSE ;
3548- m_t << " </ul>\n " ;
3552+ if (inLi[level]) decIndent (" </li>" );
3553+ inLi[level]=false ;
3554+ decIndent (" </li>" );
3555+ decIndent (" </ul>" );
35493556 level--;
35503557 }
3551- if (level <= maxLevel && inLi[level]) m_t << " </li>\n " ;
3552- m_t << " </ul>\n " ;
3558+ if (level <= maxLevel && inLi[level]) decIndent ( " </li>" ) ;
3559+ decIndent ( " </ul>" ) ;
35533560 m_t << " </div>\n " ;
35543561 }
35553562}
0 commit comments