/// <summary> /// Converts HTML content returned by a dictionary to a <see cref="Section"/>. /// </summary> /// <param name="dictionary">The dictionary. It is neccessary to retrieve CSS files referenced by the HTML content.</param> /// <param name="htmlContent">The HTML to convert.</param> /// <returns>A <see cref="Section"/> that represents the HTML content.</returns> public Section ConvertHtmlContentToSection(ISlobDictionary dictionary, string htmlContent) { Func <string, string, string> cssStyleSheetProvider = (cssFileName, refFileName) => { if (dictionary.TryGetValue(cssFileName, out var entry)) { return(entry.Content); } else { return(null); } }; try { var section = (Section)_converter.Convert(htmlContent, false, cssStyleSheetProvider, null); return(section); } catch (Exception ex) { } return(null); }
/// <summary> /// Tries to find the key <paramref name="searchText"/> in the dictionary. /// </summary> /// <param name="searchText">The text to search. If this original text was not found, on return, the parameter contains the key for which the content is returned.</param> /// <param name="dictionary">The dictionary.</param> /// <returns>A tuple consisting of the content, the content identifer, and a boolean. The boolean is true if the original search text was found in the dictionary. /// If the original search text was not found, the boolean is false, and <paramref name="searchText"/>contains the search text that was found.</returns> private (string Content, string ContentId, bool foundOriginal) GetResult(ref string searchText, ISlobDictionary dictionary) { var searchKey = _compareInfo.GetSortKey(searchText); var index = Array.BinarySearch(_sortKeys, searchKey, new UnicodeStringSorter()); (string Content, string ContentId)result = (null, null); bool found = false; if (index >= 0) { result = dictionary[searchText]; found = true; } else { index = ~index; if (index < _keys.Length) { searchText = _keys[index]; result = dictionary[searchText]; } } return(result.Content, result.ContentId, found); }