Skip to content

Commit

Permalink
Support SHFB VS2010 and VS2013 presentation styles.
Browse files Browse the repository at this point in the history
  • Loading branch information
Novacta committed Nov 15, 2021
1 parent 9407d3e commit d427d30
Show file tree
Hide file tree
Showing 599 changed files with 54,029 additions and 2 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,11 @@ TSWLatexianTemp*

## VISUAL STUDIO

# Novacta.FinTech.Documentation
**/Novacta.FinTech.Documentation/Help/
**/src/.local-nuget-debug.txt

# Documentation
**/Novacta.Shfb.LatexTools.Documentation/Help/
**/samples/SampleClassLibrary.Documentation/Help/

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
Expand Down
22 changes: 22 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### The MIT License

Copyright (c) 2021 Giovanni Lafratta.
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Novacta.Shfb.LatexTools

This repo contains the source code for **Novacta.Shfb.LatexTools**, a .NET library that
enables adding LaTeX content in documentation files created via the
[Sandcastle Help File Builder](https://github.com/EWSoftware/SHFB) project.

The tools support SHFB, version 2021.10.23.0 or later.

## Features

* The
[LatexComponent](https://novacta.github.io/shfb-latex-tools/html/T_Novacta_Shfb_LatexTools_LatexComponent.htm)
enables the representation of LaTeX equations
as images in SHFB documentation files.
Supported image formats are
[PNG](https://en.wikipedia.org/wiki/Portable_Network_Graphics)
and
[SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics).
* The
[LatexPlugIn](https://novacta.github.io/shfb-latex-tools/html/T_Novacta_Shfb_LatexTools_LatexPlugIn.htm),
which is responsible to support the *SVG* image file format for the *MSHelpViewer* help output.
* The presentation styles
[VS2010WithLatex](https://novacta.github.io/shfb-latex-tools/html/T_Novacta_Shfb_LatexTools_PresentationStyles_VS2010WithLatex.htm)
and
[VS2013WithLatex](https://novacta.github.io/shfb-latex-tools/html/T_Novacta_Shfb_LatexTools_PresentationStyles_VS2013WithLatex.htm),
which add to styles *VS2010* and *VS2013*, respectively, the ability to manage LaTeX content.

## Installation

The library is available as a [NuGet package](https://www.nuget.org/packages/Novacta.Shfb.LatexTools).

## Documentation

[Adding LaTeX equations](https://novacta.github.io/shfb-latex-tools/html/47a5afe5-726c-4f74-9ab1-90740bf0a692.htm)
includes topics showing how to define LaTeX content in help files.

Full documentation is located [here](http://novacta.github.io/shfb-latex-tools/).

## Versioning

For available versions, see the
[tags on this repository](https://github.com/novacta/shfb-latex-tools/tags).

## License

**Novacta.Shfb.LatexTools** is licensed under the
[MIT License](https://github.com/novacta/shfb-latex-tools/blob/master/LICENSE.md).
232 changes: 232 additions & 0 deletions docs/SearchHelp.aspx
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
<%@ Page Language="C#" EnableViewState="False" %>

<script runat="server">
//===============================================================================================================
// System : Sandcastle Help File Builder
// File : SearchHelp.aspx
// Author : Eric Woodruff (Eric@EWoodruff.us)
// Updated : 05/15/2014
// Note : Copyright 2007-2015, Eric Woodruff, All rights reserved
//
// This file contains the code used to search for keywords within the help topics using the full-text index
// files created by the help file builder.
//
// This code is published under the Microsoft Public License (Ms-PL). A copy of the license should be
// distributed with the code and can be found at the project website: https://GitHub.com/EWSoftware/SHFB. This
// notice, the author's name, and all copyright notices must remain intact in all applications, documentation,
// and source files.
//
// Date Who Comments
// ==============================================================================================================
// 06/24/2007 EFW Created the code
// 02/17/2012 EFW Switched to JSON serialization to support websites that use something other than ASP.NET
// such as PHP.
// 05/15/2014 EFW Updated for use with the lightweight website presentation styles
//===============================================================================================================
/// <summary>
/// This class is used to track the results and their rankings
/// </summary>
private class Ranking
{
public string Filename, PageTitle;
public int Rank;
public Ranking(string file, string title, int rank)
{
Filename = file;
PageTitle = title;
Rank = rank;
}
}
/// <summary>
/// Render the search results
/// </summary>
/// <param name="writer">The writer to which the results are written</param>
protected override void Render(HtmlTextWriter writer)
{
JavaScriptSerializer jss = new JavaScriptSerializer();
string searchText, ftiFile;
char letter;
bool sortByTitle = false;
jss.MaxJsonLength = Int32.MaxValue;
// The keywords for which to search should be passed in the query string
searchText = this.Request.QueryString["Keywords"];
if(String.IsNullOrEmpty(searchText))
{
writer.Write("<strong>Nothing found</strong>");
return;
}
// An optional SortByTitle option can also be specified
if(this.Request.QueryString["SortByTitle"] != null)
sortByTitle = Convert.ToBoolean(this.Request.QueryString["SortByTitle"]);
List<string> keywords = this.ParseKeywords(searchText);
List<char> letters = new List<char>();
List<string> fileList;
Dictionary<string, List<long>> ftiWords, wordDictionary = new Dictionary<string,List<long>>();
// Load the file index
using(StreamReader sr = new StreamReader(Server.MapPath("fti/FTI_Files.json")))
{
fileList = jss.Deserialize<List<string>>(sr.ReadToEnd());
}
// Load the required word index files
foreach(string word in keywords)
{
letter = word[0];
if(!letters.Contains(letter))
{
letters.Add(letter);
ftiFile = Server.MapPath(String.Format(CultureInfo.InvariantCulture, "fti/FTI_{0}.json", (int)letter));
if(File.Exists(ftiFile))
{
using(StreamReader sr = new StreamReader(ftiFile))
{
ftiWords = jss.Deserialize<Dictionary<string, List<long>>>(sr.ReadToEnd());
}
foreach(string ftiWord in ftiWords.Keys)
wordDictionary.Add(ftiWord, ftiWords[ftiWord]);
}
}
}
// Perform the search and return the results as a block of HTML
writer.Write(this.Search(keywords, fileList, wordDictionary, sortByTitle));
}
/// <summary>
/// Split the search text up into keywords
/// </summary>
/// <param name="keywords">The keywords to parse</param>
/// <returns>A list containing the words for which to search</returns>
private List<string> ParseKeywords(string keywords)
{
List<string> keywordList = new List<string>();
string checkWord;
string[] words = Regex.Split(keywords, @"\W+");
foreach(string word in words)
{
checkWord = word.ToLower(CultureInfo.InvariantCulture);
if(checkWord.Length > 2 && !Char.IsDigit(checkWord[0]) && !keywordList.Contains(checkWord))
keywordList.Add(checkWord);
}
return keywordList;
}
/// <summary>
/// Search for the specified keywords and return the results as a block of HTML
/// </summary>
/// <param name="keywords">The keywords for which to search</param>
/// <param name="fileInfo">The file list</param>
/// <param name="wordDictionary">The dictionary used to find the words</param>
/// <param name="sortByTitle">True to sort by title, false to sort by ranking</param>
/// <returns>A block of HTML representing the search results</returns>
private string Search(List<string> keywords, List<string> fileInfo,
Dictionary<string, List<long>> wordDictionary, bool sortByTitle)
{
StringBuilder sb = new StringBuilder(10240);
Dictionary<string, List<long>> matches = new Dictionary<string, List<long>>();
List<long> occurrences;
List<int> matchingFileIndices = new List<int>(), occurrenceIndices = new List<int>();
List<Ranking> rankings = new List<Ranking>();
string filename, title;
string[] fileIndex;
bool isFirst = true;
int idx, wordCount, matchCount;
foreach(string word in keywords)
{
if(!wordDictionary.TryGetValue(word, out occurrences))
return "<strong>Nothing found</strong>";
matches.Add(word, occurrences);
occurrenceIndices.Clear();
// Get a list of the file indices for this match
foreach(long entry in occurrences)
occurrenceIndices.Add((int)(entry >> 16));
if(isFirst)
{
isFirst = false;
matchingFileIndices.AddRange(occurrenceIndices);
}
else
{
// After the first match, remove files that do not appear for
// all found keywords.
for(idx = 0; idx < matchingFileIndices.Count; idx++)
if(!occurrenceIndices.Contains(matchingFileIndices[idx]))
{
matchingFileIndices.RemoveAt(idx);
idx--;
}
}
}
if(matchingFileIndices.Count == 0)
return "<strong>Nothing found</strong>";
// Rank the files based on the number of times the words occurs
foreach(int index in matchingFileIndices)
{
// Split out the title, filename, and word count
fileIndex = fileInfo[index].Split('\x0');
title = fileIndex[0];
filename = fileIndex[1];
wordCount = Convert.ToInt32(fileIndex[2]);
matchCount = 0;
foreach(string word in keywords)
{
occurrences = matches[word];
foreach(long entry in occurrences)
if((int)(entry >> 16) == index)
matchCount += (int)(entry & 0xFFFF);
}
rankings.Add(new Ranking(filename, title, matchCount * 1000 / wordCount));
if(rankings.Count > 99)
break;
}
// Sort by rank in descending order or by page title in ascending order
rankings.Sort(delegate (Ranking x, Ranking y)
{
if(!sortByTitle)
return y.Rank - x.Rank;
return x.PageTitle.CompareTo(y.PageTitle);
});
// Format the file list and return the results
sb.Append("<ol>");
foreach(Ranking r in rankings)
sb.AppendFormat("<li><a href=\"{0}\" target=\"_blank\">{1}</a></li>", r.Filename, r.PageTitle);
sb.Append("</ol>");
if(rankings.Count < matchingFileIndices.Count)
sb.AppendFormat("<p>Omitted {0} more results</p>", matchingFileIndices.Count - rankings.Count);
return sb.ToString();
}
</script>
Loading

0 comments on commit d427d30

Please sign in to comment.