Skip to content

Commit fd23262

Browse files
committed
issue doxygen#11179 Using README.md as directory description.
Changes - USE_MDFILE_AS_MAINPAGE now only uses the file pointed to (instead of all files with the same name) - README.md files in a sub directories (after applying STRIP_FROM_PATH) are now treated as directory documentation, unless overruled by an explicit @page or @mainpage command. - Added new option IMPLICIT_DIR_DOCS. Enabled by default, set to NO to switch back to old behavior where an explicit @dir is needed in README.md to turn it into directory documentation. - If a README.md is used for directory documentation it does not appear as an empty related page as well. - Allow <!--! to appear in the first line of the .md file when looking for @page, @mainpage, or @dir commands.
1 parent ea75ea2 commit fd23262

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

src/config.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,17 @@ PATH=/Library/TeX/texbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
17871787
is part of the input, its contents will be placed on the main page (`index.html`).
17881788
This can be useful if you have a project on for instance GitHub and want to reuse
17891789
the introduction page also for the Doxygen output.
1790+
]]>
1791+
</docs>
1792+
</option>
1793+
<option type='bool' id='IMPLICIT_DIR_DOCS' defval='1'>
1794+
<docs>
1795+
<![CDATA[
1796+
If the \c IMPLICIT_DIR_DOCS tag is set to \c YES, any `README.md` file found in sub-directories
1797+
of the project's root, is used as the documentation for that sub-directory, except when the
1798+
`README.md` starts with a \ref cmddir "\\dir", \ref cmdpage "\\page" or \ref cmdmainpage "\\mainpage" command.
1799+
If set to \c NO, the `README.md` file needs to start with an explicit \ref cmddir "\\dir" command in order
1800+
to be used as directory documentation.
17901801
]]>
17911802
</docs>
17921803
</option>

src/markdown.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ enum class ExplicitPageResult
6767
{
6868
explicitPage, /**< docs start with a page command */
6969
explicitMainPage, /**< docs start with a mainpage command */
70+
explicitDirPage, /**< docs start with a dir command */
7071
notExplicit /**< docs doesn't start with either page or mainpage */
7172
};
7273

@@ -3405,6 +3406,14 @@ static ExplicitPageResult isExplicitPage(const QCString &docs)
34053406
{
34063407
i++;
34073408
}
3409+
if (i<size-5 && data[i]=='<' && qstrncmp(&data[i],"<!--!",5)==0) // skip over <!--! marker
3410+
{
3411+
i+=5;
3412+
while (i<size && (data[i]==' ' || data[i]=='\n')) // skip over spaces after the <!--! marker
3413+
{
3414+
i++;
3415+
}
3416+
}
34083417
if (i<size-1 &&
34093418
(data[i]=='\\' || data[i]=='@') &&
34103419
(qstrncmp(&data[i+1],"page ",5)==0 || qstrncmp(&data[i+1],"mainpage",8)==0)
@@ -3421,6 +3430,14 @@ static ExplicitPageResult isExplicitPage(const QCString &docs)
34213430
return ExplicitPageResult::explicitMainPage;
34223431
}
34233432
}
3433+
else if (i<size-1 &&
3434+
(data[i]=='\\' || data[i]=='@') &&
3435+
(qstrncmp(&data[i+1],"dir\n",4)==0 || qstrncmp(&data[i+1],"dir ",4)==0)
3436+
)
3437+
{
3438+
AUTO_TRACE_EXIT("result=ExplicitPageResult::explicitDirPage");
3439+
return ExplicitPageResult::explicitDirPage;
3440+
}
34243441
}
34253442
AUTO_TRACE_EXIT("result=ExplicitPageResult::notExplicit");
34263443
return ExplicitPageResult::notExplicit;
@@ -3584,19 +3601,20 @@ void MarkdownOutlineParser::parseInput(const QCString &fileName,
35843601
}
35853602
int indentLevel=title.isEmpty() ? 0 : -1;
35863603
markdown.setIndentLevel(indentLevel);
3587-
QCString fn = FileInfo(fileName.str()).fileName();
3604+
FileInfo fi(fileName.str());
3605+
QCString fn = fi.fileName();
35883606
QCString titleFn = stripExtensionGeneral(fn,getFileNameExtension(fn));
35893607
QCString mdfileAsMainPage = Config_getString(USE_MDFILE_AS_MAINPAGE);
35903608
QCString mdFileNameId = markdownFileNameToId(fileName);
35913609
bool wasEmpty = id.isEmpty();
35923610
if (wasEmpty) id = mdFileNameId;
3611+
QCString relFileName = stripFromPath(fileName);
3612+
bool isSubdirDocs = Config_getBool(IMPLICIT_DIR_DOCS) && relFileName.lower().endsWith("/readme.md");
35933613
switch (isExplicitPage(docs))
35943614
{
35953615
case ExplicitPageResult::notExplicit:
35963616
if (!mdfileAsMainPage.isEmpty() &&
3597-
(fn==mdfileAsMainPage || // name reference
3598-
FileInfo(fileName.str()).absFilePath()==
3599-
FileInfo(mdfileAsMainPage.str()).absFilePath()) // file reference with path
3617+
(fi.absFilePath()==FileInfo(mdfileAsMainPage.str()).absFilePath()) // file reference with path
36003618
)
36013619
{
36023620
docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr ");
@@ -3608,6 +3626,10 @@ void MarkdownOutlineParser::parseInput(const QCString &fileName,
36083626
docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr ");
36093627
docs.prepend("@mainpage "+title+"\\ilinebr ");
36103628
}
3629+
else if (isSubdirDocs)
3630+
{
3631+
docs.prepend("@dir\\ilinebr ");
3632+
}
36113633
else
36123634
{
36133635
if (title.isEmpty())
@@ -3617,7 +3639,7 @@ void MarkdownOutlineParser::parseInput(const QCString &fileName,
36173639
}
36183640
if (!wasEmpty)
36193641
{
3620-
docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr @ianchor{" + stripFromPath(fileName) + "} " + mdFileNameId + "\\ilinebr ");
3642+
docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr @ianchor{" + relFileName + "} " + mdFileNameId + "\\ilinebr ");
36213643
}
36223644
else if (!generatedId.isEmpty())
36233645
{
@@ -3654,6 +3676,8 @@ void MarkdownOutlineParser::parseInput(const QCString &fileName,
36543676
break;
36553677
case ExplicitPageResult::explicitMainPage:
36563678
break;
3679+
case ExplicitPageResult::explicitDirPage:
3680+
break;
36573681
}
36583682
int lineNr=1;
36593683

0 commit comments

Comments
 (0)