Skip to content

Commit 62d9e0f

Browse files
committed
Various fixes to better support 6 levels of sections
1 parent 987a8c3 commit 62d9e0f

File tree

9 files changed

+48
-23
lines changed

9 files changed

+48
-23
lines changed

src/commentcnv.l

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ typedef yyguts_t *yyscan_t;
4444
#include "fileinfo.h"
4545
#include "stringutil.h"
4646
#include "regex.h"
47+
#include "section.h"
4748

4849
#include <assert.h>
4950

@@ -1303,13 +1304,12 @@ static void parseIncludeOptions(yyscan_t yyscanner,std::string_view s)
13031304
reg::Match match;
13041305
if (reg::search(s,match,re))
13051306
{
1306-
const int maxLevel = 6;
13071307
yyextra->raiseIncrement = atoi(match[1].str().c_str());
1308-
if (yyextra->raiseLevel+yyextra->raiseIncrement>maxLevel) // check range
1308+
if (yyextra->raiseLevel+yyextra->raiseIncrement>=Section::MaxLevel) // check range
13091309
{
1310-
warn(yyextra->fileName,yyextra->lineNr,"Raising section level from %d to %d, exceeds allowed range [0-5], adjusting",
1311-
yyextra->raiseLevel,yyextra->raiseLevel+yyextra->raiseIncrement);
1312-
yyextra->raiseIncrement = std::max(0,maxLevel-yyextra->raiseLevel);
1310+
warn(yyextra->fileName,yyextra->lineNr,"Raising section level from %d to %d, exceeds allowed range [0-%d], adjusting",
1311+
yyextra->raiseLevel,yyextra->raiseLevel+yyextra->raiseIncrement,Section::MaxLevel-1);
1312+
yyextra->raiseIncrement = std::max(0,Section::MaxLevel-1-yyextra->raiseLevel);
13131313
}
13141314
}
13151315
}

