Help browser: Enhance search syntax, and highlight search terms in the resulting pages.
[DEVELOPMENT ENVIRONMENT] * BUG: Help browser: Fix symbol links in class help pages. * NEW: Help browser: Searching returns pages including any of the search words. To search a string with spaces inside, enclose it with quotes. * NEW: Help browser: Search terms are highlighted in the result pages.
This commit is contained in:
parent
265643cdd5
commit
628a5cb424
6 changed files with 89 additions and 16 deletions
|
@ -775,11 +775,11 @@ Private Function GetSymbolType(aSym As String[]) As String
|
|||
hSym = Symbols[sName]
|
||||
sName = Replace(sName, ":", ".")
|
||||
If hSym.Class <> Name Or If hSym.Component <> Component Then
|
||||
sRes &= "[/comp" &/ LCase(hSym.Component &/ hSym.Class &/ sName) & "] \n"
|
||||
sRes &= "[" & sName & "](/comp" &/ LCase(hSym.Component &/ hSym.Class &/ sName) & ") \n"
|
||||
Else If hSym.Class <> Wiki.Class Or If hSym.Component <> Wiki.Component Then
|
||||
sRes &= "<span class=\"inherit\">~[/comp" &/ LCase(hSym.Component &/ hSym.Class &/ sName) & "]~</span> \n"
|
||||
sRes &= "<span class=\"inherit\">~[" & sName & "](/comp" &/ LCase(hSym.Component &/ hSym.Class &/ sName) & ")~</span> \n"
|
||||
Else
|
||||
sRes &= "<span class=\"inherit\">~[./" & LCase(sName) & "]~</span> \n"
|
||||
sRes &= "<span class=\"inherit\">~[" & sName & "](./" & LCase(sName) & ")~</span> \n"
|
||||
Endif
|
||||
Next
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
Inherits Task
|
||||
|
||||
Public Search As String
|
||||
Public Search As String[]
|
||||
Public Buffer As String
|
||||
|
||||
Private $aImageExt As String[] = ["png", "jpg", "jpeg", "gif", "webm", "mov", "mp4", "mp3"]
|
||||
|
@ -16,6 +16,8 @@ Public Sub Main()
|
|||
Dim sFile As String
|
||||
Dim sExt As String
|
||||
Dim sLink As String
|
||||
Dim aSearch As String[]
|
||||
Dim sSearch As String
|
||||
|
||||
Application.Priority = 10
|
||||
|
||||
|
@ -28,12 +30,15 @@ Public Sub Main()
|
|||
|
||||
Try sData = File.Load(sDir &/ "~page")
|
||||
If Not Error Then
|
||||
If String.InStr(sData, Search, 1, gb.IgnoreCase) Then
|
||||
sLink = Mid$(sDir, Len(sRoot) + 1)
|
||||
If Not sLink Then sLink = "/"
|
||||
Print sLink
|
||||
Flush
|
||||
Endif
|
||||
For Each sSearch In Search
|
||||
If String.InStr(sData, sSearch, 1, gb.IgnoreCase) Then
|
||||
sLink = Mid$(sDir, Len(sRoot) + 1)
|
||||
If Not sLink Then sLink = "/"
|
||||
Print sLink
|
||||
Flush
|
||||
Break
|
||||
Endif
|
||||
Next
|
||||
Endif
|
||||
|
||||
For Each sFile In Dir(sDir, "*", gb.Directory)
|
||||
|
|
|
@ -10,6 +10,7 @@ Private mnuLang As Menu
|
|||
Private $bFirstTime As Boolean
|
||||
Private $bOffline As Boolean
|
||||
Private $hTask As CHelpSearchTask
|
||||
Private $aSearch As String[]
|
||||
|
||||
Public Sub _new()
|
||||
|
||||
|
@ -363,7 +364,8 @@ Public Sub btnSearch_Click()
|
|||
sText = Trim(txtSearch.Text)
|
||||
If sText Then
|
||||
$hTask = New CHelpSearchTask As "TaskSearch"
|
||||
$hTask.Search = sText
|
||||
$aSearch = Split(sText, " ", Chr$(34), True)
|
||||
$hTask.Search = $aSearch
|
||||
btnSearch.Picture = Picture["icon:/small/stop"]
|
||||
txtSearch.Enabled = False
|
||||
lstResult.Clear
|
||||
|
@ -422,7 +424,7 @@ End
|
|||
Public Sub lstResult_Select()
|
||||
|
||||
tvwClasses.UnSelectAll
|
||||
MHelp.MakeOffline(webHelp, MHelp.GetURL(lstResult.Key))
|
||||
MHelp.MakeOffline(webHelp, MHelp.GetURL(lstResult.Key),, $aSearch.Join())
|
||||
|
||||
End
|
||||
|
||||
|
|
|
@ -916,7 +916,7 @@ Public Sub GetOfflineState() As Integer
|
|||
End
|
||||
|
||||
|
||||
Public Sub MakeOffline(hWebView As WebView, sUrl As String, Optional bNoHeader As Boolean) As Boolean
|
||||
Public Sub MakeOffline(hWebView As WebView, sUrl As String, Optional bNoHeader As Boolean, Optional sHighlight As String) As Boolean
|
||||
|
||||
Dim sFile As String
|
||||
Dim sHtml As String
|
||||
|
@ -937,7 +937,7 @@ Public Sub MakeOffline(hWebView As WebView, sUrl As String, Optional bNoHeader A
|
|||
|
||||
If Not $bInitOffline Then
|
||||
|
||||
For Each sFile In ["up.png", "critical.png", "info.png", "tip.png", "vb.png", "warning.png", "error-bg.png"]
|
||||
For Each sFile In ["up.png", "critical.png", "info.png", "tip.png", "vb.png", "warning.png", "error-bg.png", "highlight.js"]
|
||||
Try Kill GetOfflineDir() &/ sFile
|
||||
Copy "help/wiki" &/ sFile To GetOfflineDir() &/ sFile
|
||||
Next
|
||||
|
@ -1012,7 +1012,10 @@ Public Sub MakeOffline(hWebView As WebView, sUrl As String, Optional bNoHeader A
|
|||
Output To Default
|
||||
Close #hFile
|
||||
|
||||
hWebView.Url = "file://" & URL.Encode(sPath)
|
||||
sUrl = "file://" & URL.Encode(sPath)
|
||||
If sHighlight Then sUrl &= "?s=" & URL.Encode(sHighlight)
|
||||
|
||||
hWebView.Url = sUrl
|
||||
|
||||
Catch
|
||||
|
||||
|
|
62
app/src/gambas3/help/wiki/highlight.js
Normal file
62
app/src/gambas3/help/wiki/highlight.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
function highlight_text(text, search)
|
||||
{
|
||||
var newText = '';
|
||||
var i = -1;
|
||||
var lcSearch = search.toLowerCase();
|
||||
var lcText = text.toLowerCase();
|
||||
|
||||
while (text.length > 0)
|
||||
{
|
||||
i = lcText.indexOf(lcSearch, i+1);
|
||||
if (i < 0)
|
||||
{
|
||||
newText += text;
|
||||
text = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
// skip anything inside an HTML tag
|
||||
if (text.lastIndexOf('>', i) >= text.lastIndexOf('<', i))
|
||||
{
|
||||
// skip anything inside a <script> block
|
||||
if (lcText.lastIndexOf('/script', i) >= lcText.lastIndexOf('<script', i))
|
||||
{
|
||||
newText += text.substring(0, i) + '<mark>' + text.substr(i, search.length) + '</mark>';
|
||||
text = text.substr(i + search.length);
|
||||
lcText = text.toLowerCase();
|
||||
i = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return newText;
|
||||
}
|
||||
|
||||
function highlight_body(searches)
|
||||
{
|
||||
var text = document.body.innerHTML;
|
||||
|
||||
alert(searches.length);
|
||||
|
||||
for (var i = 0; i < searches.length; i++)
|
||||
text = highlight_text(text, searches[i]);
|
||||
|
||||
document.body.innerHTML = text;
|
||||
}
|
||||
|
||||
function highlight_check()
|
||||
{
|
||||
var i, pair;
|
||||
var query = window.location.search.substring(1).split('&');
|
||||
|
||||
for (i = 0; i < query.length; i++)
|
||||
{
|
||||
pair = query[i].split('=');
|
||||
if (pair[0] == 's' && pair.length == 2)
|
||||
{
|
||||
highlight_body(decodeURIComponent(pair[1].replace(/[+]/g, '%20')).split(','));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,10 +5,11 @@
|
|||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<link rel="stylesheet" href="$(root)/style.css">
|
||||
<script type="text/javascript" src="$(root)/highlight.js"></script>
|
||||
<title>Offline help</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<body onload="highlight_check()">
|
||||
|
||||
$(noheader)
|
||||
|
||||
|
|
Loading…
Reference in a new issue