Skip to content

Commit a8b4660

Browse files
committed
Bug 757574 - Warning regarding subsection with anchor in markdown
1 parent 7b745c4 commit a8b4660

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/markdown.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ static void processInline(GrowBuf &out,const char *data,int size)
10971097
}
10981098

10991099
/** returns whether the line is a setext-style hdr underline */
1100-
static int isHeaderline(const char *data, int size)
1100+
static int isHeaderline(const char *data, int size, bool allowAdjustLevel)
11011101
{
11021102
int i=0, c=0;
11031103
while (i<size && data[i]==' ') i++;
@@ -1107,7 +1107,17 @@ static int isHeaderline(const char *data, int size)
11071107
{
11081108
while (i<size && data[i]=='=') i++,c++;
11091109
while (i<size && data[i]==' ') i++;
1110-
return (c>1 && (i>=size || data[i]=='\n')) ? g_indentLevel+1 : 0;
1110+
int level = (c>1 && (i>=size || data[i]=='\n')) ? 1 : 0;
1111+
if (allowAdjustLevel && level==1 && g_indentLevel==-1)
1112+
{
1113+
// In case a page starts with a header line we use it as title, promoting it to @page.
1114+
// We set g_indentLevel to -1 to promoting the other sections if they have a deeper
1115+
// nesting level than the page header, i.e. @section..@subsection becomes @page..@section.
1116+
// In case a section at the same level is found (@section..@section) however we need
1117+
// to undo this (and the result will be @page..@section).
1118+
g_indentLevel=0;
1119+
}
1120+
return g_indentLevel+level;
11111121
}
11121122
// test of level 2 header
11131123
if (data[i]=='-')
@@ -2272,7 +2282,7 @@ static QCString processBlocks(const QCString &s,int indent)
22722282
QCString lang;
22732283
blockIndent = indent;
22742284
//printf("isHeaderLine(%s)=%d\n",QCString(data+i).left(size-i).data(),level);
2275-
if ((level=isHeaderline(data+i,size-i))>0)
2285+
if ((level=isHeaderline(data+i,size-i,TRUE))>0)
22762286
{
22772287
//printf("Found header at %d-%d\n",i,end);
22782288
while (pi<size && data[pi]==' ') pi++;
@@ -2414,7 +2424,7 @@ static QCString extractPageTitle(QCString &docs,QCString &id)
24142424
// second line form end1..end2
24152425
int end2=end1+1;
24162426
while (end2<size && data[end2-1]!='\n') end2++;
2417-
if (isHeaderline(data+end1,size-end1))
2427+
if (isHeaderline(data+end1,size-end1,FALSE))
24182428
{
24192429
convertStringFragment(title,data+i,end1-i-1);
24202430
QCString lns;

0 commit comments

Comments
 (0)