Skip to content

Commit d1395aa

Browse files
committed
issue #10306 Some intra-page links include the HTML file name
In case the current filename to write to and the filename in the link (and the link has an anchor) don't write out the filename in the link. One has to be careful with external references to tag files.
1 parent ed26ff0 commit d1395aa

File tree

4 files changed

+49
-11
lines changed

4 files changed

+49
-11
lines changed

src/htmldocvisitor.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ static QCString htmlAttribsToString(const HtmlAttribList &attribs, QCString *pAl
280280
//-------------------------------------------------------------------------
281281

282282
HtmlDocVisitor::HtmlDocVisitor(TextStream &t,OutputCodeList &ci,
283-
const Definition *ctx)
284-
: m_t(t), m_ci(ci), m_ctx(ctx)
283+
const Definition *ctx,const QCString &fn)
284+
: m_t(t), m_ci(ci), m_ctx(ctx), m_fileName(fn)
285285
{
286286
if (ctx) m_langExt=ctx->getDefFileExtension();
287287
}
@@ -2175,11 +2175,16 @@ void HtmlDocVisitor::startLink(const QCString &ref,const QCString &file,
21752175
m_t << "<a class=\"el\" ";
21762176
}
21772177
m_t << "href=\"";
2178-
m_t << externalRef(relPath,ref,TRUE);
2178+
if (!ref.isEmpty()) m_t << externalRef(relPath,ref,TRUE);
21792179
if (!file.isEmpty())
21802180
{
21812181
QCString fn = file;
21822182
addHtmlExtensionIfMissing(fn);
2183+
if (ref.isEmpty())
2184+
{
2185+
if (!anchor.isEmpty() && (m_fileName == Config_getString(HTML_OUTPUT) + "/" + fn)) fn = "";
2186+
else m_t << externalRef(relPath,ref,TRUE);
2187+
}
21832188
m_t << fn;
21842189
}
21852190
if (!anchor.isEmpty()) m_t << "#" << anchor;

src/htmldocvisitor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TextStream;
2929
class HtmlDocVisitor : public DocVisitor
3030
{
3131
public:
32-
HtmlDocVisitor(TextStream &t,OutputCodeList &ci,const Definition *ctx);
32+
HtmlDocVisitor(TextStream &t,OutputCodeList &ci,const Definition *ctx,const QCString &fn = QCString());
3333

3434
//--------------------------------------
3535
// visitor functions for leaf nodes
@@ -146,6 +146,7 @@ class HtmlDocVisitor : public DocVisitor
146146
bool m_hide = false;
147147
bool m_insideTitle = false;
148148
const Definition *m_ctx;
149+
QCString m_fileName;
149150
QCString m_langExt;
150151
};
151152

