diff options
author | michael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2021-01-02 19:05:31 +0000 |
---|---|---|
committer | michael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2021-01-02 19:05:31 +0000 |
commit | 663d142c0d006382bcf5528aff9cc82b103f17fe (patch) | |
tree | 601fff3378fa447d9bb0a7caecc0d3083c26e6f1 | |
parent | 060662a072937e944b0b33d36c93529cc8b85112 (diff) | |
download | fpc-663d142c0d006382bcf5528aff9cc82b103f17fe.tar.gz |
* Fix class tree & lists
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@47978 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r-- | utils/fpdoc/dw_basemd.pp | 31 | ||||
-rw-r--r-- | utils/fpdoc/dw_markdown.pp | 71 |
2 files changed, 72 insertions, 30 deletions
diff --git a/utils/fpdoc/dw_basemd.pp b/utils/fpdoc/dw_basemd.pp index b8387f0d4e..0b365a9e56 100644 --- a/utils/fpdoc/dw_basemd.pp +++ b/utils/fpdoc/dw_basemd.pp @@ -110,6 +110,8 @@ Type function EscapeMarkDown(aText: Domstring): string; function EscapeMarkDown(aText: String): string; function CreateLink(Const aText,aLink : String) : String; + function GetListPrefix: String;virtual; + // Append to current line procedure AppendToLine(aText: DomString; DoEscape: boolean = true); procedure AppendToLine(aText: UTF8String; DoEscape: boolean = true); virtual; @@ -403,22 +405,29 @@ begin if FCurrentIndentIndex<=0 then FPDocError(SErrMinIndentStack); Dec(FCurrentIndentIndex); + CalcPrefix; end; procedure TBaseMarkdownWriter.StartList(aType: TListType); begin If FListStack>=MaxLists then FPDocError(SErrMaxListStack); + OutputCurrentLine; Inc(FListStack); FListTypes[FListStack]:=aType; + if FListStack>1 then + PushIndent(CurrentIndent+Length(GetListprefix)); end; procedure TBaseMarkdownWriter.StopList(aType: TListType); begin + OutputCurrentLine; If FListStack<=0 then FPDocError(SErrMinListStack); if FListTypes[FListStack]<>aType then FPDocError(SErrPopListStack); + if FListStack>1 then + PopIndent; Dec(FListStack); end; @@ -451,6 +460,7 @@ function TBaseMarkdownWriter.CurrentList: TListType; begin if FListStack=0 then FPDOcError(SErrNotInList); + Result:=FListTypes[FListStack]; end; procedure TBaseMarkdownWriter.EndSpan(aRender : TRender); @@ -629,18 +639,25 @@ begin StopList(ltDefinition); end; -procedure TBaseMarkdownWriter.DescrBeginListItem; + +function TBaseMarkdownWriter.GetListPrefix : String; + begin Case CurrentList of - ltOrdered : AppendToLine('1. '); - ltUnordered : AppendToLine('- '); - ltDefinition : - begin - AppendToLine('- '); - end; + ltOrdered : Result:='1. '; + ltUnordered : Result:='- '; + ltDefinition : Result:=': '; end; end; +procedure TBaseMarkdownWriter.DescrBeginListItem; +Var + Pref : String; +begin + Pref:=GetListPrefix; + AppendToLine(Pref); +end; + procedure TBaseMarkdownWriter.DescrEndListItem; begin diff --git a/utils/fpdoc/dw_markdown.pp b/utils/fpdoc/dw_markdown.pp index 6c5238e5ea..8b82e710dd 100644 --- a/utils/fpdoc/dw_markdown.pp +++ b/utils/fpdoc/dw_markdown.pp @@ -26,7 +26,7 @@ type TMemberListOption = (mloAppendParent,mloAppendType,mloCheckVisibility); TMemberListOptions = Set of TMemberListOption; - + TNavigationMode = (nmUnitTree,nmUnitSubTree); { TMarkdownWriter } TMarkdownWriter = class(TBaseMarkdownWriter) @@ -37,8 +37,10 @@ type FAdditionalConfig : TStrings; FFooterMarkDown : TStrings; FHeaderMarkDown : TStrings; + FNavigationMode: TNavigationMode; FOnTest: TNotifyEvent; FNavigation : TStrings; + FUnitSubTreeStarted : Boolean; function GetAdditionalConfig: TStrings; function GetClassDeclaration(aEl: TPasClassType): String; function GetClassDeclarationFirstLine(aEl: TPasClassType): String; @@ -137,6 +139,7 @@ type Property HeaderMarkDown : TStrings Read GetHeaderMarkDown; Property FooterMarkDown : TStrings Read GetFooterMarkDown; property AdditionalConfig : TStrings Read GetAdditionalConfig; + property NavigationMode: TNavigationMode Read FNavigationMode; end; implementation @@ -180,35 +183,47 @@ procedure TMarkdownWriter.AddToNavigation(const aFileName: String; aElement: TPa aFile:=' '''+aFile+''''; FNavigation.Add(StringOfChar(' ',aLevel*4)+'- '+aName+aFile); end; +Var + Offs : Integer; begin if aElement is TPasPackage then begin - case aSubPageIndex of - IdentifierIndex: - begin - AddToNav(1,SDocPackageLinkTitle,''); - AddToNav(2,SDocOverview,aFileName); - end; - IndexSubIndex : AddToNav(2,SDocIdentifierIndex,aFileName); - ClassHierarchySubIndex : AddToNav(2,SDocPackageClassHierarchy,aFileName); - end + case aSubPageIndex of + IdentifierIndex: + begin + AddToNav(1,SDocPackageLinkTitle,''); + AddToNav(2,SDocOverview,aFileName); + end; + IndexSubIndex : AddToNav(2,SDocIdentifierIndex,aFileName); + ClassHierarchySubIndex : AddToNav(2,SDocPackageClassHierarchy,aFileName); + end end else if (aElement is TPasModule) then begin - case aSubPageIndex of - IdentifierIndex : - begin - AddToNav(1,Format(StringReplace(SDocUnitMenuTitle,'''','',[rfReplaceALl]),[aElement.Name]),''); - AddToNav(2,SDocOverview,aFileName); - end; - ResstrSubindex: AddToNav(2,SDocResStrings,aFileName); - ConstsSubindex: AddToNav(2,SDocConstants,aFileName); - TypesSubindex: AddToNav(2,SDocTypes,aFileName); - ClassesSubindex: AddToNav(2,SDocClasses,aFileName); - ProcsSubindex: AddToNav(2,SDocProceduresAndFunctions,aFileName); - VarsSubindex: AddToNav(2,SDocVariables,aFileName); - end; + offS:=Ord (NavigationMode=nmUnitSubTree); + if Offs=1 then + if Not FUnitSubTreeStarted then + begin + FUnitSubTreeStarted:=True; + AddToNav(1,SDocUnits,''); + end;; + case aSubPageIndex of + IdentifierIndex : + begin + if Offs=0 then + AddToNav(1+Offs,Format(StringReplace(SDocUnitMenuTitle,'''','',[rfReplaceALl]),[aElement.Name]),'') + else + AddToNav(1+Offs,aElement.Name,''); + AddToNav(2+offs,SDocOverview,aFileName); + end; + ResstrSubindex: AddToNav(2+Offs,SDocResStrings,aFileName); + ConstsSubindex: AddToNav(2+Offs,SDocConstants,aFileName); + TypesSubindex: AddToNav(2+Offs,SDocTypes,aFileName); + ClassesSubindex: AddToNav(2+Offs,SDocClasses,aFileName); + ProcsSubindex: AddToNav(2+Offs,SDocProceduresAndFunctions,aFileName); + VarsSubindex: AddToNav(2+Offs,SDocVariables,aFileName); + end; end end; @@ -811,6 +826,7 @@ var DocNode: TDocNode; begin DocNode:=AElement.TopicNode; + AppendTitle(AElement.Name); if not Assigned(DocNode) then // should always be true, but we're being careful. exit; AppendShortDescr(AElement, DocNode); @@ -1875,10 +1891,19 @@ begin else if Cmd = '--image-url' then FBaseImageURL := Arg else if Cmd = '--theme' then + begin if arg='-' then Theme:='' else Theme := Arg + end + else if Cmd='--navigation' then + begin + if SameText(Arg,'UnitSubTree') then + FNavigationMode:=nmUnitSubTree + else if SameText(Arg,'UnitTree') then + FNavigationMode:=nmUnitTree; + end; end; class procedure TMarkdownWriter.Usage(List: TStrings); |