diff --git a/components/wiki/lazwiki/wiki2xhtmlconvert.pas b/components/wiki/lazwiki/wiki2xhtmlconvert.pas
index 24a7e626f7..02b988a087 100644
--- a/components/wiki/lazwiki/wiki2xhtmlconvert.pas
+++ b/components/wiki/lazwiki/wiki2xhtmlconvert.pas
@@ -214,6 +214,8 @@ var
Node: TDOMElement;
TargetPage: TW2XHTMLPage;
FoundImgFile: String;
+ DocumentName: String;
+ Anchor: String;
begin
Result:=false;
if LinkToken.Token=wptExternLink then exit;
@@ -277,10 +279,20 @@ var
// default: a page
if URL<>'' then begin
- Filename:=PageToFilename(URL,true,false);
+ p:=Pos('#',URL);
+ if p<1 then begin
+ DocumentName:=URL;
+ Anchor:='';
+ end else begin
+ DocumentName:=LeftStr(URL,p-1);
+ Anchor:=copy(URL,p+1,length(URL));
+ end;
+ Filename:=PageToFilename(DocumentName,true,false);
TargetPage:=TW2XHTMLPage(ShortFilenameToPage[Filename]);
if (TargetPage<>nil) then begin
URL:=GetPageLink(TargetPage);
+ if Anchor<>'' then
+ URL+='#'+Anchor;
end else if (not FileExistsUTF8(Filename)) then begin
if WarnMissingPageLinks and WarnURL(LinkToken.Link) then
Log('WARNING: TWiki2XHTMLConverter.InsertLink "'+dbgstr(LinkToken.Link)+'": file not found: "'+Filename+'" at '+W.PosToStr(LinkToken.LinkStartPos,true));
diff --git a/components/wiki/lazwiki/wikiparser.pas b/components/wiki/lazwiki/wikiparser.pas
index b1a3a5f3ef..f4a8449bc2 100644
--- a/components/wiki/lazwiki/wikiparser.pas
+++ b/components/wiki/lazwiki/wikiparser.pas
@@ -1536,7 +1536,7 @@ begin
case Result[i] of
' ',#9:
Result[i]:='_';
- #0..#8,#10..#31,'#','$','[',']','{','}','<','>':
+ #0..#8,#10..#31,'$','[',']','{','}','<','>':
Delete(Result,i,1);
'%':
begin
diff --git a/components/wiki/test/wikisearchmain.pas b/components/wiki/test/wikisearchmain.pas
index c523ce66f4..283bbc131e 100644
--- a/components/wiki/test/wikisearchmain.pas
+++ b/components/wiki/test/wikisearchmain.pas
@@ -290,6 +290,7 @@ begin
WikiHelp.ImagesDirectory:=SetDirSeparators('../images');
WikiHelp.Converter.OutputDir:='';
WikiHelp.Converter.CSSFilename:='wiki.css';
+ WikiHelp.Converter.WarnMissingPageLinks:=true;
WikiHelp.OnScanned:=@WikiHelpScanned;
WikiHelp.OnSearched:=@WikiHelpSearched;
WikiHelp.ResultsCSSURL:='wiki.css';