From 1952bfcff4599afb8fc72c4eadf857c80cdbf942 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 2 Aug 2010 02:44:02 +0000 Subject: [PATCH] fixed search results so that the modified pages are valid html added exception handling in case the fcl html parser cannot read the html git-svn-id: trunk@26973 - --- .../chmhelp/lhelp/chmcontentprovider.pas | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/components/chmhelp/lhelp/chmcontentprovider.pas b/components/chmhelp/lhelp/chmcontentprovider.pas index 20e32fd846..d1183725c1 100644 --- a/components/chmhelp/lhelp/chmcontentprovider.pas +++ b/components/chmhelp/lhelp/chmcontentprovider.pas @@ -111,7 +111,7 @@ type implementation -uses ChmSpecialParser{$IFDEF CHM_SEARCH}, chmFIftiMain{$ENDIF}, chmsitemap, LCLType, SAX_HTML, Dom, XMLWrite, DOM_HTML; +uses ChmSpecialParser{$IFDEF CHM_SEARCH}, chmFIftiMain{$ENDIF}, chmsitemap, LCLType, SAX_HTML, Dom, XMLWrite, DOM_HTML, HTMWrite; type @@ -386,27 +386,44 @@ var NewStream: TMemoryStream; Highlighter: THTMLWordHighlighter; Words: TStringList; + UseOrigStream: Boolean; begin if not FLoadingSearchURL then Exit; // load html and add tags to highlight words then save back to stream NewStream := TMemoryStream.Create; - ReadHTMLFile(Doc, AStream); Words := TStringList.Create; Words.Delimiter:=' '; Words.DelimitedText:=fKeywordCombo.Text; - Highlighter := THTMLWordHighlighter.Create(Doc); - Highlighter.HighlightWords(Words, 'red'); - HighLighter.Free; + try + UseOrigStream := True; + ReadHTMLFile(Doc, AStream); + Highlighter := THTMLWordHighlighter.Create(Doc); + Highlighter.HighlightWords(Words, 'red'); + WriteHTMLFile(Doc, NewStream); + UseOrigStream := False; + finally + try + Doc.Free; + Highlighter.Free; + finally + end; + end; Words.Free; - WriteXMLFile(Doc, NewStream); - AStream.Free; - AStream := NewStream; - NewStream.Position:=0; + if not UseOrigStream then + begin + AStream.Free; + AStream := NewStream; + NewStream.Position:=0; + end + else + NewStream.Free; + + AStream.Position := 0; end; procedure TChmContentProvider.FillTOC(Data: PtrInt);