src/commentscan.l

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,6 +2430,20 @@ STopt [^\n@\\]*
24302430
BEGIN(Comment);
24312431
}
24322432
}
2433+
<SkipInternal>[@\\]/"subparagraph"[ \t] {
2434+
if (yyextra->sectionLevel>4)
2435+
{
2436+
unput('\\');
2437+
BEGIN(Comment);
2438+
}
2439+
}
2440+
<SkipInternal>[@\\]/"subsubparagraph"[ \t] {
2441+
if (yyextra->sectionLevel>5)
2442+
{
2443+
unput('\\');
2444+
BEGIN(Comment);
2445+
}
2446+
}
24332447
<SkipInternal>[@\\]"endinternal"[ \t]* {
24342448
BEGIN(Comment);
24352449
}
@@ -3188,7 +3202,7 @@ static bool handleSection(yyscan_t yyscanner,const QCString &s, const StringVect
31883202
else if (s=="subparagraph") yyextra->sectionLevel=5;
31893203
else if (s=="subsubparagraph") yyextra->sectionLevel=6;
31903204
// raise it if requested
3191-
yyextra->sectionLevel = std::min(yyextra->sectionLevel + yyextra->raiseLevel,6);
3205+
yyextra->sectionLevel = std::min(yyextra->sectionLevel + yyextra->raiseLevel,Section::MaxLevel);
31923206
// rewrite the update section level to the output
31933207
switch (yyextra->sectionLevel)
31943208
{
@@ -3885,7 +3899,7 @@ static bool handleToc(yyscan_t yyscanner,const QCString &, const StringVector &o
38853899
{
38863900
QCString opt = QCString(opt_).stripWhiteSpace().lower();
38873901
char dum;
3888-
int level = 5;
3902+
int level = Section::MaxLevel;
38893903
int i = opt.find(':');
38903904
if (i>0) // found ':' but not on position 0 what would mean just a level
38913905
{
@@ -3896,8 +3910,7 @@ static bool handleToc(yyscan_t yyscanner,const QCString &, const StringVector &o
38963910
}
38973911
else
38983912
{
3899-
level = (level > 5 ? 5 : level);
3900-
level = (level <= 0 ? 5 : level);
3913+
level = level<=0 ? Section::MaxLevel : std::min(level,Section::MaxLevel);
39013914
opt = opt.left(i).stripWhiteSpace();
39023915
}
39033916
}
@@ -3928,8 +3941,8 @@ static bool handleToc(yyscan_t yyscanner,const QCString &, const StringVector &o
39283941
if (yyextra->current->localToc.nothingEnabled())
39293942
{
39303943
// for backward compatibility
3931-
yyextra->current->localToc.enableHtml(5);
3932-
yyextra->current->localToc.enableXml(5);
3944+
yyextra->current->localToc.enableHtml(Section::MaxLevel);
3945+
yyextra->current->localToc.enableXml(Section::MaxLevel);
39333946
}
39343947
}
39353948
return FALSE;

src/doctokenizer.l

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,10 @@ SHOWDATE ([0-9]{4}"-"[0-9]{1,2}"-"[0-9]{1,2})?({WS}*[0-9]{1,2}":"[0-9]{1,2}(":"[
14401440
yyextra->secType = SectionType::Subparagraph;
14411441
BEGIN(St_SecLabel2);
14421442
}
1443+
<St_Sections>{CMD}"subsubparagraph"{BLANK}+ {
1444+
yyextra->secType = SectionType::Subsubparagraph;
1445+
BEGIN(St_SecLabel2);
1446+
}
14431447
<St_Sections>{CMD}"verbatim"/[^a-z_A-Z0-9] {
14441448
yyextra->endMarker="endverbatim";
14451449
BEGIN(St_SecSkip);

src/htmlgen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3499,10 +3499,11 @@ void HtmlGenerator::writeLocalToc(const SectionRefs &sectionRefs,const LocalToc
34993499
BoolVector inLi(maxLevel+1,false);
35003500
for (const SectionInfo *si : sectionRefs)
35013501
{
3502+
//printf("Section: label=%s type=%d isSection()=%d\n",qPrint(si->label()),si->type(),isSection(si->type()));
35023503
SectionType type = si->type();
35033504
if (isSection(type))
35043505
{
3505-
//printf(" level=%d title=%s\n",level,qPrint(si->title));
3506+
//printf(" level=%d title=%s maxLevel=%d\n",level,qPrint(si->title()),maxLevel);
35063507
int nextLevel = static_cast<int>(type);
35073508
if (nextLevel>level)
35083509
{

src/markdown.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,7 @@ int Markdown::Private::processLink(const std::string_view data,size_t offset)
14451445
if (isToc) // special case for [TOC]
14461446
{
14471447
int toc_level = Config_getInt(TOC_INCLUDE_HEADINGS);
1448-
if (toc_level>0 && toc_level<=5)
1448+
if (toc_level>0 && toc_level<=Section::MaxLevel)
14491449
{
14501450
out+="@tableofcontents{html:";
14511451
out+=QCString().setNum(toc_level);

src/rtfdocvisitor.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,9 +1147,7 @@ void RTFDocVisitor::operator()(const DocHtmlHeader &header)
11471147
m_t << "{" // start section
11481148
<< rtf_Style_Reset;
11491149
QCString heading;
1150-
int level = std::min(header.level()+m_hierarchyLevel,5);
1151-
if (level <= 0)
1152-
level = 1;
1150+
int level = std::clamp(header.level()+m_hierarchyLevel,1,Section::MaxLevel);
11531151
heading.sprintf("Heading%d",level);
11541152
// set style
11551153
m_t << rtf_Style[heading.str()].reference();

src/rtfstyle.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,13 @@ Rtf_Style_Default rtf_Style_Default[] =
104104
"\\sbasedon0 \\snext0 heading 4;}{\\*\\cs10 \\additive Default Paragraph Font"
105105
},
106106
{ "Heading5",
107-
"\\s5\\sb90\\sa30\\keepn\\widctlpar\\adjustright \\b\\f1\\fs20\\cgrid ",
107+
"\\s5\\sb90\\sa30\\keepn\\widctlpar\\adjustright \\b\\f1\\fs16\\cgrid ",
108108
"\\sbasedon0 \\snext0 heading 5;}{\\*\\cs10 \\additive Default Paragraph Font"
109109
},
110+
{ "Heading6",
111+
"\\s5\\sb90\\sa30\\keepn\\widctlpar\\adjustright \\b\\f1\\fs12\\cgrid ",
112+
"\\sbasedon0 \\snext0 heading 6;}{\\*\\cs10 \\additive Default Paragraph Font"
113+
},
110114
{ "Title",
111115
"\\s15\\qc\\sb240\\sa60\\widctlpar\\outlinelevel0\\adjustright \\b\\f1\\fs32\\kerning28\\cgrid ",
112116
"\\sbasedon0 \\snext15 Title"

src/section.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424

2525
class Definition;
2626

27+
namespace Section
28+
{
29+
const int MaxLevel = 6;
30+
}
31+
2732
//! enum representing the various types of sections and entities that can be referred to.
2833
enum class SectionType
2934
{
@@ -33,7 +38,7 @@ enum class SectionType
3338
Subsubsection = 3,
3439
Paragraph = 4,
3540
Subparagraph = 5,
36-
Subsubparagraph = 6,
41+
Subsubparagraph = Section::MaxLevel, // =6
3742
Anchor = 7,
3843
Table = 8
3944
};

src/xmlgen.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,8 +2008,8 @@ static void generateXMLForPage(PageDef *pd,TextStream &ti,bool isExample)
20082008
{
20092009
t << " <tableofcontents>\n";
20102010
int level=1,l;
2011-
bool inLi[5]={ FALSE, FALSE, FALSE, FALSE, FALSE };
20122011
int maxLevel = pd->localToc().xmlLevel();
2012+
BoolVector inLi(maxLevel+1,false);
20132013
for (const SectionInfo *si : sectionRefs)
20142014
{
20152015
if (isSection(si->type()))
@@ -2028,7 +2028,7 @@ static void generateXMLForPage(PageDef *pd,TextStream &ti,bool isExample)
20282028
for (l=level;l>nextLevel;l--)
20292029
{
20302030
if (l <= maxLevel && inLi[l]) t << " </tocsect>\n";
2031-
inLi[l]=FALSE;
2031+
inLi[l]=false;
20322032
if (l <= maxLevel) t << " </tableofcontents>\n";
20332033
}
20342034
}
@@ -2041,20 +2041,20 @@ static void generateXMLForPage(PageDef *pd,TextStream &ti,bool isExample)
20412041
t << " <tocsect>\n";
20422042
t << " <name>" << titleDoc << "</name>\n";
20432043
t << " <reference>" << convertToXML(pageName) << "_1" << label << "</reference>\n";
2044-
inLi[nextLevel]=TRUE;
2044+
inLi[nextLevel]=true;
20452045
level = nextLevel;
20462046
}
20472047
}
20482048
}
20492049
while (level>1 && level <= maxLevel)
20502050
{
20512051
if (inLi[level]) t << " </tocsect>\n";
2052-
inLi[level]=FALSE;
2052+
inLi[level]=false;
20532053
t << " </tableofcontents>\n";
20542054
level--;
20552055
}
20562056
if (level <= maxLevel && inLi[level]) t << " </tocsect>\n";
2057-
inLi[level]=FALSE;
2057+
inLi[level]=false;
20582058
t << " </tableofcontents>\n";
20592059
}
20602060
t << " <briefdescription>\n";

0 commit comments

Comments
 (0)