From 8625ec5da0a505caf2dcfd16a5a8c1e668633ca8 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Mon, 27 May 2019 21:42:14 +0200 Subject: Bug 757574 - Warning regarding subsection with anchor in markdown --- src/markdown.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/markdown.cpp b/src/markdown.cpp index 87d2c01..c73324a 100644 --- a/src/markdown.cpp +++ b/src/markdown.cpp @@ -1289,7 +1289,7 @@ static QCString extractTitleId(QCString &title, int level) static int isAtxHeader(const char *data,int size, - QCString &header,QCString &id) + QCString &header,QCString &id,bool allowAdjustLevel) { int i = 0, end; int level = 0, blanks=0; @@ -1322,6 +1322,28 @@ static int isAtxHeader(const char *data,int size, header=header.left(i+1); } + if (allowAdjustLevel && level==1 && g_indentLevel==-1) + { + // in case we find a `# Section` on a markdown page that started with the same level + // header, we no longer need to artificially decrease the paragraph level. + // So both + // ------------------- + // # heading 1 <-- here we set g_indentLevel to -1 + // # heading 2 <-- here we set g_indentLevel back to 0 such that this will be a @section + // ------------------- + // and + // ------------------- + // # heading 1 <-- here we set g_indentLevel to -1 + // ## heading 2 <-- here we keep g_indentLevel at -1 such that @subsection will be @section + // ------------------- + // will convert to + // ------------------- + // @page md_page Heading 1 + // @section autotoc_md1 Heading 2 + // ------------------- + + g_indentLevel=0; + } return level+g_indentLevel; } @@ -1907,7 +1929,7 @@ void writeOneLineHeaderOrRuler(GrowBuf &out,const char *data,int size) { out.addStr("\n
\n"); } - else if ((level=isAtxHeader(data,size,header,id))) + else if ((level=isAtxHeader(data,size,header,id,TRUE))) { QCString hTag; if (level<5 && !id.isEmpty()) @@ -2403,7 +2425,7 @@ static QCString extractPageTitle(QCString &docs,QCString &id) return title; } } - if (i0) + if (i0) { docs=docs.mid(end1); } -- cgit v0.12