Skip to content

Commit 800128d

Browse files
committed
Problem with refitem command (tests 45)
When running a link checker over the (x)html results of the doxygen tests 45 we get the error: ``` =============================== Processing file:///.../ex_1/html/index.xhtml List of broken links and other issues: file:///.../ex_1/html/item2.xhtml Line: 71 Code: 200 (no message) To do: Some of the links to this resource point to broken URI fragments (such as index.html#fragment). The following fragments need to be fixed: item2 Line: 71 ``` This accounts also for the second example (just with subdirs enabled). When we change *.dox files so that the `\mainpage` is disabled and `\page` is enabled the result for the subdir version is so that the links don't work at all as it searches for e.g. `.../html/d5/d4a/d5/d4a/pg1.xhtml#item1` instead of `html/d5/d4a/pg1.xhtml#item1`. (I slightly modified the example as to compare the links with the links for the `\ref` command).
1 parent ca24685 commit 800128d

File tree

6 files changed

+86
-15
lines changed

6 files changed

+86
-15
lines changed

src/docparser.cpp

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,14 +2274,40 @@ void DocSecRefItem::parse()
22742274
doctokenizerYYsetStatePara();
22752275
handlePendingStyleCommands(this,m_children);
22762276

2277-
const SectionInfo *sec=0;
22782277
if (!m_target.isEmpty())
22792278
{
2280-
sec = SectionManager::instance().find(m_target);
2281-
if (sec)
2279+
SrcLangExt lang = getLanguageFromFileName(m_target);
2280+
m_relPath = g_relPath;
2281+
const SectionInfo *sec = SectionManager::instance().find(m_target);
2282+
if (sec==0 && lang==SrcLangExt_Markdown) // lookup as markdown file
22822283
{
2283-
m_file = sec->fileName();
2284-
m_anchor = sec->label();
2284+
sec = SectionManager::instance().find(markdownFileNameToId(m_target));
2285+
}
2286+
if (sec) // ref to section or anchor
2287+
{
2288+
PageDef *pd = 0;
2289+
if (sec->type()==SectionType::Page)
2290+
{
2291+
pd = Doxygen::pageLinkedMap->find(m_target);
2292+
}
2293+
m_ref = sec->ref();
2294+
m_file = stripKnownExtensions(sec->fileName());
2295+
if (sec->type()==SectionType::Anchor)
2296+
{
2297+
m_refType = Anchor;
2298+
}
2299+
else if (sec->type()==SectionType::Table)
2300+
{
2301+
m_refType = Table;
2302+
}
2303+
else
2304+
{
2305+
m_refType = Section;
2306+
}
2307+
m_isSubPage = pd && pd->hasParentPage();
2308+
if (sec->type()!=SectionType::Page || m_isSubPage) m_anchor = sec->label();
2309+
//printf("m_ref=%s,m_file=%s,type=%d\n",
2310+
// qPrint(m_ref),qPrint(m_file),m_refType);
22852311
}
22862312
else
22872313
{

src/docparser.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class DocNode
163163
/*! Sets whether or not this item is inside a preformatted section */
164164
void setInsidePreformatted(bool p) { m_insidePre = p; }
165165
DocNode *m_parent = 0;
166+
enum RefType { Unknown, Anchor, Section, Table };
166167
private:
167168

168169
bool m_insidePre = false;
@@ -883,7 +884,6 @@ class DocRef : public CompAccept<DocRef>
883884
bool isSubPage() const { return m_isSubPage; }
884885

885886
private:
886-
enum RefType { Unknown, Anchor, Section, Table };
887887
RefType m_refType = Unknown;
888888
bool m_isSubPage = false;
889889
QCString m_file;
@@ -1005,12 +1005,20 @@ class DocSecRefItem : public CompAccept<DocSecRefItem>
10051005
QCString target() const { return m_target; }
10061006
QCString file() const { return m_file; }
10071007
QCString anchor() const { return m_anchor; }
1008+
QCString relPath() const { return m_relPath; }
1009+
QCString ref() const { return m_ref; }
1010+
bool refToTable() const { return m_refType==Table; }
1011+
bool isSubPage() const { return m_isSubPage; }
10081012
void parse();
10091013

10101014
private:
10111015
QCString m_target;
1012-
QCString m_file;
1013-
QCString m_anchor;
1016+
RefType m_refType = Unknown;
1017+
bool m_isSubPage = false;
1018+
QCString m_file;
1019+
QCString m_relPath;
1020+
QCString m_ref;
1021+
QCString m_anchor;
10141022
};
10151023

10161024
/** Node representing a list of section references */

src/htmldocvisitor.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,15 +1887,24 @@ void HtmlDocVisitor::visitPost(DocRef *ref)
18871887
void HtmlDocVisitor::visitPre(DocSecRefItem *ref)
18881888
{
18891889
if (m_hide) return;
1890-
QCString refName=addHtmlExtensionIfMissing(ref->file());
1891-
m_t << "<li><a href=\"" << refName << "#" << ref->anchor() << "\">";
1892-
1890+
//QCString refName=addHtmlExtensionIfMissing(ref->file());
1891+
//m_t << "<li><a href=\"" << refName << "#" << ref->anchor() << "\">";
1892+
if (!ref->file().isEmpty())
1893+
{
1894+
m_t << "<li>";
1895+
startLink(ref->ref(),ref->file(),ref->relPath(),ref->isSubPage() ? QCString() : ref->anchor());
1896+
}
18931897
}
18941898

1895-
void HtmlDocVisitor::visitPost(DocSecRefItem *)
1899+
void HtmlDocVisitor::visitPost(DocSecRefItem *ref)
18961900
{
18971901
if (m_hide) return;
1898-
m_t << "</a></li>\n";
1902+
if (!ref->file().isEmpty())
1903+
{
1904+
endLink();
1905+
m_t << "</li>\n";
1906+
}
1907+
// m_t << "</a></li>\n";
18991908
}
19001909

19011910
void HtmlDocVisitor::visitPre(DocSecRefList *s)

src/latexdocvisitor.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,22 +1539,47 @@ void LatexDocVisitor::visitPre(DocSecRefItem *ref)
15391539
{
15401540
if (m_hide) return;
15411541
m_t << "\\item \\contentsline{section}{";
1542+
if (ref->isSubPage())
1543+
{
1544+
startLink(ref->ref(),QCString(),ref->anchor());
1545+
}
1546+
else
1547+
{
1548+
if (!ref->file().isEmpty()) startLink(ref->ref(),ref->file(),ref->anchor(),ref->refToTable());
1549+
}
1550+
#if 0
15421551
static bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS);
15431552
if (pdfHyperlinks)
15441553
{
15451554
m_t << "\\mbox{\\hyperlink{" << ref->file() << "_" << ref->anchor() << "}{" ;
15461555
}
1556+
#endif
15471557
}
15481558

