Skip to content

Commit 2604e3f

Browse files
committed
issue doxygen#11557 @TableofContents shows <tt> tags for MarkDown headings with inline code
- properly process section/page/group titles for the search results - keep section formatting in page outline panel as well
1 parent a3bd787 commit 2604e3f

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

src/searchindex_js.cpp

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,60 @@
3737
#include "threadpool.h"
3838
#include "moduledef.h"
3939
#include "section.h"
40+
#include "htmldocvisitor.h"
41+
#include "outputlist.h"
4042

4143
//-------------------------------------------------------------------------------------------
4244

45+
static std::mutex g_titleCacheMutex;
46+
static std::unordered_map<std::string,QCString> g_titleCache;
47+
48+
static QCString convertTitleToHtml(const Definition *scope,const QCString &fileName,int lineNr,const QCString &title)
49+
{
50+
std::lock_guard lock(g_titleCacheMutex);
51+
auto it = g_titleCache.find(title.str());
52+
if (it != g_titleCache.end())
53+
{
54+
//printf("Cache: [%s]->[%s]\n",qPrint(title),qPrint(it->second));
55+
return it->second;
56+
}
57+
auto parser { createDocParser() };
58+
auto ast { validatingParseDoc(*parser.get(),fileName,lineNr,scope,nullptr,title,false,false,
59+
QCString(),true,false,Config_getBool(MARKDOWN_SUPPORT)) };
60+
auto astImpl = dynamic_cast<const DocNodeAST*>(ast.get());
61+
QCString result;
62+
if (astImpl)
63+
{
64+
TextStream t;
65+
OutputCodeList codeList;
66+
codeList.add<HtmlCodeGenerator>(&t);
67+
HtmlDocVisitor visitor(t,codeList,scope,fileName);
68+
std::visit(visitor,astImpl->root);
69+
result = t.str();
70+
}
71+
else // fallback, should not happen
72+
{
73+
result = filterTitle(title);
74+
}
75+
//printf("Conversion: [%s]->[%s]\n",qPrint(title),qPrint(result));
76+
g_titleCache.insert(std::make_pair(title.str(),result));
77+
return result;
78+
}
79+
4380
void SearchTerm::makeTitle()
4481
{
4582
if (std::holds_alternative<const Definition *>(info))
4683
{
4784
const Definition *def = std::get<const Definition *>(info);
4885
Definition::DefType type = def->definitionType();
49-
title = type==Definition::TypeGroup ? filterTitle(toGroupDef(def)->groupTitle()) :
50-
type==Definition::TypePage ? filterTitle(toPageDef(def)->title()) :
86+
title = type==Definition::TypeGroup ? convertTitleToHtml(def,def->getDefFileName(),def->getDefLine(),toGroupDef(def)->groupTitle()) :
87+
type==Definition::TypePage ? convertTitleToHtml(def,def->getDefFileName(),def->getDefLine(),toPageDef(def)->title()) :
5188
def->localName();
5289
}
5390
else if (std::holds_alternative<const SectionInfo *>(info))
5491
{
55-
title = std::get<const SectionInfo *>(info)->title();
92+
const SectionInfo *si = std::get<const SectionInfo *>(info);
93+
title = convertTitleToHtml(si->definition(),si->fileName(),si->lineNr(),si->title());
5694
}
5795
else
5896
{

templates/html/navtree.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ function initNavTree(toroot,relpath,allMembersFile) {
792792
$('h1.doxsection, h2.doxsection, h3.doxsection, h4.doxsection, h5.doxsection, h6.doxsection').each(function(){
793793
const level = parseInt(this.tagName[1]);
794794
const anchor = $(this).find('a.anchor').attr('id');
795-
const node = { text: $(this).text(), id: anchor, children: [] };
795+
const node = { text: $(this).html(), id: anchor, children: [] };
796796
while (sectionStack.length && sectionStack[sectionStack.length - 1].level >= level) sectionStack.pop();
797797
(sectionStack.length ? sectionStack[sectionStack.length - 1].children : sectionTree).push(node);
798798
sectionStack.push({ ...node, level });
@@ -805,7 +805,7 @@ function initNavTree(toroot,relpath,allMembersFile) {
805805
const span = $('<span>').addClass('arrow').attr('style','padding-left:'+parseInt(level*16)+'px;');
806806
if (n.children.length > 0) { span.append($('<span>').addClass('arrowhead opened')); }
807807
const url = $('<a>').attr('href','#'+n.id);
808-
content.append(li.append(div.append(span).append(url.append(escapeHtml(n.text)))));
808+
content.append(li.append(div.append(span).append(url.append(n.text))));
809809
topMapping.push(n.id);
810810
render(n.children,level+1);
811811
});

0 commit comments

Comments
 (0)