src/htmlgen.cpp

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -890,11 +890,16 @@ void HtmlCodeGenerator::_writeCodeLink(const QCString &className,
890890
*m_t << "<a class=\"" << className << "\" ";
891891
}
892892
*m_t << "href=\"";
893-
*m_t << externalRef(m_relPath,ref,TRUE);
893+
if (!ref.isEmpty()) *m_t << externalRef(m_relPath,ref,TRUE);
894894
if (!f.isEmpty())
895895
{
896896
QCString fn = f;
897897
addHtmlExtensionIfMissing(fn);
898+
if (ref.isEmpty())
899+
{
900+
if (!anchor.isEmpty() && (fileName() == fn)) fn = "";
901+
else *m_t << externalRef(m_relPath,ref,TRUE);
902+
}
898903
*m_t << fn;
899904
}
900905
if (!anchor.isEmpty()) *m_t << "#" << anchor;
@@ -918,7 +923,12 @@ void HtmlCodeGenerator::writeTooltip(const QCString &id, const DocLinkInfo &docI
918923
if (!docInfo.url.isEmpty())
919924
{
920925
*m_t << "<a href=\"";
921-
*m_t << externalRef(m_relPath,docInfo.ref,TRUE);
926+
if (!docInfo.ref.isEmpty()) *m_t << externalRef(m_relPath,docInfo.ref,TRUE);
927+
else
928+
{
929+
if (!docInfo.anchor.isEmpty() && (fileName() == url)) url = "";
930+
else *m_t << externalRef(m_relPath,docInfo.ref,TRUE);
931+
}
922932
*m_t << url;
923933
if (!docInfo.anchor.isEmpty())
924934
{
@@ -932,18 +942,21 @@ void HtmlCodeGenerator::writeTooltip(const QCString &id, const DocLinkInfo &docI
932942
*m_t << "</a>";
933943
}
934944
*m_t << "</div>";
945+
935946
if (!decl.isEmpty())
936947
{
937948
*m_t << "<div class=\"ttdeci\">";
938949
docify(decl);
939950
*m_t << "</div>";
940951
}
952+
941953
if (!desc.isEmpty())
942954
{
943955
*m_t << "<div class=\"ttdoc\">";
944956
docify(desc);
945957
*m_t << "</div>";
946958
}
959+
947960
if (!defInfo.file.isEmpty())
948961
{
949962
*m_t << "<div class=\"ttdef\"><b>" << theTranslator->trDefinition() << "</b> ";
@@ -952,7 +965,12 @@ void HtmlCodeGenerator::writeTooltip(const QCString &id, const DocLinkInfo &docI
952965
url = defInfo.url;
953966
addHtmlExtensionIfMissing(url);
954967
*m_t << "<a href=\"";
955-
*m_t << externalRef(m_relPath,defInfo.ref,TRUE);
968+
if (!defInfo.ref.isEmpty()) *m_t << externalRef(m_relPath,defInfo.ref,TRUE);
969+
else
970+
{
971+
if (!defInfo.anchor.isEmpty() && (fileName() == url)) url = "";
972+
else *m_t << externalRef(m_relPath,defInfo.ref,TRUE);
973+
}
956974
*m_t << url;
957975
if (!defInfo.anchor.isEmpty())
958976
{
@@ -975,7 +993,12 @@ void HtmlCodeGenerator::writeTooltip(const QCString &id, const DocLinkInfo &docI
975993
url = declInfo.url;
976994
addHtmlExtensionIfMissing(url);
977995
*m_t << "<a href=\"";
978-
*m_t << externalRef(m_relPath,declInfo.ref,TRUE);
996+
if (!declInfo.ref.isEmpty()) *m_t << externalRef(m_relPath,declInfo.ref,TRUE);
997+
else
998+
{
999+
if (!declInfo.anchor.isEmpty() && (fileName() == url)) url = "";
1000+
else *m_t << externalRef(m_relPath,declInfo.ref,TRUE);
1001+
}
9791002
*m_t << url;
9801003
if (!declInfo.anchor.isEmpty())
9811004
{
@@ -1424,6 +1447,7 @@ void HtmlGenerator::startFile(const QCString &name,const QCString &,
14241447
m_lastTitle=title;
14251448

14261449
startPlainFile(fileName);
1450+
m_codeGen->setFileName(fileName);
14271451
m_codeGen->setRelativePath(m_relPath);
14281452
{
14291453
std::lock_guard<std::mutex> lock(g_indexLock);
@@ -1723,11 +1747,16 @@ void HtmlGenerator::writeObjectLink(const QCString &ref,const QCString &f,
17231747
m_t << "<a class=\"el\" ";
17241748
}
17251749
m_t << "href=\"";
1726-
m_t << externalRef(m_relPath,ref,TRUE);
1750+
if (!ref.isEmpty()) m_t << externalRef(m_relPath,ref,TRUE);
17271751
if (!f.isEmpty())
17281752
{
17291753
QCString fn = f;
17301754
addHtmlExtensionIfMissing(fn);
1755+
if (ref.isEmpty())
1756+
{
1757+
if (!anchor.isEmpty() && (fileName() == Config_getString(HTML_OUTPUT) + "/" + fn)) fn = "";
1758+
else m_t << externalRef(m_relPath,ref,TRUE);
1759+
}
17311760
m_t << fn;
17321761
}
17331762
if (!anchor.isEmpty()) m_t << "#" << anchor;
@@ -1743,7 +1772,7 @@ void HtmlGenerator::startTextLink(const QCString &f,const QCString &anchor)
17431772
{
17441773
QCString fn = f;
17451774
addHtmlExtensionIfMissing(fn);
1746-
m_t << m_relPath << fn;
1775+
if (anchor.isEmpty() || (fileName() != Config_getString(HTML_OUTPUT) + "/" + fn)) m_t << m_relPath << fn;
17471776
}
17481777
if (!anchor.isEmpty()) m_t << "#" << anchor;
17491778
m_t << "\">";
@@ -2551,7 +2580,7 @@ void HtmlGenerator::writeDoc(const IDocNodeAST *ast,const Definition *ctx,const
25512580
if (astImpl)
25522581
{
25532582
m_codeList->setId(id);
2554-
HtmlDocVisitor visitor(m_t,*m_codeList,ctx);
2583+
HtmlDocVisitor visitor(m_t,*m_codeList,ctx,fileName());
25552584
std::visit(visitor,astImpl->root);
25562585
}
25572586
}

src/htmlgen.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class HtmlCodeGenerator
2828
HtmlCodeGenerator(TextStream *t);
2929

3030
void setTextStream(TextStream *t) { m_t = t; }
31+
void setFileName(const QCString fileName) { m_fileName = fileName; }
32+
QCString fileName() { return m_fileName; }
3133

3234
OutputType type() const { return OutputType::Html; }
3335

@@ -64,6 +66,7 @@ class HtmlCodeGenerator
6466
TextStream *m_t;
6567
int m_col = 0;
6668
QCString m_relPath;
69+
QCString m_fileName;
6770
bool m_lineOpen = false;
6871
};
6972

0 commit comments

Comments
 (0)