15491559
void LatexDocVisitor::visitPost(DocSecRefItem *ref)
15501560
{
15511561
if (m_hide) return;
1562+
#if 0
15521563
static bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS);
15531564
if (pdfHyperlinks)
15541565
{
15551566
m_t << "}}";
15561567
}
15571568
m_t << "}{\\ref{" << ref->file() << "_" << ref->anchor() << "}}{}\n";
1569+
#endif
1570+
if (ref->isSubPage())
1571+
{
1572+
endLink(ref->ref(),QCString(),ref->anchor());
1573+
}
1574+
else
1575+
{
1576+
if (!ref->file().isEmpty()) endLink(ref->ref(),ref->file(),ref->anchor(),ref->refToTable());
1577+
}
1578+
m_t << "}{\\ref{";
1579+
if (!ref->file().isEmpty()) m_t << stripPath(ref->file());
1580+
if (!ref->file().isEmpty() && !ref->anchor().isEmpty()) m_t << "_";
1581+
if (!ref->anchor().isEmpty()) m_t << ref->anchor();
1582+
m_t << "}}{}\n";
15581583
}
15591584

15601585
void LatexDocVisitor::visitPre(DocSecRefList *)

src/xmldocvisitor.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,10 @@ void XmlDocVisitor::visitPost(DocRef *ref)
10221022
void XmlDocVisitor::visitPre(DocSecRefItem *ref)
10231023
{
10241024
if (m_hide) return;
1025-
m_t << "<tocitem id=\"" << ref->file() << "_1" << ref->anchor() << "\">";
1025+
m_t << "<tocitem id=\"" << ref->file();
1026+
if (!ref->anchor().isEmpty()) m_t << "_1" << ref->anchor();
1027+
m_t << "\"";
1028+
m_t << ">";
10261029
}
10271030

10281031
void XmlDocVisitor::visitPost(DocSecRefItem *)

testing/045/indexpage.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<para>
1010
<toclist>
1111
<tocitem id="index_1item1">First Item</tocitem>
12-
<tocitem id="item2_1item2">Second Item</tocitem>
12+
<tocitem id="item2">Second Item</tocitem>
1313
<tocitem id="item2_1item3">Third Item</tocitem>
1414
</toclist>
1515
</para>

0 commit comments

Comments
 (0)