Skip to content

Commit 9735bed

Browse files
committed
issue doxygen#11373 Code examples in Python docstrings rendered in HTML with wrong indentation beyond 8 spaces
Ignore the line after """! when determining the indentation to strip.
1 parent 443b978 commit 9735bed

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

src/pyscanner.l

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -804,14 +804,17 @@ ID [a-z_A-Z%]+{IDSYM}*
804804
yyextra->current->program << yytext;
805805
}
806806
^{BB} { // something at indent >0
807-
yyextra->current->program << yytext;
808807
yyextra->curIndent = computeIndent(yytext);
809808
if (yyextra->curIndent<=yyextra->indent)
810809
// jumped out of the function
811810
{
812811
endOfDef(yyscanner,1);
813812
BEGIN(Search);
814813
}
814+
else
815+
{
816+
yyextra->current->program << yytext;
817+
}
815818
}
816819
"'" { // start of a single quoted string
817820
yyextra->current->program << yytext;
@@ -2020,7 +2023,8 @@ static void handleCommentBlock(yyscan_t yyscanner,const QCString &doc,bool brief
20202023
int lineNr = brief ? yyextra->current->briefLine : yyextra->current->docLine;
20212024
Markdown markdown(yyextra->fileName,lineNr);
20222025
GuardedSectionStack guards;
2023-
QCString strippedDoc = stripIndentation(doc);
2026+
QCString strippedDoc = stripIndentation(doc,true);
2027+
//printf("stippedDoc=[%s]\n",qPrint(strippedDoc));
20242028
QCString processedDoc = Config_getBool(MARKDOWN_SUPPORT) ? markdown.process(strippedDoc,lineNr) : strippedDoc;
20252029
while (yyextra->commentScanner.parseCommentBlock(
20262030
yyextra->thisParser,
@@ -2080,10 +2084,6 @@ static void initTriDoubleQuoteBlock(yyscan_t yyscanner)
20802084
yyextra->docBlock.clear();
20812085
yyextra->commentIndent = yyextra->curIndent;
20822086
yyextra->doubleQuote = TRUE;
2083-
if (yyextra->docBlockSpecial)
2084-
{
2085-
yyextra->docBlock.fill(' ',yyextra->indent);
2086-
}
20872087
startCommentBlock(yyscanner,FALSE);
20882088
}
20892089

@@ -2097,10 +2097,6 @@ static void initTriSingleQuoteBlock(yyscan_t yyscanner)
20972097
yyextra->docBlock.clear();
20982098
yyextra->commentIndent = yyextra->curIndent;
20992099
yyextra->doubleQuote = FALSE;
2100-
if (yyextra->docBlockSpecial)
2101-
{
2102-
yyextra->docBlock.fill(' ',yyextra->indent);
2103-
}
21042100
startCommentBlock(yyscanner,FALSE);
21052101
}
21062102

src/util.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6402,7 +6402,7 @@ bool protectionLevelVisible(Protection prot)
64026402

64036403
//---------------------------------------------------------------------------
64046404

6405-
QCString stripIndentation(const QCString &s)
6405+
QCString stripIndentation(const QCString &s,bool skipFirstLine)
64066406
{
64076407
if (s.isEmpty()) return s; // empty string -> we're done
64086408

@@ -6412,16 +6412,17 @@ QCString stripIndentation(const QCString &s)
64126412
char c=0;
64136413
int indent=0;
64146414
int minIndent=1000000; // "infinite"
6415-
bool searchIndent=TRUE;
6415+
bool searchIndent=true;
64166416
int tabSize=Config_getInt(TAB_SIZE);
6417+
bool skipFirst = skipFirstLine;
64176418
while ((c=*p++))
64186419
{
64196420
if (c=='\t') indent+=tabSize - (indent%tabSize);
6420-
else if (c=='\n') indent=0,searchIndent=TRUE;
6421+
else if (c=='\n') indent=0,searchIndent=true,skipFirst=false;
64216422
else if (c==' ') indent++;
6422-
else if (searchIndent)
6423+
else if (searchIndent && !skipFirst)
64236424
{
6424-
searchIndent=FALSE;
6425+
searchIndent=false;
64256426
if (indent<minIndent) minIndent=indent;
64266427
}
64276428
}
@@ -6433,14 +6434,16 @@ QCString stripIndentation(const QCString &s)
64336434
TextStream result;
64346435
p=s.data();
64356436
indent=0;
6437+
skipFirst=skipFirstLine;
64366438
while ((c=*p++))
64376439
{
64386440
if (c=='\n') // start of new line
64396441
{
64406442
indent=0;
64416443
result << c;
6444+
skipFirst=false;
64426445
}
6443-
else if (indent<minIndent) // skip until we reach minIndent
6446+
else if (indent<minIndent && !skipFirst) // skip until we reach minIndent
64446447
{
64456448
if (c=='\t')
64466449
{

src/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ QCString processMarkup(const QCString &s);
433433

434434
bool protectionLevelVisible(Protection prot);
435435

436-
QCString stripIndentation(const QCString &s);
436+
QCString stripIndentation(const QCString &s,bool skipFirstLine=false);
437437
void stripIndentationVerbatim(QCString &doc,const int indentationLevel);
438438

439439
QCString getDotImageExtension();

0 commit comments

Comments
 (0)