mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-04 07:42:59 +02:00
wiki: Fix links to wiki categories in wikiconvert
git-svn-id: trunk@49373 -
This commit is contained in:
parent
6d32f521e9
commit
a0a7b2536d
@ -179,6 +179,15 @@ span.keypress {
|
|||||||
white-space: nowrap;
|
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 */
|
/* images */
|
||||||
|
|
||||||
|
@ -179,6 +179,16 @@ span.keypress {
|
|||||||
white-space: nowrap;
|
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 */
|
/* images */
|
||||||
|
|
||||||
|
@ -69,6 +69,8 @@ type
|
|||||||
FMaxH: integer;
|
FMaxH: integer;
|
||||||
FPageFileExt: string;
|
FPageFileExt: string;
|
||||||
FUseTemplateIcons: Boolean;
|
FUseTemplateIcons: Boolean;
|
||||||
|
FAddCategories: Boolean;
|
||||||
|
procedure DoAddCategories(Page: TW2XHTMLPage);
|
||||||
procedure DoAddLinksToTranslations(Page: TW2XHTMLPage);
|
procedure DoAddLinksToTranslations(Page: TW2XHTMLPage);
|
||||||
procedure DoAddLinkToBaseDocument(Page: TW2XHTMLPage);
|
procedure DoAddLinkToBaseDocument(Page: TW2XHTMLPage);
|
||||||
procedure OnHeaderToken(Token: TWPToken);
|
procedure OnHeaderToken(Token: TWPToken);
|
||||||
@ -105,11 +107,16 @@ type
|
|||||||
function PageToFilename(Page: string; IsInternalLink, Full: boolean): string; virtual;
|
function PageToFilename(Page: string; IsInternalLink, Full: boolean): string; virtual;
|
||||||
function PageToFilename(Page: TW2XHTMLPage; Full: boolean): string; virtual;
|
function PageToFilename(Page: TW2XHTMLPage; Full: boolean): string; virtual;
|
||||||
property PageFileExt: string read FPageFileExt write SetPageFileExt;
|
property PageFileExt: string read FPageFileExt write SetPageFileExt;
|
||||||
property LinkToBaseDocument: string read FLinkToBaseDocument write FLinkToBaseDocument;
|
property LinkToBaseDocument: string
|
||||||
property AddLinksToTranslations: boolean read FAddLinksToTranslations write FAddLinksToTranslations default true;
|
read FLinkToBaseDocument write FLinkToBaseDocument;
|
||||||
property AddTOCIfHeaderCountMoreThan: integer read FAddTOCIfHeaderCountMoreThan
|
property AddLinksToTranslations: boolean
|
||||||
write FAddTOCIfHeaderCountMoreThan default 2;
|
read FAddLinksToTranslations write FAddLinksToTranslations default true;
|
||||||
property UseTemplateIcons: Boolean read FUseTemplateIcons write FUseTemplateIcons;
|
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;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -126,6 +133,48 @@ begin
|
|||||||
FCSSFilename:=AValue;
|
FCSSFilename:=AValue;
|
||||||
end;
|
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);
|
procedure TWiki2XHTMLConverter.DoAddLinksToTranslations(Page: TW2XHTMLPage);
|
||||||
var
|
var
|
||||||
TranslationPage: TW2XHTMLPage;
|
TranslationPage: TW2XHTMLPage;
|
||||||
@ -186,21 +235,23 @@ end;
|
|||||||
procedure TWiki2XHTMLConverter.DoAddLinkToBaseDocument(Page: TW2XHTMLPage);
|
procedure TWiki2XHTMLConverter.DoAddLinkToBaseDocument(Page: TW2XHTMLPage);
|
||||||
var
|
var
|
||||||
Link: String;
|
Link: String;
|
||||||
|
MainNode: TDOMElement;
|
||||||
Node: TDOMElement;
|
Node: TDOMElement;
|
||||||
doc: TXMLDocument;
|
doc: TXMLDocument;
|
||||||
begin
|
begin
|
||||||
// add <a href="BaseURL+WikiDocumentName">LinkToBaseDocument</a><br>
|
// add <a href="BaseURL+WikiDocumentName">LinkToBaseDocument</a><br>
|
||||||
doc:=Page.XHTML;
|
doc:=Page.XHTML;
|
||||||
|
MainNode := doc.CreateElement('p');
|
||||||
|
Page.BodyDOMNode.AppendChild(MainNode);
|
||||||
|
|
||||||
Node:=doc.CreateElement('a');
|
Node:=doc.CreateElement('a');
|
||||||
Page.BodyDOMNode.AppendChild(Node);
|
MainNode.AppendChild(Node);
|
||||||
Link:=Page.WikiPage.BaseURL;
|
Link:=Page.WikiPage.BaseURL;
|
||||||
if (Link<>'') and (Link[length(Link)]<>'/') then
|
if (Link<>'') and (Link[length(Link)]<>'/') then
|
||||||
Link+='/';
|
Link+='/';
|
||||||
Link+=Page.WikiDocumentName;
|
Link+=Page.WikiDocumentName;
|
||||||
Node.SetAttribute('href', Link);
|
Node.SetAttribute('href', Link);
|
||||||
Node.AppendChild(doc.CreateTextNode(LinkToBaseDocument));
|
Node.AppendChild(doc.CreateTextNode(LinkToBaseDocument));
|
||||||
Node:=doc.CreateElement('br');
|
|
||||||
Page.BodyDOMNode.AppendChild(Node);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TWiki2XHTMLConverter.OnHeaderToken(Token: TWPToken);
|
procedure TWiki2XHTMLConverter.OnHeaderToken(Token: TWPToken);
|
||||||
@ -469,7 +520,9 @@ var
|
|||||||
exit;
|
exit;
|
||||||
end
|
end
|
||||||
else if Scheme='category' then begin
|
else if Scheme='category' then begin
|
||||||
URL:=''; // show category without link
|
FCategoryList.Add(URL);
|
||||||
|
URL:='';
|
||||||
|
Caption := '';
|
||||||
exit;
|
exit;
|
||||||
end
|
end
|
||||||
else if (Scheme='image') or (Scheme='file') then begin
|
else if (Scheme='image') or (Scheme='file') then begin
|
||||||
@ -637,6 +690,9 @@ begin
|
|||||||
|
|
||||||
Page.WikiPage.Parse(@OnWikiToken,Page);
|
Page.WikiPage.Parse(@OnWikiToken,Page);
|
||||||
|
|
||||||
|
if FAddCategories then
|
||||||
|
DoAddCategories(Page);
|
||||||
|
|
||||||
if LinkToBaseDocument<>'' then
|
if LinkToBaseDocument<>'' then
|
||||||
DoAddLinkToBaseDocument(Page);
|
DoAddLinkToBaseDocument(Page);
|
||||||
|
|
||||||
@ -1160,6 +1216,7 @@ begin
|
|||||||
ShortFilenameToPage:=TFilenameToPointerTree.Create(false);
|
ShortFilenameToPage:=TFilenameToPointerTree.Create(false);
|
||||||
UsedImages:=TFilenameToPointerTree.Create(false);
|
UsedImages:=TFilenameToPointerTree.Create(false);
|
||||||
fLinkToBaseDocument:='Online version';
|
fLinkToBaseDocument:='Online version';
|
||||||
|
FAddCategories := true;
|
||||||
FAddLinksToTranslations:=true;
|
FAddLinksToTranslations:=true;
|
||||||
FAddTOCIfHeaderCountMoreThan:=2;
|
FAddTOCIfHeaderCountMoreThan:=2;
|
||||||
FUseTemplateIcons := true;
|
FUseTemplateIcons := true;
|
||||||
|
@ -72,6 +72,7 @@ type
|
|||||||
fPagesSortFilename: TAvgLvlTree; // TW2FormatPage sorted for WikiFilename
|
fPagesSortFilename: TAvgLvlTree; // TW2FormatPage sorted for WikiFilename
|
||||||
fPagesSortDocumentName: TAvgLvlTree; // TW2FormatPage sorted for WikiDocumentName
|
fPagesSortDocumentName: TAvgLvlTree; // TW2FormatPage sorted for WikiDocumentName
|
||||||
FPageClass: TW2FormatPageClass;
|
FPageClass: TW2FormatPageClass;
|
||||||
|
FCategoryList: TStringList;
|
||||||
function GetPages(Index: integer): TW2FormatPage;
|
function GetPages(Index: integer): TW2FormatPage;
|
||||||
procedure SetOutputDir(AValue: string);
|
procedure SetOutputDir(AValue: string);
|
||||||
procedure SetImagesDir(AValue: string);
|
procedure SetImagesDir(AValue: string);
|
||||||
@ -168,11 +169,13 @@ begin
|
|||||||
FTitle:='FPC/Lazarus Wiki (offline, generated '+DatetoStr(Now)+')';
|
FTitle:='FPC/Lazarus Wiki (offline, generated '+DatetoStr(Now)+')';
|
||||||
FImagesDir:='images';
|
FImagesDir:='images';
|
||||||
FNoWarnBaseURLs:=TStringToStringTree.Create(true);
|
FNoWarnBaseURLs:=TStringToStringTree.Create(true);
|
||||||
|
FCategoryList := TStringList.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TWiki2FormatConverter.Destroy;
|
destructor TWiki2FormatConverter.Destroy;
|
||||||
begin
|
begin
|
||||||
Clear;
|
Clear;
|
||||||
|
FreeAndNil(FCategoryList);
|
||||||
FreeAndNil(FNoWarnBaseURLs);
|
FreeAndNil(FNoWarnBaseURLs);
|
||||||
FreeAndNil(fPagesSortFilename);
|
FreeAndNil(fPagesSortFilename);
|
||||||
FreeAndNil(fPagesSortDocumentName);
|
FreeAndNil(fPagesSortDocumentName);
|
||||||
|
@ -169,7 +169,16 @@ begin
|
|||||||
if ParamName='css' then begin
|
if ParamName='css' then begin
|
||||||
TWiki2XHTMLConverter(Converter).CSSFilename:=ParamValue;
|
TWiki2XHTMLConverter(Converter).CSSFilename:=ParamValue;
|
||||||
continue;
|
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;
|
end;
|
||||||
if Converter is TWiki2CHMConverter then begin
|
if Converter is TWiki2CHMConverter then begin
|
||||||
// CHM parameters
|
// CHM parameters
|
||||||
@ -177,7 +186,7 @@ begin
|
|||||||
ParamValue:=TrimAndExpandFilename(ParamValue);
|
ParamValue:=TrimAndExpandFilename(ParamValue);
|
||||||
if (ParamValue='') or (not DirPathExists(ExtractFilePath(ParamValue)))
|
if (ParamValue='') or (not DirPathExists(ExtractFilePath(ParamValue)))
|
||||||
then begin
|
then begin
|
||||||
E('directory of chm file does not exists: '+ParamValue);
|
E('directory of chm file does not exist: '+ParamValue);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
TWiki2CHMConverter(Converter).CHMFile:=ParamValue;
|
TWiki2CHMConverter(Converter).CHMFile:=ParamValue;
|
||||||
@ -324,6 +333,7 @@ begin
|
|||||||
writeln;
|
writeln;
|
||||||
writeln('Options for --format=xhtml,html,chm :');
|
writeln('Options for --format=xhtml,html,chm :');
|
||||||
writeln(' --css=<path of stylesheet> : default: ',XHTMLConverter.CSSFilename);
|
writeln(' --css=<path of stylesheet> : default: ',XHTMLConverter.CSSFilename);
|
||||||
|
writeln(' --wikicategories=<yes|true|false|no> : default: ', XHTMLConverter.AddCategories);
|
||||||
writeln;
|
writeln;
|
||||||
writeln('Options for --format=chm :');
|
writeln('Options for --format=chm :');
|
||||||
writeln(' Note: the default page is the first page');
|
writeln(' Note: the default page is the first page');
|
||||||
|
@ -179,6 +179,15 @@ span.keypress {
|
|||||||
white-space: nowrap;
|
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 */
|
/* images */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user