mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-19 13:21:46 +02:00
wiki test: collect text
git-svn-id: trunk@35651 -
This commit is contained in:
parent
34ba568cd6
commit
5369526396
@ -43,7 +43,7 @@ type
|
||||
WikiDocumentName: string; // the path in the Wiki
|
||||
constructor Create(TheConverter: TWiki2FormatConverter); virtual;
|
||||
destructor Destroy; override;
|
||||
procedure ParseWikiDoc;
|
||||
procedure ParseWikiDoc(KeepWikiDoc: boolean);
|
||||
end;
|
||||
TW2FormatPageClass = class of TW2FormatPage;
|
||||
|
||||
@ -174,7 +174,7 @@ begin
|
||||
fPages.Add(Result);
|
||||
end;
|
||||
if ParseNow then
|
||||
Result.ParseWikiDoc;
|
||||
Result.ParseWikiDoc(false);
|
||||
end;
|
||||
|
||||
procedure TWiki2FormatConverter.Convert;
|
||||
@ -189,7 +189,7 @@ begin
|
||||
for i:=0 to Count-1 do begin
|
||||
Page:=Pages[i];
|
||||
Page.WikiPage.LanguageTags:=LanguageTags;
|
||||
Page.ParseWikiDoc;
|
||||
Page.ParseWikiDoc(false);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -220,31 +220,36 @@ begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TW2FormatPage.ParseWikiDoc;
|
||||
procedure TW2FormatPage.ParseWikiDoc(KeepWikiDoc: boolean);
|
||||
begin
|
||||
if WikiDoc=nil then begin
|
||||
try
|
||||
ReadXMLFile(WikiDoc,WikiFilename,[]);
|
||||
except
|
||||
on E: Exception do
|
||||
WikiErrorMsg:=E.Message;
|
||||
try
|
||||
if WikiDoc=nil then begin
|
||||
try
|
||||
ReadXMLFile(WikiDoc,WikiFilename,[]);
|
||||
except
|
||||
on E: Exception do
|
||||
WikiErrorMsg:=E.Message;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
if WikiErrorMsg<>'' then
|
||||
raise Exception.Create(WikiFilename+': '+WikiErrorMsg);
|
||||
if WikiPage=nil then begin
|
||||
WikiPage:=TWikiPage.Create;
|
||||
try
|
||||
if Converter<>nil then
|
||||
WikiPage.OnLog:=Converter.OnLog;
|
||||
WikiPage.LoadFromDoc(WikiDoc);
|
||||
except
|
||||
on E: Exception do
|
||||
WikiErrorMsg:=E.Message;
|
||||
if WikiErrorMsg<>'' then
|
||||
raise Exception.Create(WikiFilename+': '+WikiErrorMsg);
|
||||
if WikiPage=nil then begin
|
||||
WikiPage:=TWikiPage.Create;
|
||||
try
|
||||
if Converter<>nil then
|
||||
WikiPage.OnLog:=Converter.OnLog;
|
||||
WikiPage.LoadFromDoc(WikiDoc);
|
||||
except
|
||||
on E: Exception do
|
||||
WikiErrorMsg:=E.Message;
|
||||
end;
|
||||
end;
|
||||
if WikiErrorMsg<>'' then
|
||||
raise Exception.Create(WikiFilename+': '+WikiErrorMsg);
|
||||
finally
|
||||
if not KeepWikiDoc then
|
||||
FreeAndNil(WikiDoc);
|
||||
end;
|
||||
if WikiErrorMsg<>'' then
|
||||
raise Exception.Create(WikiFilename+': '+WikiErrorMsg);
|
||||
end;
|
||||
|
||||
function WikiPageToFilename(Page: string; IsInternalLink, AppendCaseID: boolean): string;
|
||||
|
@ -215,24 +215,62 @@ procedure TWiki2HelpConverter.ExtractTextToken(Token: TWPToken);
|
||||
var
|
||||
Page: TW2HelpPage;
|
||||
W: TWikiPage;
|
||||
Txt: String;
|
||||
CurNode: TWHTextNode;
|
||||
StartP, EndP: PChar;
|
||||
NodeType: TWHTextNodeType;
|
||||
TextToken: TWPTextToken;
|
||||
LinkToken: TWPLinkToken;
|
||||
Caption: String;
|
||||
begin
|
||||
Page:=TW2HelpPage(Token.UserData);
|
||||
W:=Page.WikiPage;
|
||||
CurNode:=Page.CurNode;
|
||||
if CurNode=nil then CurNode:=Page.TextRoot;
|
||||
case Token.Token of
|
||||
wptText:
|
||||
if Token is TWPTextToken then begin
|
||||
// ToDo
|
||||
TextToken:=TWPTextToken(Token);
|
||||
StartP:=PChar(W.Src)+TextToken.StartPos-1;
|
||||
EndP:=PChar(W.Src)+TextToken.EndPos-1;
|
||||
while (StartP<EndP) and (StartP^ in [#1..#31,' ']) do inc(StartP);
|
||||
if StartP<EndP then begin
|
||||
// not only space
|
||||
Txt:=copy(W.Src,TextToken.StartPos,TextToken.EndPos-TextToken.StartPos);
|
||||
CurNode.Txt:=CurNode.Txt+Txt;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
wptSection:
|
||||
; // ToDo
|
||||
wptHeader:
|
||||
; // ToDo
|
||||
|
||||
wptSection,wptHeader:
|
||||
if Token.Range=wprOpen then begin
|
||||
if Token.Token=wptHeader then
|
||||
NodeType:=whnHeader
|
||||
else
|
||||
NodeType:=whnTxt;
|
||||
Page.CurNode:=TWHTextNode.Create(NodeType,CurNode);
|
||||
exit;
|
||||
end else if Token.Range=wprClose then begin
|
||||
Page.CurNode:=CurNode.Parent;
|
||||
exit;
|
||||
end;
|
||||
|
||||
wptInternLink, wptExternLink:
|
||||
; // ToDo
|
||||
else
|
||||
// add a space to separate words
|
||||
// ToDo
|
||||
if Token is TWPLinkToken then begin
|
||||
LinkToken:=TWPLinkToken(Token);
|
||||
Caption:=copy(W.Src,LinkToken.CaptionStartPos,
|
||||
LinkToken.CaptionEndPos-LinkToken.CaptionStartPos);
|
||||
if Caption<>'' then begin
|
||||
CurNode:=TWHTextNode.Create(whnLink,CurNode);
|
||||
CurNode.Txt:=Caption;
|
||||
// do not exit, append a space to the current node
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
// add a space to separate words
|
||||
if (CurNode.Txt='') or (not (CurNode.Txt[length(CurNode.Txt)] in [#1..#31,' ']))
|
||||
then
|
||||
CurNode.Txt:=CurNode.Txt+' ';
|
||||
end;
|
||||
|
||||
procedure TWiki2HelpConverter.ParallelExtractPageText(Index: PtrInt;
|
||||
@ -261,7 +299,7 @@ begin
|
||||
for i:=StartIndex to EndIndex do begin
|
||||
Page:=TW2HelpPage(Pages[i]);
|
||||
try
|
||||
Page.ParseWikiDoc;
|
||||
Page.ParseWikiDoc(false);
|
||||
except
|
||||
on E: Exception do begin
|
||||
Log('ERROR: '+Page.WikiFilename+': '+E.Message);
|
||||
|
Loading…
Reference in New Issue
Block a user