wiki: Fix links to wiki categories in wikiconvert

git-svn-id: trunk@49373 -
This commit is contained in:
wp 2015-06-20 16:52:08 +00:00
parent 6d32f521e9
commit a0a7b2536d
6 changed files with 109 additions and 11 deletions

View File

@ -179,6 +179,15 @@ span.keypress {
white-space: nowrap;
}
div.categories {
background-color: #F9F9F9;
border: 1px solid #2F6FAB;
color: black;
padding: 1em;
padding-top: 0.75em;
line-height: 1.25em;
}
/* images */

View File

@ -179,6 +179,16 @@ span.keypress {
white-space: nowrap;
}
div.categories {
background-color: #F9F9F9;
border: 1px solid #2F6FAB;
color: black;
padding: 1em;
padding-top: 0.75em;
line-height: 1.25em;
font-color: #2F6FAB;
}
/* images */

View File

@ -69,6 +69,8 @@ type
FMaxH: integer;
FPageFileExt: string;
FUseTemplateIcons: Boolean;
FAddCategories: Boolean;
procedure DoAddCategories(Page: TW2XHTMLPage);
procedure DoAddLinksToTranslations(Page: TW2XHTMLPage);
procedure DoAddLinkToBaseDocument(Page: TW2XHTMLPage);
procedure OnHeaderToken(Token: TWPToken);
@ -105,11 +107,16 @@ type
function PageToFilename(Page: string; IsInternalLink, Full: boolean): string; virtual;
function PageToFilename(Page: TW2XHTMLPage; Full: boolean): string; virtual;
property PageFileExt: string read FPageFileExt write SetPageFileExt;
property LinkToBaseDocument: string read FLinkToBaseDocument write FLinkToBaseDocument;
property AddLinksToTranslations: boolean read FAddLinksToTranslations write FAddLinksToTranslations default true;
property AddTOCIfHeaderCountMoreThan: integer read FAddTOCIfHeaderCountMoreThan
write FAddTOCIfHeaderCountMoreThan default 2;
property UseTemplateIcons: Boolean read FUseTemplateIcons write FUseTemplateIcons;
property LinkToBaseDocument: string
read FLinkToBaseDocument write FLinkToBaseDocument;
property AddLinksToTranslations: boolean
read FAddLinksToTranslations write FAddLinksToTranslations default true;
property AddTOCIfHeaderCountMoreThan: integer
read FAddTOCIfHeaderCountMoreThan write FAddTOCIfHeaderCountMoreThan default 2;
property AddCategories: Boolean
read FAddCategories write FAddCategories default true;
property UseTemplateIcons: Boolean
read FUseTemplateIcons write FUseTemplateIcons;
end;
implementation
@ -126,6 +133,48 @@ begin
FCSSFilename:=AValue;
end;
procedure TWiki2XHTMLConverter.DoAddCategories(Page: TW2XHTMLPage);
var
doc: TXMLDocument;
CategoriesNode: TDOMElement;
node: TDOMElement;
category, url, txt: String;
i: Integer;
begin
if FCategoryList.Count = 0 then
exit;
doc := Page.XHTML;
url := Page.WikiPage.BaseURL;
if (url <> '') and (url[Length(url)] <> '/') then
url += '/';
CategoriesNode := doc.CreateElement('div');
CategoriesNode.SetAttribute('class', 'categories');
Page.BodyDOMNode.AppendChild(CategoriesNode);
// Add "Categories:"
node := doc.CreateElement('a');
node.SetAttribute('href', url+'Special:Categories');
CategoriesNode.AppendChild(node);
CategoriesNode.AppendChild(doc.CreateTextNode('Categories: '));
for i:=0 to FCategoryList.Count-1 do begin
category := FCategoryList[i];
// Add link to category
node := doc.CreateElement('a');
node.SetAttribute('href', url + category);
txt := Copy(category, pos(':', category)+1, MaxInt);
node.AppendChild(doc.CreateTextNode(txt));
CategoriesNode.AppendChild(node);
// Add separator
if i < FCategoryList.Count-1 then
CategoriesNode.AppendChild(doc.CreateTextNode(' | '));
end;
end;
procedure TWiki2XHTMLConverter.DoAddLinksToTranslations(Page: TW2XHTMLPage);
var
TranslationPage: TW2XHTMLPage;
@ -186,21 +235,23 @@ end;
procedure TWiki2XHTMLConverter.DoAddLinkToBaseDocument(Page: TW2XHTMLPage);
var
Link: String;
MainNode: TDOMElement;
Node: TDOMElement;
doc: TXMLDocument;
begin
// add <a href="BaseURL+WikiDocumentName">LinkToBaseDocument</a><br>
doc:=Page.XHTML;
MainNode := doc.CreateElement('p');
Page.BodyDOMNode.AppendChild(MainNode);
Node:=doc.CreateElement('a');
Page.BodyDOMNode.AppendChild(Node);
MainNode.AppendChild(Node);
Link:=Page.WikiPage.BaseURL;
if (Link<>'') and (Link[length(Link)]<>'/') then
Link+='/';
Link+=Page.WikiDocumentName;
Node.SetAttribute('href', Link);
Node.AppendChild(doc.CreateTextNode(LinkToBaseDocument));
Node:=doc.CreateElement('br');
Page.BodyDOMNode.AppendChild(Node);
end;
procedure TWiki2XHTMLConverter.OnHeaderToken(Token: TWPToken);
@ -469,7 +520,9 @@ var
exit;
end
else if Scheme='category' then begin
URL:=''; // show category without link
FCategoryList.Add(URL);
URL:='';
Caption := '';
exit;
end
else if (Scheme='image') or (Scheme='file') then begin
@ -637,6 +690,9 @@ begin
Page.WikiPage.Parse(@OnWikiToken,Page);
if FAddCategories then
DoAddCategories(Page);
if LinkToBaseDocument<>'' then
DoAddLinkToBaseDocument(Page);
@ -1160,6 +1216,7 @@ begin
ShortFilenameToPage:=TFilenameToPointerTree.Create(false);
UsedImages:=TFilenameToPointerTree.Create(false);
fLinkToBaseDocument:='Online version';
FAddCategories := true;
FAddLinksToTranslations:=true;
FAddTOCIfHeaderCountMoreThan:=2;
FUseTemplateIcons := true;

