search for headers

This commit is contained in:
ville rantanen
2017-07-03 09:35:36 +03:00
parent 12689db311
commit ecbde2bc83

View File

@@ -152,13 +152,26 @@ function search_hits(needle) {
hitList=[]; hitList=[];
var headName=""; var headName="";
for (l=0; l<linkList.length; l++) { for (l=0; l<linkList.length; l++) {
if ( linkList[l].substring(0,2) == "# " ) {
headName=linkList[l].substring(1).trim().replace(/ /g,"").toLowerCase();
}
if (needle.substring(0,1)=="#") {
/* search for header */
if (headName.indexOf(needle.substring(1).trim())>-1) {
/* current header matches */
hitList.push(l);
continue
}
}
var match=linkReg.exec(linkList[l].toLowerCase()); var match=linkReg.exec(linkList[l].toLowerCase());
if (match != null ) { if (match != null ) {
/* matches to markdown link */
if ( match[2].indexOf(needle)>-1 ) { hitList.push(l); } if ( match[2].indexOf(needle)>-1 ) { hitList.push(l); }
continue continue
} }
match=linkPlain.exec(linkList[l].toLowerCase()); match=linkPlain.exec(linkList[l].toLowerCase());
if (match != null ) { if (match != null ) {
/* matches to plain link */
if ( match[2].indexOf(needle)>-1 ) { hitList.push(l); } if ( match[2].indexOf(needle)>-1 ) { hitList.push(l); }
continue continue
} }
@@ -327,7 +340,7 @@ var config = {
</head> </head>
<body onload="read_links()"> <body onload="read_links()">
<div id="search"> <div id="search">
<span class="search_span"><input type="text" oninput="filter(event)" onkeypress="filter(event)" onblur="no_filter()" id="filter" title="Filter links by name"></span> <span class="search_span"><input type="text" oninput="filter(event)" onkeypress="filter(event)" onblur="no_filter()" id="filter" title="Filter links by name, filter headers by #name"></span>
<span class="search_span" id="menu_span"></span> <span class="search_span" id="menu_span"></span>
<span class="search_span tickbox" id=open_blank_span onclick="toggle_blank()" title="Open links in new window"><span id=open_blank_box></span><span id=open_blank_arrow></span></span> <span class="search_span tickbox" id=open_blank_span onclick="toggle_blank()" title="Open links in new window"><span id=open_blank_box></span><span id=open_blank_arrow></span></span>
</div> </div>