Skip to content

Commit 98242a3

Browse files
committed
issue #10567 Incorrectly closed markdown code block causes doxygen to forget about consecutive macro definitions
An exact match of the strings for starting and ending fenced code blocks was required, this has been relaxed to that the number of fence characters should match. Also protecting that the block starts and ends with the same type of fence character.
1 parent db523de commit 98242a3

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/pre.l

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ struct preYY_state
293293
bool isSource = false;
294294

295295
yy_size_t fenceSize = 0;
296+
char fenceChar = ' ';
296297
bool ccomment = false;
297298
QCString delimiter;
298299
bool isSpecialComment = false;
@@ -340,6 +341,7 @@ static void setFileName(yyscan_t yyscanner,const QCString &name);
340341
static int yyread(yyscan_t yyscanner,char *buf,int max_size);
341342
static Define * isDefined(yyscan_t yyscanner,const QCString &name);
342343
static void determineBlockName(yyscan_t yyscanner);
344+
static yy_size_t getFenceSize(char *txt, yy_size_t leng);
343345

344346
/* ----------------------------------------------------------------- */
345347

@@ -1422,7 +1424,8 @@ WSopt [ \t\r]*
14221424
}
14231425
else
14241426
{
1425-
yyextra->fenceSize=(int)yyleng;
1427+
yyextra->fenceChar='~';
1428+
yyextra->fenceSize=(int)getFenceSize(yytext,yyleng);
14261429
BEGIN(SkipCondVerbatim);
14271430
}
14281431
}
@@ -1434,7 +1437,8 @@ WSopt [ \t\r]*
14341437
}
14351438
else
14361439
{
1437-
yyextra->fenceSize=(int)yyleng;
1440+
yyextra->fenceChar='`';
1441+
yyextra->fenceSize=(int)getFenceSize(yytext,yyleng);
14381442
BEGIN(SkipCondVerbatim);
14391443
}
14401444
}
@@ -1447,7 +1451,8 @@ WSopt [ \t\r]*
14471451
else
14481452
{
14491453
outputArray(yyscanner,yytext,yyleng);
1450-
yyextra->fenceSize=(int)yyleng;
1454+
yyextra->fenceChar='~';
1455+
yyextra->fenceSize=(int)getFenceSize(yytext,yyleng);
14511456
BEGIN(SkipVerbatim);
14521457
}
14531458
}
@@ -1460,7 +1465,8 @@ WSopt [ \t\r]*
14601465
else
14611466
{
14621467
outputArray(yyscanner,yytext,yyleng);
1463-
yyextra->fenceSize=(int)yyleng;
1468+
yyextra->fenceChar='`';
1469+
yyextra->fenceSize=(int)getFenceSize(yytext,yyleng);
14641470
BEGIN(SkipVerbatim);
14651471
}
14661472
}
@@ -1626,27 +1632,27 @@ WSopt [ \t\r]*
16261632
}
16271633
}
16281634
<SkipCondVerbatim>^({B}*"*"+)?{B}{0,3}"~~~"[~]* {
1629-
if (yyextra->fenceSize==(yy_size_t)yyleng)
1635+
if (yyextra->fenceSize==getFenceSize(yytext,yyleng) && yyextra->fenceChar=='~')
16301636
{
16311637
BEGIN(SkipCond);
16321638
}
16331639
}
16341640
<SkipCondVerbatim>^({B}*"*"+)?{B}{0,3}"```"[`]* {
1635-
if (yyextra->fenceSize==(yy_size_t)yyleng)
1641+
if (yyextra->fenceSize==getFenceSize(yytext,yyleng) && yyextra->fenceChar=='`')
16361642
{
16371643
BEGIN(SkipCond);
16381644
}
16391645
}
16401646
<SkipVerbatim>^({B}*"*"+)?{B}{0,3}"~~~"[~]* {
16411647
outputArray(yyscanner,yytext,yyleng);
1642-
if (yyextra->fenceSize==(yy_size_t)yyleng)
1648+
if (yyextra->fenceSize==getFenceSize(yytext,yyleng) && yyextra->fenceChar=='~')
16431649
{
16441650
BEGIN(SkipCComment);
16451651
}
16461652
}
16471653
<SkipVerbatim>^({B}*"*"+)?{B}{0,3}"```"[`]* {
16481654
outputArray(yyscanner,yytext,yyleng);
1649-
if (yyextra->fenceSize==(yy_size_t)yyleng)
1655+
if (yyextra->fenceSize==getFenceSize(yytext,yyleng) && yyextra->fenceChar=='`')
16501656
{
16511657
BEGIN(SkipCComment);
16521658
}
@@ -2083,6 +2089,17 @@ static int yyread(yyscan_t yyscanner,char *buf,int max_size)
20832089
return bytesToCopy;
20842090
}
20852091

2092+
static yy_size_t getFenceSize(char *txt, yy_size_t leng)
2093+
{
2094+
yy_size_t fenceSize = 0;
2095+
for (size_t i = 0; i < leng; i++)
2096+
{
2097+
if (txt[i] != ' ' && txt[i] != '*' && txt[i] != '\t') break;
2098+
fenceSize++;
2099+
}
2100+
return leng-fenceSize;
2101+
}
2102+
20862103
static void setFileName(yyscan_t yyscanner,const QCString &name)
20872104
{
20882105
YY_EXTRA_TYPE state = preYYget_extra(yyscanner);

src/scanner.l

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7114,15 +7114,15 @@ NONLopt [^\n]*
71147114
<DocCopyBlock>^({B}*"*"+)?{B}{0,3}"~~~"[~]* {
71157115
QCString pat = substitute(yytext,"*"," ");
71167116
yyextra->docBlock << pat;
7117-
if (yyextra->fencedSize==pat.stripWhiteSpace().length())
7117+
if (yyextra->docBlockName == "~~~" && yyextra->fencedSize==pat.stripWhiteSpace().length())
71187118
{
71197119
BEGIN(DocBlock);
71207120
}
71217121
}
71227122
<DocCopyBlock>^({B}*"*"+)?{B}{0,3}"```"[`]* {
71237123
QCString pat = substitute(yytext,"*"," ");
71247124
yyextra->docBlock << pat;
7125-
if (yyextra->fencedSize==pat.stripWhiteSpace().length())
7125+
if (yyextra->docBlockName == "```" && yyextra->fencedSize==pat.stripWhiteSpace().length())
71267126
{
71277127
BEGIN(DocBlock);
71287128
}
@@ -7448,6 +7448,7 @@ static inline int computeIndent(const char *s,int startIndent)
74487448
}
74497449
return col;
74507450
}
7451+
74517452
static inline void initMethodProtection(yyscan_t yyscanner,Protection prot)
74527453
{
74537454
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;

0 commit comments

Comments
 (0)