View File

@ -72,6 +72,7 @@ type
fPagesSortFilename: TAvgLvlTree; // TW2FormatPage sorted for WikiFilename
fPagesSortDocumentName: TAvgLvlTree; // TW2FormatPage sorted for WikiDocumentName
FPageClass: TW2FormatPageClass;
FCategoryList: TStringList;
function GetPages(Index: integer): TW2FormatPage;
procedure SetOutputDir(AValue: string);
procedure SetImagesDir(AValue: string);
@ -168,11 +169,13 @@ begin
FTitle:='FPC/Lazarus Wiki (offline, generated '+DatetoStr(Now)+')';
FImagesDir:='images';
FNoWarnBaseURLs:=TStringToStringTree.Create(true);
FCategoryList := TStringList.Create;
end;
destructor TWiki2FormatConverter.Destroy;
begin
Clear;
FreeAndNil(FCategoryList);
FreeAndNil(FNoWarnBaseURLs);
FreeAndNil(fPagesSortFilename);
FreeAndNil(fPagesSortDocumentName);

View File

@ -169,7 +169,16 @@ begin
if ParamName='css' then begin
TWiki2XHTMLConverter(Converter).CSSFilename:=ParamValue;
continue;
end
end;
if ParamName='wikicategories' then begin
case ParamValue of
'yes', 'true': TWiki2XHTMLConverter(Converter).AddCategories := true;
'no', 'false': TWiki2XHTMLConverter(Converter).AddCategories := false;
else
E('Incorrect parameter value ('+Param+')');
end;
Continue;
end;
end;
if Converter is TWiki2CHMConverter then begin
// CHM parameters
@ -177,7 +186,7 @@ begin
ParamValue:=TrimAndExpandFilename(ParamValue);
if (ParamValue='') or (not DirPathExists(ExtractFilePath(ParamValue)))
then begin
E('directory of chm file does not exists: '+ParamValue);
E('directory of chm file does not exist: '+ParamValue);
exit;
end;
TWiki2CHMConverter(Converter).CHMFile:=ParamValue;
@ -324,6 +333,7 @@ begin
writeln;
writeln('Options for --format=xhtml,html,chm :');
writeln(' --css=<path of stylesheet> : default: ',XHTMLConverter.CSSFilename);
writeln(' --wikicategories=<yes|true|false|no> : default: ', XHTMLConverter.AddCategories);
writeln;
writeln('Options for --format=chm :');
writeln(' Note: the default page is the first page');

View File

@ -179,6 +179,15 @@ span.keypress {
white-space: nowrap;
}
div.categories {
background-color: #F9F9F9;
border: 1px solid #2F6FAB;
color: black;
padding: 1em;
padding-top: 0.75em;
line-height: 1.25em;
}
/* images */