Permalink
Browse files

Bug 765692 - Using `@page` to add title to Markdown file generates su…

…rplus empty page.
  • Loading branch information...
Dimitri van Heesch
Dimitri van Heesch committed May 16, 2016
1 parent ec1ef7b commit 42c7d88ffc11651d1fb6b997fd23cc938bce4a39
Showing with 40 additions and 17 deletions.
  1. +40 −17 src/markdown.cpp
View
@@ -838,7 +838,7 @@ static int processLink(GrowBuf &out,const char *data,int,int size)
out.addStr("@image html ");
out.addStr(link.mid(fd ? 0 : 5));
if (!explicitTitle && !content.isEmpty())
{
{
out.addStr(" \"");
out.addStr(content);
out.addStr("\"");
@@ -2198,6 +2198,26 @@ static QCString processBlocks(const QCString &s,int indent)
return out.get();
}
/** returns TRUE if input string docs starts with \@page or \@mainpage command */
static bool isExplicitPage(const QCString &docs)
{
int i=0;
const char *data = docs.data();
int size=docs.size();
while (i<size && (data[i]==' ' || data[i]=='\n'))
{
i++;
}
if (i<size+1 &&
(data[i]=='\\' || data[i]=='@') &&
(qstrncmp(&data[i+1],"page ",5)==0 || qstrncmp(&data[i+1],"mainpage",8)==0)
)
{
return TRUE;
}
return FALSE;
}
static QCString extractPageTitle(QCString &docs,QCString &id)
{
int ln=0;
@@ -2371,23 +2391,26 @@ void MarkdownFileParser::parseInput(const char *fileName,
QCString fn = QFileInfo(fileName).fileName().utf8();
static QCString mdfileAsMainPage = Config_getString(USE_MDFILE_AS_MAINPAGE);
if (id.isEmpty()) id = markdownFileNameToId(fileName);
if (!mdfileAsMainPage.isEmpty() &&
(fn==mdfileAsMainPage || // name reference
QFileInfo(fileName).absFilePath()==
QFileInfo(mdfileAsMainPage).absFilePath()) // file reference with path
)
{
docs.prepend("@mainpage "+title+"\n");
}
else if (id=="mainpage" || id=="index")
if (!isExplicitPage(docs))
{
if (title.isEmpty()) title = titleFn;
docs.prepend("@mainpage "+title+"\n");
}
else
{
if (title.isEmpty()) title = titleFn;
docs.prepend("@page "+id+" "+title+"\n");
if (!mdfileAsMainPage.isEmpty() &&
(fn==mdfileAsMainPage || // name reference
QFileInfo(fileName).absFilePath()==
QFileInfo(mdfileAsMainPage).absFilePath()) // file reference with path
)
{
docs.prepend("@mainpage "+title+"\n");
}
else if (id=="mainpage" || id=="index")
{
if (title.isEmpty()) title = titleFn;
docs.prepend("@mainpage "+title+"\n");
}
else
{
if (title.isEmpty()) title = titleFn;
docs.prepend("@page "+id+" "+title+"\n");
}
}
int lineNr=1;
int position=0;

0 comments on commit 42c7d88

Please sign in to comment.