From a8b46600830be24ac189f798a1915f0ad1b86beb Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Sun, 2 Jun 2019 12:34:13 +0200 Subject: Bug 757574 - Warning regarding subsection with anchor in markdown --- src/markdown.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/markdown.cpp b/src/markdown.cpp index c73324a..15f119b 100644 --- a/src/markdown.cpp +++ b/src/markdown.cpp @@ -1097,7 +1097,7 @@ static void processInline(GrowBuf &out,const char *data,int size) } /** returns whether the line is a setext-style hdr underline */ -static int isHeaderline(const char *data, int size) +static int isHeaderline(const char *data, int size, bool allowAdjustLevel) { int i=0, c=0; while (i1 && (i>=size || data[i]=='\n')) ? g_indentLevel+1 : 0; + int level = (c>1 && (i>=size || data[i]=='\n')) ? 1 : 0; + if (allowAdjustLevel && level==1 && g_indentLevel==-1) + { + // In case a page starts with a header line we use it as title, promoting it to @page. + // We set g_indentLevel to -1 to promoting the other sections if they have a deeper + // nesting level than the page header, i.e. @section..@subsection becomes @page..@section. + // In case a section at the same level is found (@section..@section) however we need + // to undo this (and the result will be @page..@section). + g_indentLevel=0; + } + return g_indentLevel+level; } // test of level 2 header if (data[i]=='-') @@ -2272,7 +2282,7 @@ static QCString processBlocks(const QCString &s,int indent) QCString lang; blockIndent = indent; //printf("isHeaderLine(%s)=%d\n",QCString(data+i).left(size-i).data(),level); - if ((level=isHeaderline(data+i,size-i))>0) + if ((level=isHeaderline(data+i,size-i,TRUE))>0) { //printf("Found header at %d-%d\n",i,end); while (pi