Skip to content

Commit 1397b6e

Browse files
committed
Interaction between markdown blockquotes and sections
After review better determination of Atx header. Solved some corner cases as well ``` > text ##NO header ##Second test on no header ``` and ``` > text ## text ```
1 parent 4f3a4c5 commit 1397b6e

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/markdown.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ struct Markdown::Private
153153
const QCString &link, const QCString &attributes,
154154
const FileDef *fd);
155155
int isHeaderline(std::string_view data, bool allowAdjustLevel);
156+
int isAtxHeaderLevel(std::string_view data, size_t &i);
156157
int isAtxHeader(std::string_view data, QCString &header,QCString &id,bool allowAdjustLevel,
157158
bool *pIsIdGenerated=nullptr);
158159
void writeOneLineHeaderOrRuler(std::string_view data);
@@ -2028,16 +2029,11 @@ QCString Markdown::Private::extractTitleId(QCString &title, int level, bool *pIs
20282029
return "";
20292030
}
20302031

2031-
2032-
int Markdown::Private::isAtxHeader(std::string_view data,
2033-
QCString &header,QCString &id,bool allowAdjustLevel,bool *pIsIdGenerated)
2032+
// find start of header text and determine heading level
2033+
int Markdown::Private::isAtxHeaderLevel (std::string_view data, size_t &i)
20342034
{
2035-
AUTO_TRACE("data='{}' header={} id={} allowAdjustLevel={}",Trace::trunc(data),Trace::trunc(header),id,allowAdjustLevel);
2036-
size_t i = 0;
2037-
int level = 0, blanks=0;
20382035
const size_t size = data.size();
2039-
2040-
// find start of header text and determine heading level
2036+
int level = 0, blanks=0;
20412037
while (i<size && data[i]==' ') i++;
20422038
if (i>=size || data[i]!='#')
20432039
{
@@ -2049,11 +2045,24 @@ int Markdown::Private::isAtxHeader(std::string_view data,
20492045
return 0;
20502046
}
20512047
while (i<size && data[i]==' ') i++,blanks++;
2052-
if (level==1 && blanks==0)
2048+
if (level>=1 && blanks==0)
20532049
{
20542050
return 0; // special case to prevent #someid seen as a header (see bug 671395)
20552051
}
20562052

2053+
return level;
2054+
}
2055+
2056+
int Markdown::Private::isAtxHeader(std::string_view data,
2057+
QCString &header,QCString &id,bool allowAdjustLevel,bool *pIsIdGenerated)
2058+
{
2059+
AUTO_TRACE("data='{}' header={} id={} allowAdjustLevel={}",Trace::trunc(data),Trace::trunc(header),id,allowAdjustLevel);
2060+
size_t i = 0;
2061+
int level = 0;
2062+
const size_t size = data.size();
2063+
2064+
if (!(level = isAtxHeaderLevel(data, i))) return 0;
2065+
20572066
// find end of header text
20582067
size_t end=i;
20592068
while (end<size && data[end]!='\n') end++;
@@ -2856,7 +2865,8 @@ size_t Markdown::Private::writeBlockQuote(std::string_view data)
28562865
{
28572866
curLevel=level;
28582867
i = indent;
2859-
if (txt[0] == '#') break; // begin of markdown section command
2868+
size_t ii = i;
2869+
if (!isAtxHeaderLevel(data, ii)) break; // begin of markdown section command
28602870
out += txt;
28612871
}
28622872
isGitHubFirst = false;

0 commit comments

Comments
 (0)