dw_html.pp 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024
  1. {
  2. FPDoc - Free Pascal Documentation Tool
  3. Copyright (C) 2000 - 2005 by
  4. Areca Systems GmbH / Sebastian Guenther, [email protected]
  5. * HTML/XHTML output generator
  6. See the file COPYING, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. }
  12. {$mode objfpc}
  13. {$H+}
  14. unit dw_HTML;
  15. interface
  16. uses Classes, DOM, DOM_HTML, dGlobals, PasTree, dWriter, ChmWriter, ChmBase;
  17. const
  18. // Subpage indices for modules
  19. ResstrSubindex = 1;
  20. ConstsSubindex = 2;
  21. TypesSubindex = 3;
  22. ClassesSubindex = 4;
  23. ProcsSubindex = 5;
  24. VarsSubindex = 6;
  25. // Maybe needed later for topic overview ??
  26. TopicsSubIndex = 7;
  27. // Subpage indices for classes
  28. PropertiesByInheritanceSubindex = 1;
  29. PropertiesByNameSubindex = 2;
  30. MethodsByInheritanceSubindex = 3;
  31. MethodsByNameSubindex = 4;
  32. EventsByInheritanceSubindex = 5;
  33. EventsByNameSubindex = 6;
  34. type
  35. TFileAllocator = class
  36. public
  37. procedure AllocFilename(AElement: TPasElement; ASubindex: Integer); virtual;
  38. function GetFilename(AElement: TPasElement;
  39. ASubindex: Integer): String; virtual; abstract;
  40. function GetRelativePathToTop(AElement: TPasElement): String; virtual;
  41. function GetCSSFilename(ARelativeTo: TPasElement): DOMString; virtual;
  42. end;
  43. TShortNameFileAllocator = class(TFileAllocator)
  44. private
  45. FExtension: String;
  46. public
  47. constructor Create(const AExtension: String);
  48. procedure AllocFilename(AElement: TPasElement; ASubindex: Integer); override;
  49. property Extension: String read FExtension;
  50. end;
  51. TLongNameFileAllocator = class(TFileAllocator)
  52. private
  53. FExtension: String;
  54. public
  55. constructor Create(const AExtension: String);
  56. function GetFilename(AElement: TPasElement;
  57. ASubindex: Integer): String; override;
  58. function GetRelativePathToTop(AElement: TPasElement): String; override;
  59. property Extension: String read FExtension;
  60. end;
  61. TPageInfo = class
  62. Element: TPasElement;
  63. SubpageIndex: Integer;
  64. end;
  65. { THTMLWriter }
  66. THTMLWriter = class(TFPDocWriter)
  67. private
  68. FOnTest: TNotifyEvent;
  69. FPackage: TPasPackage;
  70. function GetPageCount: Integer;
  71. procedure SetOnTest(const AValue: TNotifyEvent);
  72. protected
  73. FAllocator: TFileAllocator;
  74. Procedure CreateAllocator; virtual;
  75. CurDirectory: String; // relative to curdir of process
  76. BaseDirectory: String; // relative path to package base directory
  77. PageInfos: TObjectList; // list of TPageInfo objects
  78. Doc: THTMLDocument;
  79. BodyElement, TitleElement: TDOMElement;
  80. Module: TPasModule;
  81. OutputNodeStack: TList;
  82. CurOutputNode: TDOMNode;
  83. InsideHeadRow, DoPasHighlighting: Boolean;
  84. HighlighterFlags: Byte;
  85. FooterFile: string;
  86. function ResolveLinkID(const Name: String): DOMString;
  87. function ResolveLinkWithinPackage(AElement: TPasElement;
  88. ASubpageIndex: Integer): String;
  89. // Helper functions for creating DOM elements
  90. function CreateEl(Parent: TDOMNode; const AName: DOMString): THTMLElement;
  91. function CreatePara(Parent: TDOMNode): THTMLElement;
  92. function CreateH1(Parent: TDOMNode): THTMLElement;
  93. function CreateH2(Parent: TDOMNode): THTMLElement;
  94. function CreateH3(Parent: TDOMNode): THTMLElement;
  95. function CreateTable(Parent: TDOMNode): THTMLElement;
  96. function CreateContentTable(Parent: TDOMNode): THTMLElement;
  97. function CreateTR(Parent: TDOMNode): THTMLElement;
  98. function CreateTD(Parent: TDOMNode): THTMLElement;
  99. function CreateTD_vtop(Parent: TDOMNode): THTMLElement;
  100. function CreateLink(Parent: TDOMNode; const AHRef: DOMString): THTMLElement;
  101. function CreateAnchor(Parent: TDOMNode; const AName: DOMString): THTMLElement;
  102. function CreateCode(Parent: TDOMNode): THTMLElement;
  103. function CreateWarning(Parent: TDOMNode): THTMLElement;
  104. // Description node conversion
  105. procedure PushOutputNode(ANode: TDOMNode);
  106. procedure PopOutputNode;
  107. procedure DescrWriteText(const AText: DOMString); override;
  108. procedure DescrBeginBold; override;
  109. procedure DescrEndBold; override;
  110. procedure DescrBeginItalic; override;
  111. procedure DescrEndItalic; override;
  112. procedure DescrBeginEmph; override;
  113. procedure DescrEndEmph; override;
  114. procedure DescrWriteFileEl(const AText: DOMString); override;
  115. procedure DescrWriteKeywordEl(const AText: DOMString); override;
  116. procedure DescrWriteVarEl(const AText: DOMString); override;
  117. procedure DescrBeginLink(const AId: DOMString); override;
  118. procedure DescrEndLink; override;
  119. procedure DescrWriteLinebreak; override;
  120. procedure DescrBeginParagraph; override;
  121. procedure DescrEndParagraph; override;
  122. procedure DescrBeginCode(HasBorder: Boolean; const AHighlighterName: String); override;
  123. procedure DescrWriteCodeLine(const ALine: String); override;
  124. procedure DescrEndCode; override;
  125. procedure DescrBeginOrderedList; override;
  126. procedure DescrEndOrderedList; override;
  127. procedure DescrBeginUnorderedList; override;
  128. procedure DescrEndUnorderedList; override;
  129. procedure DescrBeginDefinitionList; override;
  130. procedure DescrEndDefinitionList; override;
  131. procedure DescrBeginListItem; override;
  132. procedure DescrEndListItem; override;
  133. procedure DescrBeginDefinitionTerm; override;
  134. procedure DescrEndDefinitionTerm; override;
  135. procedure DescrBeginDefinitionEntry; override;
  136. procedure DescrEndDefinitionEntry; override;
  137. procedure DescrBeginSectionTitle; override;
  138. procedure DescrBeginSectionBody; override;
  139. procedure DescrEndSection; override;
  140. procedure DescrBeginRemark; override;
  141. procedure DescrEndRemark; override;
  142. procedure DescrBeginTable(ColCount: Integer; HasBorder: Boolean); override;
  143. procedure DescrEndTable; override;
  144. procedure DescrBeginTableCaption; override;
  145. procedure DescrEndTableCaption; override;
  146. procedure DescrBeginTableHeadRow; override;
  147. procedure DescrEndTableHeadRow; override;
  148. procedure DescrBeginTableRow; override;
  149. procedure DescrEndTableRow; override;
  150. procedure DescrBeginTableCell; override;
  151. procedure DescrEndTableCell; override;
  152. procedure AppendText(Parent: TDOMNode; const AText: DOMString);
  153. procedure AppendNbSp(Parent: TDOMNode; ACount: Integer);
  154. procedure AppendSym(Parent: TDOMNode; const AText: DOMString);
  155. procedure AppendKw(Parent: TDOMNode; const AText: DOMString);
  156. function AppendPasSHFragment(Parent: TDOMNode; const AText: String;
  157. AShFlags: Byte): Byte;
  158. Procedure AppendShortDescr(AContext : TPasElement;Parent: TDOMNode; DocNode : TDocNode);
  159. procedure AppendShortDescr(Parent: TDOMNode; Element: TPasElement);
  160. procedure AppendDescr(AContext: TPasElement; Parent: TDOMNode;
  161. DescrNode: TDOMElement; AutoInsertBlock: Boolean);
  162. procedure AppendDescrSection(AContext: TPasElement; Parent: TDOMNode;
  163. DescrNode: TDOMElement; const ATitle: DOMString);
  164. procedure AppendShortDescrCell(Parent: TDOMNode; Element: TPasElement);
  165. function AppendHyperlink(Parent: TDOMNode; Element: TPasElement): TDOMElement;
  166. function AppendType(CodeEl, TableEl: TDOMElement;
  167. Element: TPasType; Expanded: Boolean;
  168. NestingLevel: Integer = 0): TDOMElement;
  169. function AppendProcType(CodeEl, TableEl: TDOMElement;
  170. Element: TPasProcedureType; Indent: Integer): TDOMElement;
  171. procedure AppendProcExt(CodeEl: TDOMElement; Element: TPasProcedure);
  172. procedure AppendProcDecl(CodeEl, TableEl: TDOMElement;
  173. Element: TPasProcedureBase);
  174. procedure AppendProcArgsSection(Parent: TDOMNode;
  175. Element: TPasProcedureType);
  176. function AppendRecordType(CodeEl, TableEl: TDOMElement;
  177. Element: TPasRecordType; NestingLevel: Integer): TDOMElement;
  178. procedure AppendTitle(const AText: DOMString);
  179. procedure AppendMenuBar(ASubpageIndex: Integer);
  180. procedure AppendTopicMenuBar(Topic : TTopicElement);
  181. procedure AppendSourceRef(AElement: TPasElement);
  182. procedure FinishElementPage(AElement: TPasElement);
  183. Procedure AppendSeeAlsoSection(AElement : TPasElement;DocNode : TDocNode);
  184. Procedure AppendExampleSection(AElement : TPasElement;DocNode : TDocNode);
  185. procedure AppendFooter;
  186. procedure CreatePageBody(AElement: TPasElement; ASubpageIndex: Integer); virtual;
  187. procedure CreatePackagePageBody;
  188. Procedure CreateTopicPageBody(AElement : TTopicElement);
  189. procedure CreateModulePageBody(AModule: TPasModule; ASubpageIndex: Integer);
  190. procedure CreateConstPageBody(AConst: TPasConst);
  191. procedure CreateTypePageBody(AType: TPasType);
  192. procedure CreateClassPageBody(AClass: TPasClassType; ASubpageIndex: Integer);
  193. procedure CreateClassMemberPageBody(AElement: TPasElement);
  194. procedure CreateVarPageBody(AVar: TPasVariable);
  195. procedure CreateProcPageBody(AProc: TPasProcedureBase);
  196. Procedure CreateTopicLinks(Node : TDocNode; PasElement : TPasElement);
  197. public
  198. constructor Create(APackage: TPasPackage; AEngine: TFPDocEngine); override;
  199. destructor Destroy; override;
  200. // Single-page generation
  201. function CreateHTMLPage(AElement: TPasElement;
  202. ASubpageIndex: Integer): TXMLDocument;
  203. function CreateXHTMLPage(AElement: TPasElement;
  204. ASubpageIndex: Integer): TXMLDocument;
  205. // For producing complete package documentation
  206. procedure WriteHTMLPages; virtual;
  207. procedure WriteXHTMLPages;
  208. SearchPage: String;
  209. property Allocator: TFileAllocator read FAllocator;
  210. property Package: TPasPackage read FPackage;
  211. property PageCount: Integer read GetPageCount;
  212. property OnTest: TNotifyEvent read FOnTest write SetOnTest;
  213. Function InterPretOption(Const Cmd,Arg : String) : boolean; override;
  214. Procedure WriteDoc; override;
  215. class procedure Usage(List: TStrings); override;
  216. end;
  217. THTMWriter = class(THTMLWriter)
  218. Protected
  219. Procedure CreateAllocator; override;
  220. end;
  221. {$DEFINE chmInterface}
  222. {$I dw_htmlchm.inc}
  223. {$UNDEF chmInterface}
  224. implementation
  225. uses SysUtils, XHTML, XMLRead, XMLWrite, HTMWrite, sh_pas,chmsitemap;
  226. Function FixHTMLpath(S : String) : STring;
  227. begin
  228. Result:=StringReplace(S,'\','/',[rfReplaceAll]);
  229. end;
  230. {$I dw_htmlchm.inc}
  231. procedure TFileAllocator.AllocFilename(AElement: TPasElement;
  232. ASubindex: Integer);
  233. begin
  234. end;
  235. function TFileAllocator.GetRelativePathToTop(AElement: TPasElement): String;
  236. begin
  237. SetLength(Result, 0);
  238. end;
  239. function TFileAllocator.GetCSSFilename(ARelativeTo: TPasElement): DOMString;
  240. begin
  241. Result := GetRelativePathToTop(ARelativeTo) + 'fpdoc.css';
  242. end;
  243. constructor TShortNameFileAllocator.Create(const AExtension: String);
  244. begin
  245. inherited Create;
  246. FExtension := AExtension;
  247. end;
  248. procedure TShortNameFileAllocator.AllocFilename(AElement: TPasElement;
  249. ASubindex: Integer);
  250. begin
  251. // !!!: Add element to file list
  252. end;
  253. constructor TLongNameFileAllocator.Create(const AExtension: String);
  254. begin
  255. inherited Create;
  256. FExtension := AExtension;
  257. end;
  258. function TLongNameFileAllocator.GetFilename(AElement: TPasElement;
  259. ASubindex: Integer): String;
  260. var
  261. s: String;
  262. i: Integer;
  263. begin
  264. if AElement.ClassType = TPasPackage then
  265. Result := 'index'
  266. else if AElement.ClassType = TPasModule then
  267. Result := LowerCase(AElement.Name) + PathDelim + 'index'
  268. else
  269. begin
  270. if AElement is TPasOperator then
  271. begin
  272. Result := LowerCase(AElement.Parent.PathName) + '.op-';
  273. s := Copy(AElement.Name, Pos(' ', AElement.Name) + 1, Length(AElement.Name));
  274. s := Copy(s, 1, Pos('(', s) - 1);
  275. if s = ':=' then
  276. s := 'assign'
  277. else if s = '+' then
  278. s := 'add'
  279. else if s = '-' then
  280. s := 'sub'
  281. else if s = '*' then
  282. s := 'mul'
  283. else if s = '/' then
  284. s := 'div'
  285. else if s = '**' then
  286. s := 'power'
  287. else if s = '=' then
  288. s := 'equal'
  289. else if s = '<>' then
  290. s := 'unequal'
  291. else if s = '<' then
  292. s := 'less'
  293. else if s = '<=' then
  294. s := 'lessequal'
  295. else if s = '>' then
  296. s := 'greater'
  297. else if s = '>=' then
  298. s := 'greaterthan'
  299. else if s = '><' then
  300. s := 'symmetricdifference';
  301. Result := Result + s + '-';
  302. s := '';
  303. i := 1;
  304. while AElement.Name[i] <> '(' do
  305. Inc(i);
  306. Inc(i);
  307. while AElement.Name[i] <> ')' do
  308. begin
  309. if AElement.Name[i] = ',' then
  310. begin
  311. s := s + '-';
  312. Inc(i);
  313. end else
  314. s := s + AElement.Name[i];
  315. Inc(i);
  316. end;
  317. Result := Result + LowerCase(s) + '-' + LowerCase(Copy(AElement.Name,
  318. Pos('):', AElement.Name) + 3, Length(AElement.Name)));
  319. end else
  320. Result := LowerCase(AElement.PathName);
  321. i := 1;
  322. if (Length(Result) > 0) and (Result[1] = '#') then
  323. begin
  324. while Result[i] <> '.' do
  325. Inc(i);
  326. Result := Copy(Result, i + 1, Length(Result));
  327. end;
  328. i := 1;
  329. while (i <= Length(Result)) and (Result[i] <> '.') do
  330. Inc(i);
  331. if (i <= Length(Result)) and (i > 0) then
  332. Result[i] := PathDelim;
  333. end;
  334. if ASubindex > 0 then
  335. Result := Result + '-' + IntToStr(ASubindex);
  336. Result := Result + Extension;
  337. end;
  338. function TLongNameFileAllocator.GetRelativePathToTop(AElement: TPasElement): String;
  339. begin
  340. if (AElement.ClassType=TPasPackage) then
  341. Result := ''
  342. else if (AElement.ClassType=TTopicElement) then
  343. begin
  344. If (AElement.Parent.ClassType=TTopicElement) then
  345. Result:='../'+GetRelativePathToTop(AElement.Parent)
  346. else if (AElement.Parent.ClassType=TPasPackage) then
  347. Result:=''
  348. else if (AElement.Parent.ClassType=TPasModule) then
  349. Result:='../';
  350. end
  351. else
  352. Result := '../';
  353. end;
  354. constructor THTMLWriter.Create(APackage: TPasPackage; AEngine: TFPDocEngine);
  355. procedure AddPage(AElement: TPasElement; ASubpageIndex: Integer);
  356. var
  357. PageInfo: TPageInfo;
  358. begin
  359. PageInfo := TPageInfo.Create;
  360. PageInfo.Element := AElement;
  361. PageInfo.SubpageIndex := ASubpageIndex;
  362. PageInfos.Add(PageInfo);
  363. Allocator.AllocFilename(AElement, ASubpageIndex);
  364. if ASubpageIndex = 0 then
  365. Engine.AddLink(AElement.PathName,
  366. Allocator.GetFilename(AElement, ASubpageIndex));
  367. end;
  368. procedure AddTopicPages(AElement: TPasElement);
  369. var
  370. PreviousTopic,
  371. TopicElement : TTopicElement;
  372. PageInfo : TPageInfo;
  373. DocNode,
  374. TopicNode : TDocNode;
  375. begin
  376. DocNode:=Engine.FindDocNode(AElement);
  377. If not Assigned(DocNode) then
  378. exit;
  379. TopicNode:=DocNode.FirstChild;
  380. PreviousTopic:=Nil;
  381. While Assigned(TopicNode) do
  382. begin
  383. If TopicNode.TopicNode then
  384. begin
  385. TopicElement:=TTopicElement.Create(TopicNode.Name,AElement);
  386. Topics.Add(TopicElement);
  387. TopicElement.TopicNode:=TopicNode;
  388. TopicElement.Previous:=PreviousTopic;
  389. If Assigned(PreviousTopic) then
  390. PreviousTopic.Next:=TopicElement;
  391. PreviousTopic:=TopicElement;
  392. if AElement is TTopicElement then
  393. TTopicElement(AElement).SubTopics.Add(TopicElement);
  394. PageInfo := TPageInfo.Create;
  395. PageInfo.Element := TopicElement;
  396. PageInfo.SubpageIndex := 0;
  397. PageInfos.Add(PageInfo);
  398. Allocator.AllocFilename(TopicElement,0);
  399. Engine.AddLink(TopicElement.PathName, Allocator.GetFilename(TopicElement,0));
  400. if AElement is TTopicElement then
  401. TTopicElement(AElement).SubTopics.Add(TopicElement)
  402. else // Only one level of recursion.
  403. AddTopicPages(TopicElement);
  404. end;
  405. TopicNode:=TopicNode.NextSibling;
  406. end;
  407. end;
  408. procedure AddPages(AElement: TPasElement; ASubpageIndex: Integer;
  409. AList: TList);
  410. var
  411. i: Integer;
  412. begin
  413. if AList.Count > 0 then
  414. begin
  415. AddPage(AElement, ASubpageIndex);
  416. for i := 0 to AList.Count - 1 do
  417. AddPage(TPasElement(AList[i]), 0);
  418. end;
  419. end;
  420. procedure ScanModule(AModule: TPasModule);
  421. var
  422. i, j, k: Integer;
  423. s: String;
  424. ClassEl: TPasClassType;
  425. FPEl, AncestorMemberEl: TPasElement;
  426. DocNode: TDocNode;
  427. DidAutolink: Boolean;
  428. begin
  429. AddPage(AModule, 0);
  430. AddTopicPages(AModule);
  431. with AModule do
  432. begin
  433. if InterfaceSection.ResStrings.Count > 0 then
  434. begin
  435. AddPage(AModule, ResstrSubindex);
  436. s := Allocator.GetFilename(AModule, ResstrSubindex);
  437. for i := 0 to InterfaceSection.ResStrings.Count - 1 do
  438. with TPasResString(InterfaceSection.ResStrings[i]) do
  439. Engine.AddLink(PathName, s + '#' + LowerCase(Name));
  440. end;
  441. AddPages(AModule, ConstsSubindex, InterfaceSection.Consts);
  442. AddPages(AModule, TypesSubindex, InterfaceSection.Types);
  443. if InterfaceSection.Classes.Count > 0 then
  444. begin
  445. AddPage(AModule, ClassesSubindex);
  446. for i := 0 to InterfaceSection.Classes.Count - 1 do
  447. begin
  448. ClassEl := TPasClassType(InterfaceSection.Classes[i]);
  449. AddPage(ClassEl, 0);
  450. // !!!: Only add when there are items
  451. AddPage(ClassEl, PropertiesByInheritanceSubindex);
  452. AddPage(ClassEl, PropertiesByNameSubindex);
  453. AddPage(ClassEl, MethodsByInheritanceSubindex);
  454. AddPage(ClassEl, MethodsByNameSubindex);
  455. AddPage(ClassEl, EventsByInheritanceSubindex);
  456. AddPage(ClassEl, EventsByNameSubindex);
  457. for j := 0 to ClassEl.Members.Count - 1 do
  458. begin
  459. FPEl := TPasElement(ClassEl.Members[j]);
  460. if ((FPEl.Visibility = visPrivate) and Engine.HidePrivate) or
  461. ((FPEl.Visibility = visProtected) and Engine.HideProtected) then
  462. continue;
  463. DocNode := Engine.FindDocNode(FPEl);
  464. if not Assigned(DocNode) then
  465. begin
  466. DidAutolink := False;
  467. if Assigned(ClassEl.AncestorType) and
  468. (ClassEl.AncestorType.ClassType = TPasClassType) then
  469. begin
  470. for k := 0 to TPasClassType(ClassEl.AncestorType).Members.Count - 1 do
  471. begin
  472. AncestorMemberEl :=
  473. TPasElement(TPasClassType(ClassEl.AncestorType).Members[k]);
  474. if AncestorMemberEl.Name = FPEl.Name then
  475. begin
  476. DocNode := Engine.FindDocNode(AncestorMemberEl);
  477. if Assigned(DocNode) then
  478. begin
  479. DidAutolink := True;
  480. Engine.AddLink(FPEl.PathName,
  481. Engine.FindAbsoluteLink(AncestorMemberEl.PathName));
  482. break;
  483. end;
  484. end;
  485. end;
  486. end;
  487. if not DidAutolink then
  488. AddPage(FPEl, 0);
  489. end else
  490. AddPage(FPEl, 0);
  491. end;
  492. end;
  493. end;
  494. AddPages(AModule, ProcsSubindex, InterfaceSection.Functions);
  495. AddPages(AModule, VarsSubindex, InterfaceSection.Variables);
  496. end;
  497. end;
  498. var
  499. i: Integer;
  500. begin
  501. inherited ;
  502. CreateAllocator;
  503. FPackage := APackage;
  504. OutputNodeStack := TList.Create;
  505. PageInfos := TObjectList.Create;
  506. // Allocate page for the package itself, if a name is given (i.e. <> '#')
  507. if Length(Package.Name) > 1 then
  508. begin
  509. AddPage(Package, 0);
  510. AddTopicPages(Package);
  511. end;
  512. for i := 0 to Package.Modules.Count - 1 do
  513. ScanModule(TPasModule(Package.Modules[i]));
  514. end;
  515. destructor THTMLWriter.Destroy;
  516. begin
  517. PageInfos.Free;
  518. OutputNodeStack.Free;
  519. inherited Destroy;
  520. end;
  521. function THTMLWriter.CreateHTMLPage(AElement: TPasElement;
  522. ASubpageIndex: Integer): TXMLDocument;
  523. var
  524. HTMLEl: THTMLHtmlElement;
  525. HeadEl: THTMLHeadElement;
  526. El: TDOMElement;
  527. begin
  528. Doc := THTMLDocument.Create;
  529. Result := Doc;
  530. Doc.AppendChild(Doc.CreateProcessingInstruction(
  531. 'DOCTYPE', 'HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"'));
  532. HTMLEl := Doc.CreateHtmlElement;
  533. Doc.AppendChild(HTMLEl);
  534. HeadEl := Doc.CreateHeadElement;
  535. HTMLEl.AppendChild(HeadEl);
  536. El := Doc.CreateElement('meta');
  537. HeadEl.AppendChild(El);
  538. El['http-equiv'] := 'Content-Type';
  539. El['content'] := 'text/html; charset=iso-8859-1';
  540. TitleElement := Doc.CreateElement('title');
  541. HeadEl.AppendChild(TitleElement);
  542. El := Doc.CreateElement('link');
  543. BodyElement := Doc.CreateElement('body');
  544. HTMLEl.AppendChild(BodyElement);
  545. CreatePageBody(AElement, ASubpageIndex);
  546. AppendFooter;
  547. HeadEl.AppendChild(El);
  548. El['rel'] := 'stylesheet';
  549. El['type'] := 'text/css';
  550. El['href'] := FixHtmlPath(Allocator.GetCSSFilename(AElement));
  551. end;
  552. function THTMLWriter.CreateXHTMLPage(AElement: TPasElement;
  553. ASubpageIndex: Integer): TXMLDocument;
  554. begin
  555. Result := nil;
  556. end;
  557. procedure CreatePath(const AFilename: String);
  558. var
  559. EndIndex: Integer;
  560. Path: String;
  561. begin
  562. EndIndex := Length(AFilename);
  563. if EndIndex = 0 then
  564. exit;
  565. while not (AFilename[EndIndex] in AllowDirectorySeparators) do
  566. begin
  567. Dec(EndIndex);
  568. if EndIndex = 0 then
  569. exit;
  570. end;
  571. Path := Copy(AFilename, 1, EndIndex - 1);
  572. if not DirectoryExists(Path) then
  573. begin
  574. CreatePath(Path);
  575. MkDir(Path);
  576. end;
  577. end;
  578. procedure THTMLWriter.WriteHTMLPages;
  579. var
  580. i: Integer;
  581. PageDoc: TXMLDocument;
  582. Filename: String;
  583. begin
  584. if Engine.Output <> '' then
  585. Engine.Output := IncludeTrailingBackSlash(Engine.Output);
  586. for i := 0 to PageInfos.Count - 1 do
  587. with TPageInfo(PageInfos[i]) do
  588. begin
  589. PageDoc := CreateHTMLPage(Element, SubpageIndex);
  590. try
  591. Filename := Engine.Output + Allocator.GetFilename(Element, SubpageIndex);
  592. try
  593. CreatePath(Filename);
  594. WriteHTMLFile(PageDoc, Filename);
  595. except
  596. on E: Exception do
  597. WriteLn(Format(SErrCouldNotCreateFile, [FileName, e.Message]));
  598. end;
  599. finally
  600. PageDoc.Free;
  601. end;
  602. end;
  603. end;
  604. procedure THTMLWriter.WriteXHTMLPages;
  605. begin
  606. end;
  607. {procedure THTMLWriter.CreateDoc(const ATitle: DOMString;
  608. AElement: TPasElement; const AFilename: String);
  609. var
  610. El: TDOMElement;
  611. DocInfo: TDocInfo;
  612. CSSName: String;
  613. begin
  614. Doc := TXHTMLDocument.Create;
  615. with TXHTMLDocument(Doc) do
  616. begin
  617. Encoding := 'ISO8859-1';
  618. CSSName := 'fpdoc.css';
  619. if Assigned(Module) then
  620. CSSName := '../' + CSSName;
  621. $IFNDEF ver1_0
  622. StylesheetType := 'text/css';
  623. StylesheetHRef := CSSName;
  624. $ENDIF
  625. CreateRoot(xhtmlStrict);
  626. with RequestHeadElement do
  627. begin
  628. AppendText(RequestTitleElement, ATitle);
  629. El := CreateElement('link');
  630. AppendChild(El);
  631. El['rel'] := 'stylesheet';
  632. El['type'] := 'text/css';
  633. El['href'] := FixHtmlPath(CSSName);
  634. end;
  635. Self.BodyElement := RequestBodyElement('en');
  636. end;
  637. if Length(AFilename) > 0 then
  638. begin
  639. DocInfo := TDocInfo.Create;
  640. DocInfos.Add(DocInfo);
  641. DocInfo.Element := AElement;
  642. DocInfo.Filename := AFilename;
  643. end;
  644. end;
  645. }
  646. { Used for:
  647. - <link> elements in descriptions
  648. - "see also" entries
  649. - AppendHyperlink (for unresolved parse tree element links)
  650. }
  651. function THTMLWriter.ResolveLinkID(const Name: String): DOMString;
  652. var
  653. i: Integer;
  654. ThisPackage: TLinkNode;
  655. begin
  656. if Length(Name) = 0 then
  657. begin
  658. SetLength(Result, 0);
  659. exit;
  660. end;
  661. if Name[1] = '#' then
  662. Result := Engine.FindAbsoluteLink(Name)
  663. else
  664. begin
  665. SetLength(Result, 0);
  666. { Try all packages }
  667. ThisPackage := Engine.RootLinkNode.FirstChild;
  668. while Assigned(ThisPackage) do
  669. begin
  670. Result := Engine.FindAbsoluteLink(ThisPackage.Name + '.' + Name);
  671. if Length(Result) = 0 then
  672. begin
  673. if Assigned(Module) then
  674. Result := Engine.FindAbsoluteLink(Module.PathName + '.' + Name);
  675. // WriteLn('Searching for ', Module.PathName + '.' + Name, ' => ', Result);
  676. if Length(Result) = 0 then
  677. for i := Length(Name) downto 1 do
  678. if Name[i] = '.' then
  679. begin
  680. Result := ResolveLinkID(Copy(Name, 1, i - 1));
  681. exit;
  682. end;
  683. end;
  684. ThisPackage := ThisPackage.NextSibling;
  685. end;
  686. end;
  687. if Length(Result) > 0 then
  688. if Copy(Result, 1, Length(CurDirectory) + 1) = CurDirectory + '/' then
  689. Result := Copy(Result, Length(CurDirectory) + 2, Length(Result))
  690. else if not IsLinkAbsolute(Result) then
  691. Result := BaseDirectory + Result;
  692. end;
  693. function THTMLWriter.ResolveLinkWithinPackage(AElement: TPasElement;
  694. ASubpageIndex: Integer): String;
  695. var
  696. ParentEl: TPasElement;
  697. begin
  698. ParentEl := AElement;
  699. while Assigned(ParentEl) and not (ParentEl.ClassType = TPasPackage) do
  700. ParentEl := ParentEl.Parent;
  701. if Assigned(ParentEl) and (TPasPackage(ParentEl) = Engine.Package) then
  702. begin
  703. Result := Allocator.GetFilename(AElement, ASubpageIndex);
  704. if Copy(Result, 1, Length(CurDirectory) + 1) = CurDirectory + '/' then
  705. Result := Copy(Result, Length(CurDirectory) + 2, Length(Result))
  706. else
  707. Result := BaseDirectory + Result;
  708. end else
  709. SetLength(Result, 0);
  710. end;
  711. function THTMLWriter.CreateEl(Parent: TDOMNode;
  712. const AName: DOMString): THTMLElement;
  713. begin
  714. Result := Doc.CreateElement(AName);
  715. Parent.AppendChild(Result);
  716. end;
  717. function THTMLWriter.CreatePara(Parent: TDOMNode): THTMLElement;
  718. begin
  719. Result := CreateEl(Parent, 'p');
  720. end;
  721. function THTMLWriter.CreateH1(Parent: TDOMNode): THTMLElement;
  722. begin
  723. Result := CreateEl(Parent, 'h1');
  724. end;
  725. function THTMLWriter.CreateH2(Parent: TDOMNode): THTMLElement;
  726. begin
  727. Result := CreateEl(Parent, 'h2');
  728. end;
  729. function THTMLWriter.CreateH3(Parent: TDOMNode): THTMLElement;
  730. begin
  731. Result := CreateEl(Parent, 'h3');
  732. end;
  733. function THTMLWriter.CreateTable(Parent: TDOMNode): THTMLElement;
  734. begin
  735. Result := CreateEl(Parent, 'table');
  736. Result['cellspacing'] := '0';
  737. Result['cellpadding'] := '0';
  738. end;
  739. function THTMLWriter.CreateContentTable(Parent: TDOMNode): THTMLElement;
  740. begin
  741. Result := CreateEl(Parent, 'table');
  742. end;
  743. function THTMLWriter.CreateTR(Parent: TDOMNode): THTMLElement;
  744. begin
  745. Result := CreateEl(Parent, 'tr');
  746. end;
  747. function THTMLWriter.CreateTD(Parent: TDOMNode): THTMLElement;
  748. begin
  749. Result := CreateEl(Parent, 'td');
  750. end;
  751. function THTMLWriter.CreateTD_vtop(Parent: TDOMNode): THTMLElement;
  752. begin
  753. Result := CreateEl(Parent, 'td');
  754. Result['valign'] := 'top';
  755. end;
  756. function THTMLWriter.CreateLink(Parent: TDOMNode;
  757. const AHRef: DOMString): THTMLElement;
  758. begin
  759. Result := CreateEl(Parent, 'a');
  760. Result['href'] := FixHtmlPath(AHRef);
  761. end;
  762. function THTMLWriter.CreateAnchor(Parent: TDOMNode;
  763. const AName: DOMString): THTMLElement;
  764. begin
  765. Result := CreateEl(Parent, 'a');
  766. Result['name'] := AName;
  767. end;
  768. function THTMLWriter.CreateCode(Parent: TDOMNode): THTMLElement;
  769. begin
  770. Result := CreateEl(CreateEl(Parent, 'tt'), 'span');
  771. Result['class'] := 'code';
  772. end;
  773. function THTMLWriter.CreateWarning(Parent: TDOMNode): THTMLElement;
  774. begin
  775. Result := CreateEl(Parent, 'span');
  776. Result['class'] := 'warning';
  777. end;
  778. procedure THTMLWriter.PushOutputNode(ANode: TDOMNode);
  779. begin
  780. OutputNodeStack.Add(CurOutputNode);
  781. CurOutputNode := ANode;
  782. end;
  783. procedure THTMLWriter.PopOutputNode;
  784. begin
  785. CurOutputNode := TDOMNode(OutputNodeStack[OutputNodeStack.Count - 1]);
  786. OutputNodeStack.Delete(OutputNodeStack.Count - 1);
  787. end;
  788. procedure THTMLWriter.DescrWriteText(const AText: DOMString);
  789. begin
  790. AppendText(CurOutputNode, AText);
  791. end;
  792. procedure THTMLWriter.DescrBeginBold;
  793. begin
  794. PushOutputNode(CreateEl(CurOutputNode, 'b'));
  795. end;
  796. procedure THTMLWriter.DescrEndBold;
  797. begin
  798. PopOutputNode;
  799. end;
  800. procedure THTMLWriter.DescrBeginItalic;
  801. begin
  802. PushOutputNode(CreateEl(CurOutputNode, 'i'));
  803. end;
  804. procedure THTMLWriter.DescrEndItalic;
  805. begin
  806. PopOutputNode;
  807. end;
  808. procedure THTMLWriter.DescrBeginEmph;
  809. begin
  810. PushOutputNode(CreateEl(CurOutputNode, 'em'));
  811. end;
  812. procedure THTMLWriter.DescrEndEmph;
  813. begin
  814. PopOutputNode;
  815. end;
  816. procedure THTMLWriter.DescrWriteFileEl(const AText: DOMString);
  817. var
  818. NewEl: TDOMElement;
  819. begin
  820. NewEl := CreateEl(CurOutputNode, 'span');
  821. NewEl['class'] := 'file';
  822. AppendText(NewEl, AText);
  823. end;
  824. procedure THTMLWriter.DescrWriteKeywordEl(const AText: DOMString);
  825. var
  826. NewEl: TDOMElement;
  827. begin
  828. NewEl := CreateEl(CurOutputNode, 'span');
  829. NewEl['class'] := 'kw';
  830. AppendText(NewEl, AText);
  831. end;
  832. procedure THTMLWriter.DescrWriteVarEl(const AText: DOMString);
  833. begin
  834. AppendText(CreateEl(CurOutputNode, 'var'), AText);
  835. end;
  836. procedure THTMLWriter.DescrBeginLink(const AId: DOMString);
  837. var
  838. a,s: String;
  839. begin
  840. a:=AId;
  841. s := ResolveLinkID(a);
  842. if Length(s) = 0 then
  843. begin
  844. WriteLn(Format(SErrUnknownLinkID, [a]));
  845. PushOutputNode(CreateEl(CurOutputNode, 'b'));
  846. end else
  847. PushOutputNode(CreateLink(CurOutputNode, s));
  848. end;
  849. procedure THTMLWriter.DescrEndLink;
  850. begin
  851. PopOutputNode;
  852. end;
  853. procedure THTMLWriter.DescrWriteLinebreak;
  854. begin
  855. CreateEl(CurOutputNode, 'br');
  856. end;
  857. procedure THTMLWriter.DescrBeginParagraph;
  858. begin
  859. PushOutputNode(CreatePara(CurOutputNode));
  860. end;
  861. procedure THTMLWriter.DescrEndParagraph;
  862. begin
  863. PopOutputNode;
  864. end;
  865. procedure THTMLWriter.DescrBeginCode(HasBorder: Boolean; const AHighlighterName: String);
  866. begin
  867. DoPasHighlighting := (AHighlighterName = '') or (AHighlighterName = 'Pascal');
  868. HighlighterFlags := 0;
  869. PushOutputNode(CreateEl(CurOutputNode, 'pre'));
  870. end;
  871. procedure THTMLWriter.DescrWriteCodeLine(const ALine: String);
  872. begin
  873. if DoPasHighlighting then
  874. begin
  875. HighlighterFlags := AppendPasSHFragment(CurOutputNode, ALine,
  876. HighlighterFlags);
  877. AppendText(CurOutputNode, #10);
  878. end else
  879. AppendText(CurOutputNode, ALine + #10);
  880. end;
  881. procedure THTMLWriter.DescrEndCode;
  882. begin
  883. PopOutputNode;
  884. end;
  885. procedure THTMLWriter.DescrBeginOrderedList;
  886. begin
  887. PushOutputNode(CreateEl(CurOutputNode, 'ol'));
  888. end;
  889. procedure THTMLWriter.DescrEndOrderedList;
  890. begin
  891. PopOutputNode;
  892. end;
  893. procedure THTMLWriter.DescrBeginUnorderedList;
  894. begin
  895. PushOutputNode(CreateEl(CurOutputNode, 'ul'));
  896. end;
  897. procedure THTMLWriter.DescrEndUnorderedList;
  898. begin
  899. PopOutputNode;
  900. end;
  901. procedure THTMLWriter.DescrBeginDefinitionList;
  902. begin
  903. PushOutputNode(CreateEl(CurOutputNode, 'dl'));
  904. end;
  905. procedure THTMLWriter.DescrEndDefinitionList;
  906. begin
  907. PopOutputNode;
  908. end;
  909. procedure THTMLWriter.DescrBeginListItem;
  910. begin
  911. PushOutputNode(CreateEl(CurOutputNode, 'li'));
  912. end;
  913. procedure THTMLWriter.DescrEndListItem;
  914. begin
  915. PopOutputNode;
  916. end;
  917. procedure THTMLWriter.DescrBeginDefinitionTerm;
  918. begin
  919. PushOutputNode(CreateEl(CurOutputNode, 'dt'));
  920. end;
  921. procedure THTMLWriter.DescrEndDefinitionTerm;
  922. begin
  923. PopOutputNode;
  924. end;
  925. procedure THTMLWriter.DescrBeginDefinitionEntry;
  926. begin
  927. PushOutputNode(CreateEl(CurOutputNode, 'dd'));
  928. end;
  929. procedure THTMLWriter.DescrEndDefinitionEntry;
  930. begin
  931. PopOutputNode;
  932. end;
  933. procedure THTMLWriter.DescrBeginSectionTitle;
  934. begin
  935. PushOutputNode(CreateEl(CurOutputNode, 'h3'));
  936. end;
  937. procedure THTMLWriter.DescrBeginSectionBody;
  938. begin
  939. PopOutputNode;
  940. end;
  941. procedure THTMLWriter.DescrEndSection;
  942. begin
  943. end;
  944. procedure THTMLWriter.DescrBeginRemark;
  945. var
  946. NewEl, TDEl: TDOMElement;
  947. begin
  948. NewEl := CreateEl(CurOutputNode, 'table');
  949. NewEl['width'] := '100%';
  950. NewEl['border'] := '0';
  951. NewEl['CellSpacing'] := '0';
  952. NewEl['class'] := 'remark';
  953. NewEl := CreateTR(NewEl);
  954. TDEl := CreateTD(NewEl);
  955. TDEl['valign'] := 'top';
  956. TDEl['class'] := 'pre';
  957. AppendText(CreateEl(TDEl, 'b'), SDocRemark);
  958. PushOutputNode(CreateTD(NewEl));
  959. end;
  960. procedure THTMLWriter.DescrEndRemark;
  961. begin
  962. PopOutputNode;
  963. end;
  964. procedure THTMLWriter.DescrBeginTable(ColCount: Integer; HasBorder: Boolean);
  965. var
  966. Table: TDOMElement;
  967. begin
  968. Table := CreateEl(CurOutputNode, 'table');
  969. Table['border'] := IntToStr(Ord(HasBorder));
  970. PushOutputNode(Table);
  971. end;
  972. procedure THTMLWriter.DescrEndTable;
  973. begin
  974. PopOutputNode;
  975. end;
  976. procedure THTMLWriter.DescrBeginTableCaption;
  977. begin
  978. PushOutputNode(CreateEl(CurOutputNode, 'caption'));
  979. end;
  980. procedure THTMLWriter.DescrEndTableCaption;
  981. begin
  982. PopOutputNode;
  983. end;
  984. procedure THTMLWriter.DescrBeginTableHeadRow;
  985. begin
  986. PushOutputNode(CreateTr(CurOutputNode));
  987. InsideHeadRow := True;
  988. end;
  989. procedure THTMLWriter.DescrEndTableHeadRow;
  990. begin
  991. InsideHeadRow := False;
  992. PopOutputNode;
  993. end;
  994. procedure THTMLWriter.DescrBeginTableRow;
  995. begin
  996. PushOutputNode(CreateTR(CurOutputNode));
  997. end;
  998. procedure THTMLWriter.DescrEndTableRow;
  999. begin
  1000. PopOutputNode;
  1001. end;
  1002. procedure THTMLWriter.DescrBeginTableCell;
  1003. begin
  1004. if InsideHeadRow then
  1005. PushOutputNode(CreateEl(CurOutputNode, 'th'))
  1006. else
  1007. PushOutputNode(CreateTD(CurOutputNode));
  1008. end;
  1009. procedure THTMLWriter.DescrEndTableCell;
  1010. begin
  1011. PopOutputNode;
  1012. end;
  1013. procedure THTMLWriter.AppendText(Parent: TDOMNode; const AText: DOMString);
  1014. begin
  1015. Parent.AppendChild(Doc.CreateTextNode(AText));
  1016. end;
  1017. procedure THTMLWriter.AppendNbSp(Parent: TDOMNode; ACount: Integer);
  1018. begin
  1019. while ACount > 0 do
  1020. begin
  1021. Parent.AppendChild(Doc.CreateEntityReference('nbsp'));
  1022. Dec(ACount);
  1023. end;
  1024. end;
  1025. procedure THTMLWriter.AppendSym(Parent: TDOMNode; const AText: DOMString);
  1026. var
  1027. El: TDOMElement;
  1028. begin
  1029. El := CreateEl(Parent, 'span');
  1030. El['class'] := 'sym';
  1031. AppendText(El, AText);
  1032. end;
  1033. procedure THTMLWriter.AppendKw(Parent: TDOMNode; const AText: DOMString);
  1034. var
  1035. El: TDOMElement;
  1036. begin
  1037. El := CreateEl(Parent, 'span');
  1038. El['class'] := 'kw';
  1039. AppendText(El, AText);
  1040. end;
  1041. function THTMLWriter.AppendPasSHFragment(Parent: TDOMNode;
  1042. const AText: String; AShFlags: Byte): Byte;
  1043. var
  1044. Line, Last, p: PChar;
  1045. IsInSpecial: Boolean;
  1046. lastwasasm : boolean;
  1047. El: TDOMElement;
  1048. Procedure MaybeOutput;
  1049. Var
  1050. CurParent: TDomNode;
  1051. begin
  1052. If (Last<>Nil) then
  1053. begin
  1054. If (el<>Nil) then
  1055. CurParent:=El
  1056. else
  1057. CurParent:=Parent;
  1058. AppendText(CurParent,Last);
  1059. El:=Nil;
  1060. Last:=Nil;
  1061. end;
  1062. end;
  1063. Function NewEl(Const ElType,Attr,AttrVal : String) : TDomElement;
  1064. begin
  1065. Result:=CreateEl(Parent,ElType);
  1066. Result[Attr]:=AttrVal;
  1067. end;
  1068. Function NewSpan(Const AttrVal : String) : TDomElement;
  1069. begin
  1070. Result:=CreateEl(Parent,'span');
  1071. Result['class']:=AttrVal;
  1072. end;
  1073. begin
  1074. GetMem(Line, Length(AText) * 3 + 4);
  1075. Try
  1076. DoPascalHighlighting(AShFlags, PChar(AText), Line);
  1077. Result := AShFlags;
  1078. IsInSpecial := False;
  1079. Last := Nil;
  1080. p := Line;
  1081. el:=nil;
  1082. while p[0] <> #0 do
  1083. begin
  1084. if p[0] = LF_ESCAPE then
  1085. begin
  1086. p[0] := #0;
  1087. MaybeOutput;
  1088. case Ord(p[1]) of
  1089. shDefault: El:=Nil;
  1090. shInvalid: El:=newel('font','color','red');
  1091. shSymbol : El:=newspan('sym');
  1092. shKeyword: El:=newspan('kw');
  1093. shComment: El:=newspan('cmt');
  1094. shDirective: El:=newspan('dir');
  1095. shNumbers: El:=newspan('num');
  1096. shCharacters: El:=newspan('chr');
  1097. shStrings: El:=newspan('str');
  1098. shAssembler: El:=newspan('asm');
  1099. end;
  1100. Inc(P);
  1101. end
  1102. else If (Last=Nil) then
  1103. Last:=P;
  1104. Inc(p);
  1105. end;
  1106. MaybeOutput;
  1107. Finally
  1108. FreeMem(Line);
  1109. end;
  1110. end;
  1111. Procedure THTMLWriter.AppendShortDescr(AContext: TPasElement; Parent: TDOMNode; DocNode : TDocNode);
  1112. begin
  1113. if Assigned(DocNode) and Assigned(DocNode.ShortDescr) then
  1114. begin
  1115. PushOutputNode(Parent);
  1116. try
  1117. if not ConvertShort(AContext,TDomElement(DocNode.ShortDescr)) then
  1118. Warning(AContext, SErrInvalidShortDescr)
  1119. finally
  1120. PopOutputNode;
  1121. end;
  1122. end;
  1123. end;
  1124. procedure THTMLWriter.AppendShortDescr(Parent: TDOMNode; Element: TPasElement);
  1125. begin
  1126. AppendShortDescr(Element,Parent,Engine.FindDocNode(Element));
  1127. end;
  1128. procedure THTMLWriter.AppendDescr(AContext: TPasElement; Parent: TDOMNode;
  1129. DescrNode: TDOMElement; AutoInsertBlock: Boolean);
  1130. begin
  1131. if Assigned(DescrNode) then
  1132. begin
  1133. PushOutputNode(Parent);
  1134. try
  1135. ConvertDescr(AContext, DescrNode, AutoInsertBlock);
  1136. finally
  1137. PopOutputNode;
  1138. end;
  1139. end;
  1140. end;
  1141. procedure THTMLWriter.AppendDescrSection(AContext: TPasElement;
  1142. Parent: TDOMNode; DescrNode: TDOMElement; const ATitle: DOMString);
  1143. begin
  1144. if not IsDescrNodeEmpty(DescrNode) then
  1145. begin
  1146. If (ATitle<>'') then // Can be empty for topic.
  1147. AppendText(CreateH2(Parent), ATitle);
  1148. AppendDescr(AContext, Parent, DescrNode, True);
  1149. end;
  1150. end;
  1151. procedure THTMLWriter.AppendShortDescrCell(Parent: TDOMNode;
  1152. Element: TPasElement);
  1153. var
  1154. ParaEl: TDOMElement;
  1155. begin
  1156. if Assigned(Engine.FindShortDescr(Element)) then
  1157. begin
  1158. AppendNbSp(CreatePara(CreateTD(Parent)), 2);
  1159. ParaEl := CreatePara(CreateTD(Parent));
  1160. ParaEl['class'] := 'cmt';
  1161. AppendShortDescr(ParaEl, Element);
  1162. end;
  1163. end;
  1164. function THTMLWriter.AppendHyperlink(Parent: TDOMNode;
  1165. Element: TPasElement): TDOMElement;
  1166. var
  1167. s: String;
  1168. UnitList: TList;
  1169. i: Integer;
  1170. ThisPackage: TLinkNode;
  1171. begin
  1172. if Assigned(Element) then
  1173. begin
  1174. if Element.InheritsFrom(TPasUnresolvedTypeRef) then
  1175. begin
  1176. s := ResolveLinkID(Element.Name);
  1177. if Length(s) = 0 then
  1178. begin
  1179. { Try all packages }
  1180. ThisPackage := Engine.RootLinkNode.FirstChild;
  1181. while Assigned(ThisPackage) do
  1182. begin
  1183. s := ResolveLinkID(ThisPackage.Name + '.' + Element.Name);
  1184. if Length(s) > 0 then
  1185. break;
  1186. ThisPackage := ThisPackage.NextSibling;
  1187. end;
  1188. if Length(s) = 0 then
  1189. begin
  1190. { Okay, then we have to try all imported units of the current module }
  1191. UnitList := Module.InterfaceSection.UsesList;
  1192. for i := UnitList.Count - 1 downto 0 do
  1193. begin
  1194. { Try all packages }
  1195. ThisPackage := Engine.RootLinkNode.FirstChild;
  1196. while Assigned(ThisPackage) do
  1197. begin
  1198. s := ResolveLinkID(ThisPackage.Name + '.' +
  1199. TPasType(UnitList[i]).Name + '.' + Element.Name);
  1200. if Length(s) > 0 then
  1201. break;
  1202. ThisPackage := ThisPackage.NextSibling;
  1203. end;
  1204. if Length(s) > 0 then
  1205. break;
  1206. end;
  1207. end;
  1208. end;
  1209. end else
  1210. s := ResolveLinkID(Element.PathName);
  1211. if Length(s) > 0 then
  1212. begin
  1213. Result := CreateLink(Parent, s);
  1214. AppendText(Result, Element.Name);
  1215. end else
  1216. begin
  1217. Result := nil;
  1218. AppendText(Parent, Element.Name);
  1219. end;
  1220. end else
  1221. begin
  1222. Result := nil;
  1223. AppendText(CreateWarning(Parent), '<NIL>');
  1224. end;
  1225. end;
  1226. { Returns the new CodeEl, which will be the old CodeEl in most cases }
  1227. function THTMLWriter.AppendType(CodeEl, TableEl: TDOMElement;
  1228. Element: TPasType; Expanded: Boolean; NestingLevel: Integer): TDOMElement;
  1229. Var
  1230. S : String;
  1231. begin
  1232. Result := CodeEl;
  1233. if not Assigned(Element) then
  1234. AppendText(CreateWarning(CodeEl), '<NIL>')
  1235. else if (not Expanded) and (Length(Element.Name) > 0) then
  1236. AppendHyperlink(CodeEl, Element)
  1237. else
  1238. // Array
  1239. if Element.ClassType = TPasArrayType then
  1240. begin
  1241. S:='array ';
  1242. If (TPasArrayType(Element).IndexRange<>'') then
  1243. S:=S+'[' + TPasArrayType(Element).IndexRange + '] ';
  1244. S:=S+'of ';
  1245. If (TPasArrayType(Element).ElType=Nil) then
  1246. S:=S+'Const';
  1247. AppendPasSHFragment(CodeEl,S,0);
  1248. If (TPasArrayType(Element).ElType<>Nil) then
  1249. Result := AppendType(CodeEl, TableEl, TPasArrayType(Element).ElType, False);
  1250. end else
  1251. // Procedure or funtion type
  1252. if Element.InheritsFrom(TPasProcedureType) then
  1253. begin
  1254. AppendKw(CodeEl, TPasProcedureType(Element).TypeName);
  1255. Result := AppendProcType(CodeEl, TableEl, TPasProcedureType(Element), 0)
  1256. end else
  1257. // Range type
  1258. if Element.InheritsFrom(TPasRangeType) then
  1259. AppendPasSHFragment(CodeEl, TPasRangeType(Element).RangeStart + '..' +
  1260. TPasRangeType(Element).RangeEnd, 0)
  1261. // Record type
  1262. else if Element.ClassType = TPasRecordType then
  1263. Result := AppendRecordType(CodeEl, TableEl, TPasRecordType(Element), NestingLevel)
  1264. else if (Element.ClassType = TPasFileType) and (TPasFileType(Element).elType=Nil) then
  1265. AppendPasSHFragment(CodeEl,'file',0)
  1266. else
  1267. // Other types
  1268. AppendHyperlink(CodeEl, Element);
  1269. end;
  1270. function THTMLWriter.AppendProcType(CodeEl, TableEl: TDOMElement;
  1271. Element: TPasProcedureType; Indent: Integer): TDOMElement;
  1272. function CreateIndentedCodeEl(Indent: Integer): TDOMElement;
  1273. begin
  1274. Result := CreateCode(CreatePara(CreateTD(CreateTR(TableEl))));
  1275. AppendNbSp(Result, Indent);
  1276. end;
  1277. var
  1278. i: Integer;
  1279. Arg: TPasArgument;
  1280. begin
  1281. if Element.Args.Count > 0 then
  1282. begin
  1283. AppendSym(CodeEl, '(');
  1284. for i := 0 to Element.Args.Count - 1 do
  1285. begin
  1286. Arg := TPasArgument(Element.Args[i]);
  1287. CodeEl := CreateIndentedCodeEl(Indent + 2);
  1288. case Arg.Access of
  1289. argConst: AppendKw(CodeEl, 'const ');
  1290. argVar: AppendKw(CodeEl, 'var ');
  1291. argOut: AppendKw(CodeEl, 'out ');
  1292. end;
  1293. AppendText(CodeEl, Arg.Name);
  1294. if Assigned(Arg.ArgType) then
  1295. begin
  1296. AppendSym(CodeEl, ': ');
  1297. CodeEl := AppendType(CodeEl, TableEl, Arg.ArgType, False);
  1298. end;
  1299. if Length(Arg.Value) > 0 then
  1300. AppendPasSHFragment(CodeEl, ' = ' + Arg.Value, 0);
  1301. if i < Element.Args.Count - 1 then
  1302. AppendSym(CodeEl, ';');
  1303. end;
  1304. if Element.InheritsFrom(TPasFunctionType) or Element.IsOfObject then
  1305. begin
  1306. CodeEl := CreateIndentedCodeEl(Indent);
  1307. if Element.InheritsFrom(TPasFunctionType) then
  1308. begin
  1309. AppendSym(CodeEl, '):');
  1310. AppendHyperlink(CodeEl, TPasFunctionType(Element).ResultEl.ResultType);
  1311. end else
  1312. AppendSym(CodeEl, ')');
  1313. if Element.IsOfObject then
  1314. begin
  1315. AppendText(CodeEl, ' '); // Don't remove
  1316. AppendKw(CodeEl, 'of object');
  1317. end;
  1318. end else
  1319. if Indent > 0 then
  1320. AppendSym(CodeEl, ')')
  1321. else
  1322. begin
  1323. CodeEl := CreateCode(CreatePara(CreateTD(CreateTR(TableEl))));
  1324. AppendSym(CodeEl, ')');
  1325. end;
  1326. end else
  1327. begin
  1328. { Procedure or function without arguments }
  1329. if Element.InheritsFrom(TPasFunctionType) then
  1330. begin
  1331. AppendSym(CodeEl, ': ');
  1332. AppendHyperlink(CodeEl, TPasFunctionType(Element).ResultEl.ResultType);
  1333. end;
  1334. if Element.IsOfObject then
  1335. AppendKw(CodeEl, ' of object');
  1336. end;
  1337. Result := CodeEl;
  1338. end;
  1339. procedure THTMLWriter.AppendProcExt(CodeEl: TDOMElement;
  1340. Element: TPasProcedure);
  1341. procedure AppendExt(const Ext: String);
  1342. begin
  1343. AppendKw(CodeEl, ' ' + Ext);
  1344. AppendSym(CodeEl, ';');
  1345. end;
  1346. begin
  1347. if Element.IsVirtual then
  1348. AppendExt('virtual');
  1349. if Element.IsDynamic then
  1350. AppendExt('dynamic');
  1351. if Element.IsAbstract then
  1352. AppendExt('abstract');
  1353. if Element.IsOverride then
  1354. AppendExt('override');
  1355. if Element.IsOverload then
  1356. AppendExt('overload');
  1357. if Element.IsMessage then
  1358. AppendExt('message');
  1359. end;
  1360. { Used in two places:
  1361. - Page for the method of a class
  1362. - Page for a tandalone procedure or function. }
  1363. procedure THTMLWriter.AppendProcDecl(CodeEl, TableEl: TDOMElement;
  1364. Element: TPasProcedureBase);
  1365. procedure WriteVariant(AProc: TPasProcedure);
  1366. begin
  1367. AppendProcArgsSection(TableEl.ParentNode, AProc.ProcType);
  1368. AppendKw(CodeEl, AProc.TypeName);
  1369. if Element.Parent.ClassType = TPasClassType then
  1370. begin
  1371. AppendText(CodeEl, ' ');
  1372. AppendHyperlink(CodeEl, Element.Parent);
  1373. AppendSym(CodeEl, '.');
  1374. AppendText(CodeEl, AProc.Name);
  1375. end else
  1376. AppendText(CodeEl, ' ' + AProc.FullName);
  1377. CodeEl := AppendProcType(CodeEl, TableEl, AProc.ProcType, 0);
  1378. AppendSym(CodeEl, ';');
  1379. AppendProcExt(CodeEl, AProc);
  1380. end;
  1381. var
  1382. i: Integer;
  1383. begin
  1384. if Element.ClassType = TPasOverloadedProc then
  1385. for i := 0 to TPasOverloadedProc(Element).Overloads.Count - 1 do
  1386. begin
  1387. if i > 0 then
  1388. begin
  1389. CreateEl(CodeEl, 'br');
  1390. CreateEl(CodeEl, 'br');
  1391. end;
  1392. WriteVariant(TPasProcedure(TPasOverloadedProc(Element).Overloads[i]));
  1393. end
  1394. else
  1395. WriteVariant(TPasProcedure(Element));
  1396. end;
  1397. procedure THTMLWriter.AppendProcArgsSection(Parent: TDOMNode;
  1398. Element: TPasProcedureType);
  1399. var
  1400. HasFullDescr, IsFirst: Boolean;
  1401. ResultEl: TPasResultElement;
  1402. ArgTableEl, TREl: TDOMElement;
  1403. DocNode: TDocNode;
  1404. i: Integer;
  1405. Arg: TPasArgument;
  1406. begin
  1407. IsFirst := True;
  1408. for i := 0 to Element.Args.Count - 1 do
  1409. begin
  1410. Arg := TPasArgument(Element.Args[i]);
  1411. if IsDescrNodeEmpty(Engine.FindShortDescr(Arg)) then
  1412. continue;
  1413. if IsFirst then
  1414. begin
  1415. IsFirst := False;
  1416. AppendText(CreateH2(Parent), SDocArguments);
  1417. ArgTableEl := CreateTable(Parent);
  1418. end;
  1419. TREl := CreateTR(ArgTableEl);
  1420. AppendText(CreateCode(CreatePara(CreateTD_vtop(TREl))), Arg.Name);
  1421. AppendShortDescrCell(TREl, Arg);
  1422. end;
  1423. if Element.ClassType = TPasFunctionType then
  1424. begin
  1425. ResultEl := TPasFunctionType(Element).ResultEl;
  1426. DocNode := Engine.FindDocNode(ResultEl);
  1427. HasFullDescr := Assigned(DocNode) and not IsDescrNodeEmpty(DocNode.Descr);
  1428. if HasFullDescr or
  1429. (Assigned(DocNode) and not IsDescrNodeEmpty(DocNode.ShortDescr)) then
  1430. begin
  1431. AppendText(CreateH2(Parent), SDocFunctionResult);
  1432. if HasFullDescr then
  1433. AppendDescr(ResultEl, Parent, DocNode.Descr, True)
  1434. else
  1435. AppendDescr(ResultEl, CreatePara(Parent), DocNode.ShortDescr, False);
  1436. end;
  1437. end;
  1438. end;
  1439. function THTMLWriter.AppendRecordType(CodeEl, TableEl: TDOMElement;
  1440. Element: TPasRecordType; NestingLevel: Integer): TDOMElement;
  1441. var
  1442. i, j: Integer;
  1443. Variable: TPasVariable;
  1444. TREl, TDEl: TDOMElement;
  1445. CurVariant: TPasVariant;
  1446. begin
  1447. if not (Element.Parent is TPasVariant) then
  1448. if Element.IsPacked then
  1449. If Element.IsBitPacked then
  1450. AppendKw(CodeEl, 'bitpacked record')
  1451. else
  1452. AppendKW(CodeEl, 'packed record')
  1453. else
  1454. AppendKw(CodeEl, 'record');
  1455. for i := 0 to Element.Members.Count - 1 do
  1456. begin
  1457. Variable := TPasVariable(Element.Members[i]);
  1458. TREl := CreateTR(TableEl);
  1459. CodeEl := CreateCode(CreatePara(CreateTD_vtop(TREl)));
  1460. AppendShortDescrCell(TREl, Variable);
  1461. AppendNbSp(CodeEl, NestingLevel * 2 + 2);
  1462. AppendText(CodeEl, Variable.Name);
  1463. AppendSym(CodeEl, ': ');
  1464. CodeEl := AppendType(CodeEl, TableEl, Variable.VarType, False, NestingLevel + 1);
  1465. AppendSym(CodeEl, ';');
  1466. end;
  1467. if Assigned(Element.VariantType) then
  1468. begin
  1469. TREl := CreateTR(TableEl);
  1470. CodeEl := CreateCode(CreatePara(CreateTD_vtop(TREl)));
  1471. AppendNbSp(CodeEl, NestingLevel * 2 + 2);
  1472. AppendKw(CodeEl, 'case ');
  1473. if TPasRecordType(Element).VariantName <> '' then
  1474. begin
  1475. AppendText(CodeEl, TPasRecordType(Element).VariantName);
  1476. AppendSym(CodeEl, ': ');
  1477. end;
  1478. CodeEl := AppendType(CodeEl, TableEl, TPasRecordType(Element).VariantType, True);
  1479. AppendKw(CodeEl, ' of');
  1480. for i := 0 to TPasRecordType(Element).Variants.Count - 1 do
  1481. begin
  1482. CurVariant := TPasVariant(Element.Variants[i]);
  1483. TREl := CreateTR(TableEl);
  1484. CodeEl := CreateCode(CreatePara(CreateTD_vtop(TREl)));
  1485. AppendNbSp(CodeEl, NestingLevel * 2 + 4);
  1486. for j := 0 to CurVariant.Values.Count - 1 do
  1487. begin
  1488. if j > 0 then
  1489. AppendSym(CodeEl, ', ');
  1490. AppendPasSHFragment(CodeEl, CurVariant.Values[j], 0);
  1491. end;
  1492. AppendSym(CodeEl, ': (');
  1493. AppendType(CodeEl, TableEl, CurVariant.Members, True, NestingLevel + 3);
  1494. CodeEl := CreateCode(CreatePara(CreateTD_vtop(CreateTR(TableEl))));
  1495. AppendNbSp(CodeEl, NestingLevel * 2 + 6);
  1496. AppendSym(CodeEl, ');');
  1497. end;
  1498. end;
  1499. if not (Element.Parent is TPasVariant) then
  1500. begin
  1501. CodeEl := CreateCode(CreatePara(CreateTD(CreateTR(TableEl))));
  1502. AppendText(CodeEl, ' '); // !!!: Dirty trick, necessary for current XML writer
  1503. AppendNbSp(CodeEl, NestingLevel * 2);
  1504. AppendKw(CodeEl, 'end');
  1505. end;
  1506. Result := CodeEl;
  1507. end;
  1508. procedure THTMLWriter.AppendTitle(const AText: DOMString);
  1509. begin
  1510. AppendText(TitleElement, AText);
  1511. AppendText(CreateH1(BodyElement), AText);
  1512. end;
  1513. procedure THTMLWriter.AppendTopicMenuBar(Topic : TTopicElement);
  1514. var
  1515. TableEl, TREl, ParaEl, TitleEl: TDOMElement;
  1516. procedure AddLink(El : TPasElement; const AName: String);
  1517. begin
  1518. AppendText(ParaEl, '[');
  1519. AppendText(CreateLink(ParaEl, ResolveLinkWithinPackage(El,0)),AName);
  1520. AppendText(ParaEl, ']');
  1521. end;
  1522. begin
  1523. TableEl := CreateEl(BodyElement, 'table');
  1524. TableEl['cellpadding'] := '4';
  1525. TableEl['cellspacing'] := '0';
  1526. TableEl['border'] := '0';
  1527. TableEl['width'] := '100%';
  1528. TableEl['class'] := 'bar';
  1529. TREl := CreateTR(TableEl);
  1530. ParaEl := CreateEl(CreateTD(TREl), 'b');
  1531. If Assigned(Topic.Previous) then
  1532. AddLink(Topic.Previous,SDocPrevious);
  1533. If Assigned(Topic.Parent) then
  1534. AddLink(Topic.Parent,SDocUp);
  1535. if Assigned(Topic.Next) then
  1536. AddLink(Topic.Next,SDocNext);
  1537. if Length(SearchPage) > 0 then
  1538. begin
  1539. AppendText(ParaEl, '[');
  1540. AppendText(CreateLink(ParaEl, SearchPage), SDocSearch);
  1541. AppendText(ParaEl, ']');
  1542. end;
  1543. ParaEl := CreateTD(TREl);
  1544. ParaEl['align'] := 'right';
  1545. TitleEl := CreateEl(ParaEl, 'span');
  1546. TitleEl['class'] := 'bartitle';
  1547. if Assigned(Module) then
  1548. AppendText(TitleEl, Format(SDocUnitTitle, [Module.Name]));
  1549. if Assigned(Package) then
  1550. begin
  1551. AppendText(TitleEl, ' (');
  1552. AppendHyperlink(TitleEl, Package);
  1553. AppendText(TitleEl, ')');
  1554. end;
  1555. end;
  1556. procedure THTMLWriter.AppendMenuBar(ASubpageIndex: Integer);
  1557. var
  1558. TableEl, TREl, ParaEl, TitleEl: TDOMElement;
  1559. procedure AddLink(ALinkSubpageIndex: Integer; const AName: String);
  1560. begin
  1561. AppendText(ParaEl, '[');
  1562. if ALinkSubpageIndex = ASubpageIndex then
  1563. AppendText(ParaEl, AName)
  1564. else
  1565. AppendText(
  1566. CreateLink(ParaEl, ResolveLinkWithinPackage(Module, ALinkSubpageIndex)),
  1567. AName);
  1568. AppendText(ParaEl, ']');
  1569. end;
  1570. begin
  1571. TableEl := CreateEl(BodyElement, 'table');
  1572. TableEl['cellpadding'] := '4';
  1573. TableEl['cellspacing'] := '0';
  1574. TableEl['border'] := '0';
  1575. TableEl['width'] := '100%';
  1576. TableEl['class'] := 'bar';
  1577. TREl := CreateTR(TableEl);
  1578. ParaEl := CreateEl(CreateTD(TREl), 'b');
  1579. if Assigned(Module) then
  1580. begin
  1581. AddLink(0, SDocOverview);
  1582. if Module.InterfaceSection.ResStrings.Count > 0 then
  1583. AddLink(ResstrSubindex, SDocResStrings);
  1584. if Module.InterfaceSection.Consts.Count > 0 then
  1585. AddLink(ConstsSubindex, SDocConstants);
  1586. if Module.InterfaceSection.Types.Count > 0 then
  1587. AddLink(TypesSubindex, SDocTypes);
  1588. if Module.InterfaceSection.Classes.Count > 0 then
  1589. AddLink(ClassesSubindex, SDocClasses);
  1590. if Module.InterfaceSection.Functions.Count > 0 then
  1591. AddLink(ProcsSubindex, SDocProceduresAndFunctions);
  1592. if Module.InterfaceSection.Variables.Count > 0 then
  1593. AddLink(VarsSubindex, SDocVariables);
  1594. end;
  1595. if Length(SearchPage) > 0 then
  1596. begin
  1597. AppendText(ParaEl, '[');
  1598. AppendText(CreateLink(ParaEl, SearchPage), SDocSearch);
  1599. AppendText(ParaEl, ']');
  1600. end;
  1601. ParaEl := CreateTD(TREl);
  1602. ParaEl['align'] := 'right';
  1603. TitleEl := CreateEl(ParaEl, 'span');
  1604. TitleEl['class'] := 'bartitle';
  1605. if Assigned(Module) then
  1606. AppendText(TitleEl, Format(SDocUnitTitle, [Module.Name]));
  1607. if Assigned(Package) then
  1608. begin
  1609. AppendText(TitleEl, ' (');
  1610. AppendHyperlink(TitleEl, Package);
  1611. AppendText(TitleEl, ')');
  1612. end;
  1613. end;
  1614. procedure THTMLWriter.AppendSourceRef(AElement: TPasElement);
  1615. begin
  1616. AppendText(CreatePara(BodyElement), Format(SDocSourcePosition,
  1617. [ExtractFileName(AElement.SourceFilename), AElement.SourceLinenumber]));
  1618. end;
  1619. Procedure THTMLWriter.AppendSeeAlsoSection(AElement : TPasElement;DocNode : TDocNode);
  1620. var
  1621. Node: TDOMNode;
  1622. TableEl, El, TREl, TDEl, ParaEl, NewEl, DescrEl: TDOMElement;
  1623. l,s: String;
  1624. f: Text;
  1625. IsFirstSeeAlso : Boolean;
  1626. begin
  1627. if Not (Assigned(DocNode) and Assigned(DocNode.SeeAlso)) then
  1628. Exit;
  1629. IsFirstSeeAlso := True;
  1630. Node:=DocNode.SeeAlso.FirstChild;
  1631. While Assigned(Node) do
  1632. begin
  1633. if (Node.NodeType=ELEMENT_NODE) and (Node.NodeName='link') then
  1634. begin
  1635. if IsFirstSeeAlso then
  1636. begin
  1637. IsFirstSeeAlso := False;
  1638. AppendText(CreateH2(BodyElement), SDocSeeAlso);
  1639. TableEl := CreateTable(BodyElement);
  1640. end;
  1641. El:=TDOMElement(Node);
  1642. TREl:=CreateTR(TableEl);
  1643. ParaEl:=CreatePara(CreateTD_vtop(TREl));
  1644. l:=El['id'];
  1645. s:= ResolveLinkID(l);
  1646. if Length(s)=0 then
  1647. begin
  1648. WriteLn(Format(SErrUnknownLinkID, [l]));
  1649. NewEl := CreateEl(ParaEl,'b')
  1650. end
  1651. else
  1652. NewEl := CreateLink(ParaEl,s);
  1653. if Not IsDescrNodeEmpty(El) then
  1654. begin
  1655. PushOutputNode(NewEl);
  1656. Try
  1657. ConvertBaseShortList(AElement, El, True)
  1658. Finally
  1659. PopOutputNode;
  1660. end;
  1661. end
  1662. else
  1663. AppendText(NewEl,El['id']);
  1664. l:=El['id'];
  1665. DescrEl := Engine.FindShortDescr(AElement.GetModule,L);
  1666. if Assigned(DescrEl) then
  1667. begin
  1668. AppendNbSp(CreatePara(CreateTD(TREl)), 2);
  1669. ParaEl := CreatePara(CreateTD(TREl));
  1670. ParaEl['class'] := 'cmt';
  1671. PushOutputNode(ParaEl);
  1672. try
  1673. ConvertShort(AElement, DescrEl);
  1674. finally
  1675. PopOutputNode;
  1676. end;
  1677. end;
  1678. end; // Link node
  1679. Node := Node.NextSibling;
  1680. end; // While
  1681. end;
  1682. Procedure THTMLWriter.AppendExampleSection(AElement : TPasElement;DocNode : TDocNode);
  1683. var
  1684. Node: TDOMNode;
  1685. // TableEl, El, TREl, TDEl, ParaEl, NewEl, DescrEl: TDOMElement;
  1686. fn,s: String;
  1687. f: Text;
  1688. begin
  1689. if not (Assigned(DocNode) and Assigned(DocNode.FirstExample)) then
  1690. Exit;
  1691. Node := DocNode.FirstExample;
  1692. while Assigned(Node) do
  1693. begin
  1694. if (Node.NodeType = ELEMENT_NODE) and (Node.NodeName = 'example') then
  1695. begin
  1696. fn:=Engine.GetExampleFilename(TDOMElement(Node));
  1697. If (fn<>'') then
  1698. begin
  1699. AppendText(CreateH2(BodyElement), SDocExample);
  1700. try
  1701. Assign(f, FN);
  1702. Reset(f);
  1703. try
  1704. PushOutputNode(BodyElement);
  1705. DescrBeginCode(False, TDOMElement(Node)['highlighter']);
  1706. while not EOF(f) do
  1707. begin
  1708. ReadLn(f, s);
  1709. DescrWriteCodeLine(s);
  1710. end;
  1711. DescrEndCode;
  1712. PopOutputNode;
  1713. finally
  1714. Close(f);
  1715. end;
  1716. except
  1717. on e: Exception do
  1718. begin
  1719. e.Message := '[example] ' + e.Message;
  1720. raise;
  1721. end;
  1722. end;
  1723. end;
  1724. end;
  1725. Node := Node.NextSibling;
  1726. end;
  1727. end;
  1728. procedure THTMLWriter.AppendFooter;
  1729. begin
  1730. if FooterFile<>'' then
  1731. ReadXMLFragment(BodyElement, FooterFile);
  1732. end;
  1733. procedure THTMLWriter.FinishElementPage(AElement: TPasElement);
  1734. var
  1735. DocNode: TDocNode;
  1736. begin
  1737. DocNode := Engine.FindDocNode(AElement);
  1738. If Assigned(DocNode) then
  1739. begin
  1740. // Description
  1741. if Assigned(DocNode.Descr) then
  1742. AppendDescrSection(AElement, BodyElement, DocNode.Descr, SDocDescription);
  1743. // Append "Errors" section
  1744. if Assigned(DocNode.ErrorsDoc) then
  1745. AppendDescrSection(AElement, BodyElement, DocNode.ErrorsDoc, SDocErrors);
  1746. // Append "See also" section
  1747. AppendSeeAlsoSection(AElement,DocNode);
  1748. // Append examples, if present
  1749. AppendExampleSection(AElement,DocNode);
  1750. end;
  1751. end;
  1752. Procedure THTMLWriter.CreateTopicPageBody(AElement : TTopicElement);
  1753. var
  1754. DocNode: TDocNode;
  1755. TableEl, TREl: TDOMElement;
  1756. I : Integer;
  1757. S : String;
  1758. begin
  1759. AppendTopicMenuBar(AElement);
  1760. DocNode:=AElement.TopicNode;
  1761. if Assigned(DocNode) then // should always be true, but we're being careful.
  1762. begin
  1763. AppendShortDescr(AElement,TitleElement, DocNode);
  1764. AppendShortDescr(AElement,CreateH2(BodyElement), DocNode);
  1765. if Assigned(DocNode.Descr) then
  1766. AppendDescrSection(AElement, BodyElement, DocNode.Descr, '');
  1767. AppendSeeAlsoSection(AElement,DocNode);
  1768. CreateTopicLinks(DocNode,AElement);
  1769. AppendExampleSection(AElement,DocNode);
  1770. end;
  1771. end;
  1772. procedure THTMLWriter.CreatePageBody(AElement: TPasElement;
  1773. ASubpageIndex: Integer);
  1774. var
  1775. i: Integer;
  1776. Element: TPasElement;
  1777. begin
  1778. CurDirectory := Allocator.GetFilename(AElement, ASubpageIndex);
  1779. i := Length(CurDirectory);
  1780. while (i > 0) and not (CurDirectory[i] in AllowDirectorySeparators) do
  1781. Dec(i);
  1782. CurDirectory := Copy(CurDirectory, 1, i);
  1783. BaseDirectory := Allocator.GetRelativePathToTop(AElement);
  1784. if AElement.ClassType = TPasPackage then
  1785. CreatePackagePageBody
  1786. else
  1787. begin
  1788. Element := AElement;
  1789. while (Element<>Nil) and (Element.ClassType<>TPasModule) do
  1790. Element := Element.Parent;
  1791. Module := TPasModule(Element);
  1792. if AElement.ClassType = TPasModule then
  1793. CreateModulePageBody(TPasModule(AElement), ASubpageIndex)
  1794. else if AElement.Parent.InheritsFrom(TPasClassType) then
  1795. CreateClassMemberPageBody(AElement)
  1796. else if AElement.ClassType = TPasConst then
  1797. CreateConstPageBody(TPasConst(AElement))
  1798. else if AElement.InheritsFrom(TPasClassType) then
  1799. CreateClassPageBody(TPasClassType(AElement), ASubpageIndex)
  1800. else if AElement.InheritsFrom(TPasType) then
  1801. CreateTypePageBody(TPasType(AElement))
  1802. else if AElement.ClassType = TPasVariable then
  1803. CreateVarPageBody(TPasVariable(AElement))
  1804. else if AElement.InheritsFrom(TPasProcedureBase) then
  1805. CreateProcPageBody(TPasProcedure(AElement))
  1806. else if AElement.ClassType = TTopicELement then
  1807. CreateTopicPageBody(TTopicElement(AElement))
  1808. end;
  1809. end;
  1810. procedure THTMLWriter.CreatePackagePageBody;
  1811. var
  1812. DocNode: TDocNode;
  1813. TableEl, TREl: TDOMElement;
  1814. i: Integer;
  1815. ThisModule: TPasModule;
  1816. L : TStringList;
  1817. begin
  1818. AppendMenuBar(0);
  1819. AppendTitle(Format(SDocPackageTitle, [Copy(Package.Name, 2, 256)]));
  1820. AppendShortDescr(CreatePara(BodyElement), Package);
  1821. AppendText(CreateH2(BodyElement), SDocUnits);
  1822. TableEl := CreateTable(BodyElement);
  1823. L:=TStringList.Create;
  1824. Try
  1825. L.Sorted:=True;
  1826. // Sort modules.
  1827. For I:=0 to Package.Modules.Count-1 do
  1828. L.AddObject(TPasModule(Package.Modules[i]).Name,TPasModule(Package.Modules[i]));
  1829. // Now create table.
  1830. for i:=0 to L.Count - 1 do
  1831. begin
  1832. ThisModule := TPasModule(L.Objects[i]);
  1833. TREl := CreateTR(TableEl);
  1834. AppendHyperlink(CreateCode(CreatePara(CreateTD_vtop(TREl))), ThisModule);
  1835. AppendShortDescrCell(TREl, ThisModule);
  1836. end;
  1837. Finally
  1838. L.Free;
  1839. end;
  1840. DocNode := Engine.FindDocNode(Package);
  1841. if Assigned(DocNode) then
  1842. begin
  1843. if Assigned(DocNode.Descr) then
  1844. AppendDescrSection(nil, BodyElement, DocNode.Descr, SDocDescription);
  1845. CreateTopicLinks(DocNode,Package);
  1846. end;
  1847. end;
  1848. Procedure THTMLWriter.CreateTopicLinks(Node : TDocNode; PasElement : TPasElement);
  1849. var
  1850. DocNode: TDocNode;
  1851. TableEl, TREl: TDOMElement;
  1852. First : Boolean;
  1853. ThisTopic: TPasElement;
  1854. begin
  1855. DocNode:=Node.FirstChild;
  1856. First:=True;
  1857. While Assigned(DocNode) do
  1858. begin
  1859. If DocNode.TopicNode then
  1860. begin
  1861. if first then
  1862. begin
  1863. First:=False;
  1864. AppendText(CreateH2(BodyElement), SDocRelatedTopics);
  1865. TableEl := CreateTable(BodyElement);
  1866. end;
  1867. TREl := CreateTR(TableEl);
  1868. ThisTopic:=FindTopicElement(DocNode);
  1869. if Assigned(ThisTopic) then
  1870. AppendHyperlink(CreateCode(CreatePara(CreateTD_vtop(TREl))), ThisTopic);
  1871. AppendShortDescrCell(TREl, ThisTopic);
  1872. end;
  1873. DocNode:=DocNode.NextSibling;
  1874. end;
  1875. end;
  1876. procedure THTMLWriter.CreateModulePageBody(AModule: TPasModule;
  1877. ASubpageIndex: Integer);
  1878. procedure CreateMainPage;
  1879. var
  1880. TableEl, TREl, TDEl, CodeEl: TDOMElement;
  1881. i: Integer;
  1882. UnitRef: TPasType;
  1883. DocNode: TDocNode;
  1884. begin
  1885. AppendMenuBar(0);
  1886. AppendTitle(Format(SDocUnitTitle, [AModule.Name]));
  1887. AppendShortDescr(CreatePara(BodyElement), AModule);
  1888. if AModule.InterfaceSection.UsesList.Count > 0 then
  1889. begin
  1890. TableEl := CreateTable(BodyElement);
  1891. AppendKw(CreateCode(CreatePara(CreateTD(CreateTR(TableEl)))), 'uses');
  1892. for i := 0 to AModule.InterfaceSection.UsesList.Count - 1 do
  1893. begin
  1894. UnitRef := TPasType(AModule.InterfaceSection.UsesList[i]);
  1895. DocNode := Engine.FindDocNode(UnitRef);
  1896. if Assigned(DocNode) and DocNode.IsSkipped then
  1897. continue;
  1898. TREl := CreateTR(TableEl);
  1899. TDEl := CreateTD_vtop(TREl);
  1900. CodeEl := CreateCode(CreatePara(TDEl));
  1901. AppendNbSp(CodeEl, 2);
  1902. AppendHyperlink(CodeEl, UnitRef);
  1903. if i < AModule.InterfaceSection.UsesList.Count - 1 then
  1904. AppendSym(CodeEl, ',')
  1905. else
  1906. AppendSym(CodeEl, ';');
  1907. AppendText(CodeEl, ' '); // Space for descriptions
  1908. AppendShortDescrCell(TREl, UnitRef);
  1909. end;
  1910. end;
  1911. DocNode := Engine.FindDocNode(AModule);
  1912. if Assigned(DocNode) then
  1913. begin
  1914. if Assigned(DocNode.Descr) then
  1915. AppendDescrSection(AModule, BodyElement, DocNode.Descr, SDocOverview);
  1916. CreateTopicLinks(DocNode,AModule);
  1917. end;
  1918. end;
  1919. procedure CreateSimpleSubpage(const ATitle: DOMString; AList: TList);
  1920. var
  1921. TableEl, TREl, TDEl, CodeEl: TDOMElement;
  1922. i, j: Integer;
  1923. Decl: TPasElement;
  1924. SortedList: TList;
  1925. DocNode: TDocNode;
  1926. S : String;
  1927. begin
  1928. AppendMenuBar(ASubpageIndex);
  1929. S:=ATitle;
  1930. AppendTitle(Format(SDocUnitTitle + ': %s', [AModule.Name, S]));
  1931. SortedList := TList.Create;
  1932. try
  1933. for i := 0 to AList.Count - 1 do
  1934. begin
  1935. Decl := TPasElement(AList[i]);
  1936. DocNode := Engine.FindDocNode(Decl);
  1937. if (not Assigned(DocNode)) or (not DocNode.IsSkipped) then
  1938. begin
  1939. j := 0;
  1940. while (j < SortedList.Count) and (CompareText(
  1941. TPasElement(SortedList[j]).PathName, Decl.PathName) < 0) do
  1942. Inc(j);
  1943. SortedList.Insert(j, Decl);
  1944. end;
  1945. end;
  1946. TableEl := CreateTable(BodyElement);
  1947. for i := 0 to SortedList.Count - 1 do
  1948. begin
  1949. Decl := TPasElement(SortedList[i]);
  1950. TREl := CreateTR(TableEl);
  1951. CodeEl := CreateCode(CreatePara(CreateTD_vtop(TREl)));
  1952. AppendHyperlink(CodeEl, Decl);
  1953. AppendShortDescrCell(TREl, Decl);
  1954. end;
  1955. finally
  1956. SortedList.Free;
  1957. end;
  1958. end;
  1959. procedure CreateResStringsPage;
  1960. var
  1961. ParaEl: TDOMElement;
  1962. i, j: Integer;
  1963. Decl: TPasResString;
  1964. DocNode: TDocNode;
  1965. begin
  1966. AppendMenuBar(ResstrSubindex);
  1967. AppendTitle(Format(SDocUnitTitle + ': %s', [AModule.Name, SDocResStrings]));
  1968. for i := 0 to AModule.InterfaceSection.ResStrings.Count - 1 do
  1969. begin
  1970. Decl := TPasResString(AModule.InterfaceSection.ResStrings[i]);
  1971. CreateEl(BodyElement, 'a')['name'] := LowerCase(Decl.Name);
  1972. ParaEl := CreatePara(BodyElement);
  1973. AppendText(CreateCode(ParaEl), Decl.Name);
  1974. CreateEl(ParaEl, 'br');
  1975. AppendText(ParaEl, Decl.Value);
  1976. end;
  1977. end;
  1978. begin
  1979. case ASubpageIndex of
  1980. 0:
  1981. CreateMainPage;
  1982. ResstrSubindex:
  1983. CreateResStringsPage;
  1984. ConstsSubindex:
  1985. CreateSimpleSubpage(SDocConstants, AModule.InterfaceSection.Consts);
  1986. TypesSubindex:
  1987. CreateSimpleSubpage(SDocTypes, AModule.InterfaceSection.Types);
  1988. ClassesSubindex:
  1989. CreateSimpleSubpage(SDocClasses, AModule.InterfaceSection.Classes);
  1990. ProcsSubindex:
  1991. CreateSimpleSubpage(SDocProceduresAndFunctions, AModule.InterfaceSection.Functions);
  1992. VarsSubindex:
  1993. CreateSimpleSubpage(SDocVariables, AModule.InterfaceSection.Variables);
  1994. end;
  1995. end;
  1996. procedure THTMLWriter.CreateConstPageBody(AConst: TPasConst);
  1997. var
  1998. TableEl, CodeEl: TDOMElement;
  1999. begin
  2000. AppendMenuBar(-1);
  2001. AppendTitle(AConst.Name);
  2002. AppendShortDescr(CreatePara(BodyElement), AConst);
  2003. AppendText(CreateH2(BodyElement), SDocDeclaration);
  2004. AppendSourceRef(AConst);
  2005. TableEl := CreateTable(BodyElement);
  2006. CodeEl := CreateCode(CreatePara(CreateTD(CreateTR(TableEl))));
  2007. AppendKw(CodeEl, 'const');
  2008. AppendText(CodeEl, ' ' + AConst.Name);
  2009. if Assigned(AConst.VarType) then
  2010. begin
  2011. AppendSym(CodeEl, ': ');
  2012. AppendType(CodeEl, TableEl, AConst.VarType, False);
  2013. end;
  2014. AppendPasSHFragment(CodeEl, ' = ' + AConst.Value + ';', 0);
  2015. FinishElementPage(AConst);
  2016. end;
  2017. procedure THTMLWriter.CreateTypePageBody(AType: TPasType);
  2018. var
  2019. TableEl, TREl, TDEl, CodeEl: TDOMElement;
  2020. DocNode: TDocNode;
  2021. i: Integer;
  2022. s: String;
  2023. EnumType: TPasEnumType;
  2024. EnumValue: TPasEnumValue;
  2025. Variable: TPasVariable;
  2026. begin
  2027. AppendMenuBar(-1);
  2028. AppendTitle(AType.Name);
  2029. AppendShortDescr(CreatePara(BodyElement), AType);
  2030. AppendText(CreateH2(BodyElement), SDocDeclaration);
  2031. AppendSourceRef(AType);
  2032. TableEl := CreateTable(BodyElement);
  2033. TREl := CreateTR(TableEl);
  2034. TDEl := CreateTD(TREl);
  2035. CodeEl := CreateCode(CreatePara(TDEl));
  2036. DocNode := Engine.FindDocNode(AType);
  2037. AppendKw(CodeEl, 'type ');
  2038. AppendText(CodeEl, AType.Name);
  2039. AppendSym(CodeEl, ' = ');
  2040. If Assigned(DocNode) and
  2041. Assigned(DocNode.Node) and
  2042. (Docnode.Node['opaque']='1') then
  2043. AppendText(CodeEl,SDocOpaque)
  2044. else
  2045. begin
  2046. // Alias
  2047. if AType.ClassType = TPasAliasType then
  2048. begin
  2049. if Assigned(TPasAliasType(AType).DestType) then
  2050. AppendHyperlink(CodeEl, TPasAliasType(AType).DestType)
  2051. else
  2052. AppendText(CreateWarning(CodeEl), '<Destination type is NIL>');
  2053. AppendSym(CodeEl, ';');
  2054. end else
  2055. // Class of
  2056. if AType.ClassType = TPasClassOfType then
  2057. begin
  2058. AppendKw(CodeEl, 'class of ');
  2059. AppendHyperlink(CodeEl, TPasClassOfType(AType).DestType);
  2060. AppendSym(CodeEl, ';');
  2061. end else
  2062. // Enumeration
  2063. if AType.ClassType = TPasEnumType then
  2064. begin
  2065. AppendSym(CodeEl, '(');
  2066. for i := 0 to TPasEnumType(AType).Values.Count - 1 do
  2067. begin
  2068. EnumValue := TPasEnumValue(TPasEnumType(AType).Values[i]);
  2069. TREl := CreateTR(TableEl);
  2070. CodeEl := CreateCode(CreatePara(CreateTD_vtop(TREl)));
  2071. AppendShortDescrCell(TREl, EnumValue);
  2072. AppendNbSp(CodeEl, 2);
  2073. s := EnumValue.Name;
  2074. if EnumValue.IsValueUsed then
  2075. s := s + ' = ' + IntToStr(EnumValue.Value);
  2076. if i < TPasEnumType(AType).Values.Count - 1 then
  2077. s := s + ',';
  2078. AppendPasSHFragment(CodeEl, s, 0);
  2079. end;
  2080. AppendSym(CreateCode(CreatePara(CreateTD(CreateTR(TableEl)))), ');');
  2081. end else
  2082. // Pointer type
  2083. if AType.ClassType = TPasPointerType then
  2084. begin
  2085. AppendSym(CodeEl, '^');
  2086. if Assigned(TPasPointerType(AType).DestType) then
  2087. AppendHyperlink(CodeEl, TPasPointerType(AType).DestType)
  2088. else
  2089. AppendText(CreateWarning(CodeEl), '<Destination type is NIL>');
  2090. AppendSym(CodeEl, ';');
  2091. end else
  2092. if AType.InheritsFrom(TPasProcedureType) then
  2093. begin
  2094. AppendSym(AppendType(CodeEl, TableEl, TPasType(AType), True), ';');
  2095. AppendProcArgsSection(BodyElement, TPasProcedureType(AType));
  2096. end else
  2097. // Record
  2098. if AType.ClassType = TPasRecordType then
  2099. begin
  2100. CodeEl := AppendRecordType(CodeEl, TableEl, TPasRecordType(AType), 0);
  2101. AppendSym(CodeEl, ';');
  2102. end else
  2103. // Set
  2104. if AType.ClassType = TPasSetType then
  2105. begin
  2106. AppendKw(CodeEl, 'set of ');
  2107. if TPasSetType(AType).EnumType.ClassType = TPasEnumType then
  2108. begin
  2109. AppendSym(CodeEl, '(');
  2110. EnumType := TPasEnumType(TPasSetType(AType).EnumType);
  2111. for i := 0 to EnumType.Values.Count - 1 do
  2112. begin
  2113. EnumValue := TPasEnumValue(EnumType.Values[i]);
  2114. TREl := CreateTR(TableEl);
  2115. CodeEl := CreateCode(CreatePara(CreateTD_vtop(TREl)));
  2116. AppendShortDescrCell(TREl, EnumValue);
  2117. AppendNbSp(CodeEl, 2);
  2118. s := EnumValue.Name;
  2119. if EnumValue.IsValueUsed then
  2120. s := s + ' = ' + IntToStr(EnumValue.Value);
  2121. if i < EnumType.Values.Count - 1 then
  2122. s := s + ',';
  2123. AppendPasSHFragment(CodeEl, s, 0);
  2124. end;
  2125. AppendSym(CreateCode(CreatePara(CreateTD(CreateTR(TableEl)))), ');');
  2126. end else
  2127. begin
  2128. AppendHyperlink(CodeEl, TPasSetType(AType).EnumType);
  2129. AppendSym(CodeEl, ';');
  2130. end;
  2131. end else
  2132. // Type alias
  2133. if AType.ClassType = TPasTypeAliasType then
  2134. begin
  2135. AppendKw(CodeEl, 'type ');
  2136. AppendHyperlink(CodeEl, TPasTypeAliasType(AType).DestType);
  2137. AppendSym(CodeEl, ';');
  2138. end else
  2139. // Probably one of the simple types, which allowed in other places as wel...
  2140. AppendSym(AppendType(CodeEl, TableEl, TPasType(AType), True), ';');
  2141. end;
  2142. FinishElementPage(AType);
  2143. end;
  2144. function PropertyFilter(AMember: TPasElement): Boolean;
  2145. begin
  2146. Result := (AMember.ClassType = TPasProperty) and
  2147. (Copy(AMember.Name, 1, 2) <> 'On');
  2148. end;
  2149. function MethodFilter(AMember: TPasElement): Boolean;
  2150. begin
  2151. Result := AMember.InheritsFrom(TPasProcedureBase);
  2152. end;
  2153. function EventFilter(AMember: TPasElement): Boolean;
  2154. begin
  2155. Result := (AMember.ClassType = TPasProperty) and
  2156. (Copy(AMember.Name, 1, 2) = 'On');
  2157. end;
  2158. procedure THTMLWriter.CreateClassPageBody(AClass: TPasClassType;
  2159. ASubpageIndex: Integer);
  2160. type
  2161. TMemberFilter = function(AMember: TPasElement): Boolean;
  2162. var
  2163. ParaEl: TDOMElement;
  2164. procedure AppendMemberListLink(AListSubpageIndex: Integer;
  2165. const AText: DOMString);
  2166. var
  2167. LinkEl: TDOMElement;
  2168. begin
  2169. AppendText(ParaEl, '[');
  2170. LinkEl := CreateEl(ParaEl, 'a');
  2171. LinkEl['href'] :=
  2172. FixHtmlPath(ResolveLinkWithinPackage(AClass, AListSubpageIndex));
  2173. LinkEl['onClick'] := 'window.open(''' + LinkEl['href'] + ''', ''list'', ' +
  2174. '''dependent=yes,resizable=yes,scrollbars=yes,height=400,width=300''); return false;';
  2175. AppendText(LinkEl, AText);
  2176. AppendText(ParaEl, ' (');
  2177. LinkEl := CreateEl(ParaEl, 'a');
  2178. LinkEl['href'] :=
  2179. FixHtmlPath(ResolveLinkWithinPackage(AClass, AListSubpageIndex + 1));
  2180. LinkEl['onClick'] := 'window.open(''' + LinkEl['href'] + ''', ''list'', ' +
  2181. '''dependent=yes,resizable=yes,scrollbars=yes,height=400,width=300''); return false;';
  2182. AppendText(LinkEl, SDocByName);
  2183. AppendText(ParaEl, ')');
  2184. AppendText(ParaEl, '] ');
  2185. end;
  2186. procedure CreateMainPage;
  2187. var
  2188. TableEl, TREl, TDEl, CodeEl: TDOMElement;
  2189. DocNode: TDocNode;
  2190. Member: TPasElement;
  2191. CurVisibility: TPasMemberVisibility;
  2192. i: Integer;
  2193. s: String;
  2194. ThisClass: TPasClassType;
  2195. HaveSeenTObject: Boolean;
  2196. begin
  2197. AppendMenuBar(-1);
  2198. AppendTitle(AClass.Name);
  2199. ParaEl := CreatePara(BodyElement);
  2200. AppendMemberListLink(PropertiesByInheritanceSubindex, SDocProperties);
  2201. AppendMemberListLink(MethodsByInheritanceSubindex, SDocMethods);
  2202. AppendMemberListLink(EventsByInheritanceSubindex, SDocEvents);
  2203. AppendShortDescr(CreatePara(BodyElement), AClass);
  2204. AppendText(CreateH2(BodyElement), SDocDeclaration);
  2205. AppendSourceRef(AClass);
  2206. TableEl := CreateTable(BodyElement);
  2207. TREl := CreateTR(TableEl);
  2208. TDEl := CreateTD(TREl);
  2209. CodeEl := CreateCode(CreatePara(TDEl));
  2210. AppendKw(CodeEl, 'type');
  2211. AppendText(CodeEl, ' ' + AClass.Name + ' ');
  2212. AppendSym(CodeEl, '=');
  2213. AppendText(CodeEl, ' ');
  2214. AppendKw(CodeEl, ObjKindNames[AClass.ObjKind]);
  2215. if Assigned(AClass.AncestorType) then
  2216. begin
  2217. AppendSym(CodeEl, '(');
  2218. AppendHyperlink(CodeEl, AClass.AncestorType);
  2219. AppendSym(CodeEl, ')');
  2220. end;
  2221. if AClass.Members.Count > 0 then
  2222. begin
  2223. CurVisibility := visDefault;
  2224. for i := 0 to AClass.Members.Count - 1 do
  2225. begin
  2226. Member := TPasElement(AClass.Members[i]);
  2227. if CurVisibility <> Member.Visibility then
  2228. begin
  2229. CurVisibility := Member.Visibility;
  2230. if ((CurVisibility = visPrivate) and Engine.HidePrivate) or
  2231. ((CurVisibility = visProtected) and Engine.HideProtected) then
  2232. continue;
  2233. case CurVisibility of
  2234. visPrivate: s := 'private';
  2235. visProtected: s := 'protected';
  2236. visPublic: s := 'public';
  2237. visPublished: s := 'published';
  2238. visAutomated: s := 'automated';
  2239. end;
  2240. AppendKw(CreateCode(CreatePara(CreateTD(CreateTR(TableEl)))), s);
  2241. end else
  2242. if ((CurVisibility = visPrivate) and Engine.HidePrivate) or
  2243. ((CurVisibility = visProtected) and Engine.HideProtected) then
  2244. continue;
  2245. TREl := CreateTR(TableEl);
  2246. CodeEl := CreateCode(CreatePara(CreateTD_vtop(TREl)));
  2247. AppendNbSp(CodeEl, 2);
  2248. AppendShortDescrCell(TREl, Member);
  2249. if Member.InheritsFrom(TPasProcedureBase) then
  2250. begin
  2251. AppendKw(CodeEl, TPasProcedureBase(Member).TypeName + ' ');
  2252. AppendHyperlink(CodeEl, Member);
  2253. if (Member.ClassType = TPasOverloadedProc) or
  2254. (TPasProcedure(Member).ProcType.Args.Count > 0) then
  2255. AppendSym(CodeEl, '();')
  2256. else
  2257. AppendSym(CodeEl, ';');
  2258. if Member.ClassType <> TPasOverloadedProc then
  2259. AppendProcExt(CodeEl, TPasProcedure(Member));
  2260. end else
  2261. if Member.ClassType = TPasVariable then
  2262. begin
  2263. AppendHyperlink(CodeEl, Member);
  2264. AppendSym(CodeEl, ': ');
  2265. AppendHyperlink(CodeEl, TPasVariable(Member).VarType);
  2266. AppendSym(CodeEl, ';');
  2267. end else
  2268. if Member.ClassType = TPasProperty then
  2269. begin
  2270. AppendKw(CodeEl, 'property ');
  2271. AppendHyperlink(CodeEl, Member);
  2272. if Assigned(TPasProperty(Member).VarType) then
  2273. begin
  2274. AppendSym(CodeEl, ': ');
  2275. AppendHyperlink(CodeEl, TPasProperty(Member).VarType);
  2276. end;
  2277. AppendSym(CodeEl, ';');
  2278. if TPasProperty(Member).IsDefault then
  2279. begin
  2280. AppendKw(CodeEl, ' default');
  2281. AppendSym(CodeEl, ';');
  2282. end;
  2283. SetLength(s, 0);
  2284. if Length(TPasProperty(Member).ReadAccessorName) > 0 then
  2285. s := s + 'r';
  2286. if Length(TPasProperty(Member).WriteAccessorName) > 0 then
  2287. s := s + 'w';
  2288. if Length(TPasProperty(Member).StoredAccessorName) > 0 then
  2289. s := s + 's';
  2290. if Length(s) > 0 then
  2291. AppendText(CodeEl, ' [' + s + ']');
  2292. end else
  2293. AppendText(CreateWarning(CodeEl), '<' + Member.ClassName + '>');
  2294. end;
  2295. CodeEl := CreateCode(CreatePara(CreateTD(CreateTR(TableEl))));
  2296. end;
  2297. AppendText(CodeEl, ' '); // !!!: Dirty trick, necessary for current XML writer
  2298. AppendKw(CodeEl, 'end');
  2299. AppendSym(CodeEl, ';');
  2300. AppendText(CreateH2(BodyElement), SDocInheritance);
  2301. TableEl := CreateTable(BodyElement);
  2302. HaveSeenTObject := AClass.ObjKind <> okClass;
  2303. ThisClass := AClass;
  2304. while True do
  2305. begin
  2306. TREl := CreateTR(TableEl);
  2307. TDEl := CreateTD_vtop(TREl);
  2308. TDEl['align'] := 'center';
  2309. CodeEl := CreateCode(CreatePara(TDEl));
  2310. AppendHyperlink(CodeEl, ThisClass);
  2311. AppendShortDescrCell(TREl, ThisClass);
  2312. if HaveSeenTObject or (CompareText(ThisClass.Name, 'TObject') = 0) then
  2313. HaveSeenTObject := True
  2314. else
  2315. begin
  2316. TDEl := CreateTD(CreateTR(TableEl));
  2317. TDEl['align'] := 'center';
  2318. AppendText(TDEl, '|');
  2319. end;
  2320. if Assigned(ThisClass.AncestorType) then
  2321. begin
  2322. if ThisClass.AncestorType.InheritsFrom(TPasClassType) then
  2323. ThisClass := TPasClassType(ThisClass.AncestorType)
  2324. else
  2325. begin
  2326. TDEl := CreateTD(CreateTR(TableEl));
  2327. TDEl['align'] := 'center';
  2328. AppendText(CreateCode(CreatePara(TDEl)), ThisClass.AncestorType.Name);
  2329. if CompareText(ThisClass.AncestorType.Name, 'TObject') = 0 then
  2330. HaveSeenTObject := True
  2331. else
  2332. begin
  2333. TDEl := CreateTD(CreateTR(TableEl));
  2334. TDEl['align'] := 'center';
  2335. AppendText(TDEl, '?');
  2336. end;
  2337. break;
  2338. end
  2339. end else
  2340. break;
  2341. end;
  2342. if not HaveSeenTObject then
  2343. begin
  2344. TDEl := CreateTD(CreateTR(TableEl));
  2345. TDEl['align'] := 'center';
  2346. AppendText(CreateCode(CreatePara(TDEl)), 'TObject');
  2347. end;
  2348. FinishElementPage(AClass);
  2349. end;
  2350. procedure CreateInheritanceSubpage(AFilter: TMemberFilter);
  2351. var
  2352. ThisClass: TPasClassType;
  2353. i: Integer;
  2354. Member: TPasElement;
  2355. TableEl, TREl, TDEl, ParaEl, LinkEl: TDOMElement;
  2356. begin
  2357. TableEl := CreateTable(BodyElement);
  2358. ThisClass := AClass;
  2359. while True do
  2360. begin
  2361. TREl := CreateTR(TableEl);
  2362. TDEl := CreateTD(TREl);
  2363. TDEl['colspan'] := '3';
  2364. CreateTD(TREl);
  2365. LinkEl := AppendHyperlink(CreateEl(CreateCode(CreatePara(TDEl)), 'b'), ThisClass);
  2366. if Assigned(LinkEl) then
  2367. LinkEl['onClick'] := 'opener.location.href = ''' + LinkEl['href'] +
  2368. '''; return false;';
  2369. for i := 0 to ThisClass.Members.Count - 1 do
  2370. begin
  2371. Member := TPasElement(ThisClass.Members[i]);
  2372. if ((Member.Visibility = visPrivate) and Engine.HidePrivate) or
  2373. ((Member.Visibility = visProtected) and Engine.HideProtected) or
  2374. not AFilter(Member) then
  2375. continue;
  2376. TREl := CreateTR(TableEl);
  2377. ParaEl := CreatePara(CreateTD(TREl));
  2378. case Member.Visibility of
  2379. visPrivate:
  2380. AppendText(ParaEl, 'pv');
  2381. visProtected:
  2382. AppendText(ParaEl, 'pt');
  2383. visPublished:
  2384. AppendText(ParaEl, 'pl');
  2385. end;
  2386. AppendNbSp(ParaEl, 1);
  2387. ParaEl := CreateTD(TREl);
  2388. if (Member.ClassType = TPasProperty) and
  2389. (Length(TPasProperty(Member).WriteAccessorName) = 0) then
  2390. begin
  2391. AppendText(ParaEl, 'ro');
  2392. AppendNbSp(ParaEl, 1);
  2393. end;
  2394. LinkEl := AppendHyperlink(CreatePara(CreateTD(TREl)), Member);
  2395. if Assigned(LinkEl) then
  2396. LinkEl['onClick'] := 'opener.location.href = ''' + LinkEl['href'] +
  2397. '''; return false;';
  2398. end;
  2399. if (not Assigned(ThisClass.AncestorType)) or
  2400. (not (ThisClass.AncestorType.ClassType = TPasClassType)) then
  2401. break;
  2402. ThisClass := TPasClassType(ThisClass.AncestorType);
  2403. AppendNbSp(CreatePara(CreateTD(CreateTR(TableEl))), 1);
  2404. end;
  2405. end;
  2406. procedure CreateSortedSubpage(AFilter: TMemberFilter);
  2407. var
  2408. List: TList;
  2409. ThisClass: TPasClassType;
  2410. i, j: Integer;
  2411. Member: TPasElement;
  2412. TableEl, TREl, TDEl, ParaEl, LinkEl: TDOMElement;
  2413. begin
  2414. List := TList.Create;
  2415. try
  2416. ThisClass := AClass;
  2417. while True do
  2418. begin
  2419. for i := 0 to ThisClass.Members.Count - 1 do
  2420. begin
  2421. Member := TPasElement(ThisClass.Members[i]);
  2422. if (not (((Member.Visibility = visPrivate) and Engine.HidePrivate) or
  2423. ((Member.Visibility = visProtected) and Engine.HideProtected))) and
  2424. AFilter(Member) then
  2425. begin
  2426. j := 0;
  2427. while (j < List.Count) and
  2428. (CompareText(TPasElement(List[j]).Name, Member.Name) < 0) do
  2429. Inc(j);
  2430. List.Insert(j, Member);
  2431. end;
  2432. end;
  2433. if (not Assigned(ThisClass.AncestorType)) or
  2434. (not (ThisClass.AncestorType.ClassType = TPasClassType)) then
  2435. break;
  2436. ThisClass := TPasClassType(ThisClass.AncestorType);
  2437. end;
  2438. TableEl := CreateTable(BodyElement);
  2439. for i := 0 to List.Count - 1 do
  2440. begin
  2441. Member := TPasElement(List[i]);
  2442. TREl := CreateTR(TableEl);
  2443. ParaEl := CreatePara(CreateTD(TREl));
  2444. case Member.Visibility of
  2445. visPrivate:
  2446. AppendText(ParaEl, 'pv');
  2447. visProtected:
  2448. AppendText(ParaEl, 'pt');
  2449. visPublished:
  2450. AppendText(ParaEl, 'pl');
  2451. end;
  2452. AppendNbSp(ParaEl, 1);
  2453. ParaEl := CreatePara(CreateTD(TREl));
  2454. if (Member.ClassType = TPasProperty) and
  2455. (Length(TPasProperty(Member).WriteAccessorName) = 0) then
  2456. begin
  2457. AppendText(ParaEl, 'ro');
  2458. AppendNbSp(ParaEl, 1);
  2459. end;
  2460. TDEl := CreateTD(TREl);
  2461. TDEl['nowrap'] := 'nowrap';
  2462. ParaEl := CreatePara(TDEl);
  2463. LinkEl := AppendHyperlink(ParaEl, Member);
  2464. if Assigned(LinkEl) then
  2465. LinkEl['onClick'] := 'opener.location.href = ''' + LinkEl['href'] +
  2466. '''; return false;';
  2467. AppendText(ParaEl, ' (');
  2468. LinkEl := AppendHyperlink(ParaEl, Member.Parent);
  2469. if Assigned(LinkEl) then
  2470. LinkEl['onClick'] := 'opener.location.href = ''' + LinkEl['href'] +
  2471. '''; return false;';
  2472. AppendText(ParaEl, ')');
  2473. end;
  2474. finally
  2475. List.Free;
  2476. end;
  2477. end;
  2478. begin
  2479. case ASubpageIndex of
  2480. 0:
  2481. CreateMainPage;
  2482. PropertiesByInheritanceSubindex:
  2483. CreateInheritanceSubpage(@PropertyFilter);
  2484. PropertiesByNameSubindex:
  2485. CreateSortedSubpage(@PropertyFilter);
  2486. MethodsByInheritanceSubindex:
  2487. CreateInheritanceSubpage(@MethodFilter);
  2488. MethodsByNameSubindex:
  2489. CreateSortedSubpage(@MethodFilter);
  2490. EventsByInheritanceSubindex:
  2491. CreateInheritanceSubpage(@EventFilter);
  2492. EventsByNameSubindex:
  2493. CreateSortedSubpage(@EventFilter);
  2494. end;
  2495. end;
  2496. procedure THTMLWriter.CreateClassMemberPageBody(AElement: TPasElement);
  2497. var
  2498. TableEl, TREl, CodeEl: TDOMElement;
  2499. procedure CreateVarPage(Element: TPasVariable);
  2500. begin
  2501. AppendHyperlink(CodeEl, Element.Parent);
  2502. AppendSym(CodeEl, '.');
  2503. AppendText(CodeEl, Element.Name);
  2504. if Assigned(Element.VarType) then
  2505. begin
  2506. AppendSym(CodeEl, ': ');
  2507. AppendSym(AppendType(CodeEl, TableEl, Element.VarType, False), ';');
  2508. end;
  2509. end;
  2510. procedure CreatePropertyPage(Element: TPasProperty);
  2511. var
  2512. NeedBreak: Boolean;
  2513. begin
  2514. AppendKw(CodeEl, 'property ');
  2515. AppendHyperlink(CodeEl, Element.Parent);
  2516. AppendSym(CodeEl, '.');
  2517. AppendText(CodeEl, Element.Name);
  2518. if Assigned(Element.VarType) then
  2519. begin
  2520. AppendSym(CodeEl, ': ');
  2521. AppendType(CodeEl, TableEl, Element.VarType, False);
  2522. end;
  2523. NeedBreak := False;
  2524. if Length(TPasProperty(Element).IndexValue) <> 0 then
  2525. begin
  2526. CreateEl(CodeEl, 'br');
  2527. AppendNbsp(CodeEl, 2);
  2528. AppendKw(CodeEl, 'index ');
  2529. AppendPasSHFragment(CodeEl, TPasProperty(Element).IndexValue, 0);
  2530. NeedBreak := True;
  2531. end;
  2532. if Length(TPasProperty(Element).ReadAccessorName) <> 0 then
  2533. begin
  2534. CreateEl(CodeEl, 'br');
  2535. AppendNbsp(CodeEl, 2);
  2536. AppendKw(CodeEl, 'read ');
  2537. AppendText(CodeEl, TPasProperty(Element).ReadAccessorName);
  2538. NeedBreak := True;
  2539. end;
  2540. if Length(TPasProperty(Element).WriteAccessorName) <> 0 then
  2541. begin
  2542. CreateEl(CodeEl, 'br');
  2543. AppendNbsp(CodeEl, 2);
  2544. AppendKw(CodeEl, 'write ');
  2545. AppendText(CodeEl, TPasProperty(Element).WriteAccessorName);
  2546. NeedBreak := True;
  2547. end;
  2548. if Length(TPasProperty(Element).StoredAccessorName) <> 0 then
  2549. begin
  2550. CreateEl(CodeEl, 'br');
  2551. AppendNbsp(CodeEl, 2);
  2552. AppendKw(CodeEl, 'stored ');
  2553. AppendText(CodeEl, TPasProperty(Element).StoredAccessorName);
  2554. NeedBreak := True;
  2555. end;
  2556. if Length(TPasProperty(Element).DefaultValue) <> 0 then
  2557. begin
  2558. CreateEl(CodeEl, 'br');
  2559. AppendNbsp(CodeEl, 2);
  2560. AppendKw(CodeEl, 'default ');
  2561. AppendPasSHFragment(CodeEl, TPasProperty(Element).DefaultValue, 0);
  2562. NeedBreak := True;
  2563. end;
  2564. AppendSym(CodeEl, ';');
  2565. if TPasProperty(Element).IsDefault or TPasProperty(Element).IsNodefault then
  2566. begin
  2567. if NeedBreak then
  2568. begin
  2569. CreateEl(CodeEl, 'br');
  2570. AppendNbsp(CodeEl, 2);
  2571. end;
  2572. if TPasProperty(Element).IsDefault then
  2573. AppendKw(CodeEl, 'default')
  2574. else
  2575. AppendKw(CodeEl, 'nodefault');
  2576. AppendSym(CodeEl, ';');
  2577. end;
  2578. end;
  2579. var
  2580. s: String;
  2581. DocNode: TDocNode;
  2582. begin
  2583. AppendMenuBar(-1);
  2584. AppendTitle(AElement.FullName);
  2585. AppendShortDescr(CreatePara(BodyElement), AElement);
  2586. AppendText(CreateH2(BodyElement), SDocDeclaration);
  2587. AppendSourceRef(AElement);
  2588. TableEl := CreateTable(BodyElement);
  2589. TREl := CreateTR(TableEl);
  2590. CodeEl := CreateCode(CreatePara(CreateTD(TREl)));
  2591. AppendText(CodeEl, ' '); // !!!: Workaround for current HTML writer
  2592. case AElement.Visibility of
  2593. visPrivate: s := 'private';
  2594. visProtected: s := 'protected';
  2595. visPublic: s := 'public';
  2596. visPublished: s := 'published';
  2597. visAutomated: s := 'automated';
  2598. else s := '';
  2599. end;
  2600. if Length(s) > 0 then
  2601. AppendKw(CodeEl, s);
  2602. AppendText(CodeEl, ' ');
  2603. if AElement.ClassType = TPasVariable then
  2604. CreateVarPage(TPasVariable(AElement))
  2605. else if AElement.InheritsFrom(TPasProcedureBase) then
  2606. AppendProcDecl(CodeEl, TableEl, TPasProcedureBase(AElement))
  2607. else if AElement.ClassType = TPasProperty then
  2608. CreatePropertyPage(TPasProperty(AElement))
  2609. else
  2610. AppendText(CreateWarning(BodyElement), '<' + AElement.ClassName + '>');
  2611. FinishElementPage(AElement);
  2612. end;
  2613. procedure THTMLWriter.CreateVarPageBody(AVar: TPasVariable);
  2614. var
  2615. TableEl, TREl, TDEl, CodeEl, El: TDOMElement;
  2616. DocNode: TDocNode;
  2617. begin
  2618. AppendMenuBar(-1);
  2619. AppendTitle(AVar.FullName);
  2620. AppendShortDescr(CreatePara(BodyElement), AVar);
  2621. AppendText(CreateH2(BodyElement), SDocDeclaration);
  2622. AppendSourceRef(AVar);
  2623. TableEl := CreateTable(BodyElement);
  2624. TREl := CreateTR(TableEl);
  2625. TDEl := CreateTD(TREl);
  2626. CodeEl := CreateCode(CreatePara(TDEl));
  2627. AppendKw(CodeEl, 'var');
  2628. AppendText(CodeEl, ' ' + AVar.Name);
  2629. if Assigned(AVar.VarType) then
  2630. begin
  2631. AppendSym(CodeEl, ': ');
  2632. El := AppendType(CodeEl, TableEl, AVar.VarType, False);
  2633. end else
  2634. El := CodeEl;
  2635. if Length(AVar.Value) > 0 then
  2636. AppendPasSHFragment(El, ' = ' + AVar.Value + ';', 0)
  2637. else
  2638. AppendSym(El, ';');
  2639. FinishElementPage(AVar);
  2640. end;
  2641. procedure THTMLWriter.CreateProcPageBody(AProc: TPasProcedureBase);
  2642. var
  2643. TableEl, TREl, TDEl, CodeEl: TDOMElement;
  2644. begin
  2645. AppendMenuBar(-1);
  2646. AppendTitle(AProc.Name);
  2647. AppendShortDescr(CreatePara(BodyElement), AProc);
  2648. AppendText(CreateH2(BodyElement), SDocDeclaration);
  2649. AppendSourceRef(AProc);
  2650. TableEl := CreateTable(BodyElement);
  2651. TREl := CreateTR(TableEl);
  2652. TDEl := CreateTD(TREl);
  2653. CodeEl := CreateCode(CreatePara(TDEl));
  2654. AppendProcDecl(CodeEl, TableEl, AProc);
  2655. FinishElementPage(AProc);
  2656. end;
  2657. Function THTMLWriter.InterPretOption(Const Cmd,Arg : String) : boolean;
  2658. begin
  2659. Result:=True;
  2660. if Cmd = '--html-search' then
  2661. SearchPage := Arg
  2662. else if Cmd = '--footer' then
  2663. FooterFile := Arg
  2664. else
  2665. Result:=False;
  2666. end;
  2667. procedure THTMLWriter.WriteDoc;
  2668. begin
  2669. WriteLn(Format(SWritingPages, [PageCount]));
  2670. WriteHTMLPages;
  2671. end;
  2672. class procedure THTMLWriter.Usage(List: TStrings);
  2673. begin
  2674. List.add('--footer');
  2675. List.Add(SHTMLUsageFooter);
  2676. end;
  2677. // private methods
  2678. function THTMLWriter.GetPageCount: Integer;
  2679. begin
  2680. Result := PageInfos.Count;
  2681. end;
  2682. procedure THTMLWriter.SetOnTest(const AValue: TNotifyEvent);
  2683. begin
  2684. if FOnTest=AValue then exit;
  2685. FOnTest:=AValue;
  2686. end;
  2687. procedure THTMLWriter.CreateAllocator;
  2688. begin
  2689. FAllocator:=TLongNameFileAllocator.Create('.html');
  2690. end;
  2691. procedure THTMWriter.CreateAllocator;
  2692. begin
  2693. FAllocator:=TShortNameFileAllocator.Create('.htm');
  2694. end;
  2695. initialization
  2696. // Do not localize.
  2697. RegisterWriter(THTMLWriter,'html','HTML output using fpdoc.css stylesheet.');
  2698. RegisterWriter(THTMWriter,'htm','HTM (8.3 filenames) output using fpdoc.css stylesheet.');
  2699. RegisterWriter(TCHMHTMLWriter,'chm','Compressed HTML file output using fpdoc.css stylesheet.');
  2700. finalization
  2701. UnRegisterWriter('html');
  2702. UnRegisterWriter('htm');
  2703. UnRegisterWriter('chm');
  2704. end.