dw_html.pp 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021
  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 DirSeparators) 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 WriteLn('!!!!!!!!!!!!!!!!!!!!!!1');
  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. AppendKw(CodeEl, 'packed record')
  1450. else
  1451. AppendKw(CodeEl, 'record');
  1452. for i := 0 to Element.Members.Count - 1 do
  1453. begin
  1454. Variable := TPasVariable(Element.Members[i]);
  1455. TREl := CreateTR(TableEl);
  1456. CodeEl := CreateCode(CreatePara(CreateTD_vtop(TREl)));
  1457. AppendShortDescrCell(TREl, Variable);
  1458. AppendNbSp(CodeEl, NestingLevel * 2 + 2);
  1459. AppendText(CodeEl, Variable.Name);
  1460. AppendSym(CodeEl, ': ');
  1461. CodeEl := AppendType(CodeEl, TableEl, Variable.VarType, False, NestingLevel + 1);
  1462. AppendSym(CodeEl, ';');
  1463. end;
  1464. if Assigned(Element.VariantType) then
  1465. begin
  1466. TREl := CreateTR(TableEl);
  1467. CodeEl := CreateCode(CreatePara(CreateTD_vtop(TREl)));
  1468. AppendNbSp(CodeEl, NestingLevel * 2 + 2);
  1469. AppendKw(CodeEl, 'case ');
  1470. if TPasRecordType(Element).VariantName <> '' then
  1471. begin
  1472. AppendText(CodeEl, TPasRecordType(Element).VariantName);
  1473. AppendSym(CodeEl, ': ');
  1474. end;
  1475. CodeEl := AppendType(CodeEl, TableEl, TPasRecordType(Element).VariantType, True);
  1476. AppendKw(CodeEl, ' of');
  1477. for i := 0 to TPasRecordType(Element).Variants.Count - 1 do
  1478. begin
  1479. CurVariant := TPasVariant(Element.Variants[i]);
  1480. TREl := CreateTR(TableEl);
  1481. CodeEl := CreateCode(CreatePara(CreateTD_vtop(TREl)));
  1482. AppendNbSp(CodeEl, NestingLevel * 2 + 4);
  1483. for j := 0 to CurVariant.Values.Count - 1 do
  1484. begin
  1485. if j > 0 then
  1486. AppendSym(CodeEl, ', ');
  1487. AppendPasSHFragment(CodeEl, CurVariant.Values[j], 0);
  1488. end;
  1489. AppendSym(CodeEl, ': (');
  1490. AppendType(CodeEl, TableEl, CurVariant.Members, True, NestingLevel + 3);
  1491. CodeEl := CreateCode(CreatePara(CreateTD_vtop(CreateTR(TableEl))));
  1492. AppendNbSp(CodeEl, NestingLevel * 2 + 6);
  1493. AppendSym(CodeEl, ');');
  1494. end;
  1495. end;
  1496. if not (Element.Parent is TPasVariant) then
  1497. begin
  1498. CodeEl := CreateCode(CreatePara(CreateTD(CreateTR(TableEl))));
  1499. AppendText(CodeEl, ' '); // !!!: Dirty trick, necessary for current XML writer
  1500. AppendNbSp(CodeEl, NestingLevel * 2);
  1501. AppendKw(CodeEl, 'end');
  1502. end;
  1503. Result := CodeEl;
  1504. end;
  1505. procedure THTMLWriter.AppendTitle(const AText: DOMString);
  1506. begin
  1507. AppendText(TitleElement, AText);
  1508. AppendText(CreateH1(BodyElement), AText);
  1509. end;
  1510. procedure THTMLWriter.AppendTopicMenuBar(Topic : TTopicElement);
  1511. var
  1512. TableEl, TREl, ParaEl, TitleEl: TDOMElement;
  1513. procedure AddLink(El : TPasElement; const AName: String);
  1514. begin
  1515. AppendText(ParaEl, '[');
  1516. AppendText(CreateLink(ParaEl, ResolveLinkWithinPackage(El,0)),AName);
  1517. AppendText(ParaEl, ']');
  1518. end;
  1519. begin
  1520. TableEl := CreateEl(BodyElement, 'table');
  1521. TableEl['cellpadding'] := '4';
  1522. TableEl['cellspacing'] := '0';
  1523. TableEl['border'] := '0';
  1524. TableEl['width'] := '100%';
  1525. TableEl['class'] := 'bar';
  1526. TREl := CreateTR(TableEl);
  1527. ParaEl := CreateEl(CreateTD(TREl), 'b');
  1528. If Assigned(Topic.Previous) then
  1529. AddLink(Topic.Previous,SDocPrevious);
  1530. If Assigned(Topic.Parent) then
  1531. AddLink(Topic.Parent,SDocUp);
  1532. if Assigned(Topic.Next) then
  1533. AddLink(Topic.Next,SDocNext);
  1534. if Length(SearchPage) > 0 then
  1535. begin
  1536. AppendText(ParaEl, '[');
  1537. AppendText(CreateLink(ParaEl, SearchPage), SDocSearch);
  1538. AppendText(ParaEl, ']');
  1539. end;
  1540. ParaEl := CreateTD(TREl);
  1541. ParaEl['align'] := 'right';
  1542. TitleEl := CreateEl(ParaEl, 'span');
  1543. TitleEl['class'] := 'bartitle';
  1544. if Assigned(Module) then
  1545. AppendText(TitleEl, Format(SDocUnitTitle, [Module.Name]));
  1546. if Assigned(Package) then
  1547. begin
  1548. AppendText(TitleEl, ' (');
  1549. AppendHyperlink(TitleEl, Package);
  1550. AppendText(TitleEl, ')');
  1551. end;
  1552. end;
  1553. procedure THTMLWriter.AppendMenuBar(ASubpageIndex: Integer);
  1554. var
  1555. TableEl, TREl, ParaEl, TitleEl: TDOMElement;
  1556. procedure AddLink(ALinkSubpageIndex: Integer; const AName: String);
  1557. begin
  1558. AppendText(ParaEl, '[');
  1559. if ALinkSubpageIndex = ASubpageIndex then
  1560. AppendText(ParaEl, AName)
  1561. else
  1562. AppendText(
  1563. CreateLink(ParaEl, ResolveLinkWithinPackage(Module, ALinkSubpageIndex)),
  1564. AName);
  1565. AppendText(ParaEl, ']');
  1566. end;
  1567. begin
  1568. TableEl := CreateEl(BodyElement, 'table');
  1569. TableEl['cellpadding'] := '4';
  1570. TableEl['cellspacing'] := '0';
  1571. TableEl['border'] := '0';
  1572. TableEl['width'] := '100%';
  1573. TableEl['class'] := 'bar';
  1574. TREl := CreateTR(TableEl);
  1575. ParaEl := CreateEl(CreateTD(TREl), 'b');
  1576. if Assigned(Module) then
  1577. begin
  1578. AddLink(0, SDocOverview);
  1579. if Module.InterfaceSection.ResStrings.Count > 0 then
  1580. AddLink(ResstrSubindex, SDocResStrings);
  1581. if Module.InterfaceSection.Consts.Count > 0 then
  1582. AddLink(ConstsSubindex, SDocConstants);
  1583. if Module.InterfaceSection.Types.Count > 0 then
  1584. AddLink(TypesSubindex, SDocTypes);
  1585. if Module.InterfaceSection.Classes.Count > 0 then
  1586. AddLink(ClassesSubindex, SDocClasses);
  1587. if Module.InterfaceSection.Functions.Count > 0 then
  1588. AddLink(ProcsSubindex, SDocProceduresAndFunctions);
  1589. if Module.InterfaceSection.Variables.Count > 0 then
  1590. AddLink(VarsSubindex, SDocVariables);
  1591. end;
  1592. if Length(SearchPage) > 0 then
  1593. begin
  1594. AppendText(ParaEl, '[');
  1595. AppendText(CreateLink(ParaEl, SearchPage), SDocSearch);
  1596. AppendText(ParaEl, ']');
  1597. end;
  1598. ParaEl := CreateTD(TREl);
  1599. ParaEl['align'] := 'right';
  1600. TitleEl := CreateEl(ParaEl, 'span');
  1601. TitleEl['class'] := 'bartitle';
  1602. if Assigned(Module) then
  1603. AppendText(TitleEl, Format(SDocUnitTitle, [Module.Name]));
  1604. if Assigned(Package) then
  1605. begin
  1606. AppendText(TitleEl, ' (');
  1607. AppendHyperlink(TitleEl, Package);
  1608. AppendText(TitleEl, ')');
  1609. end;
  1610. end;
  1611. procedure THTMLWriter.AppendSourceRef(AElement: TPasElement);
  1612. begin
  1613. AppendText(CreatePara(BodyElement), Format(SDocSourcePosition,
  1614. [ExtractFileName(AElement.SourceFilename), AElement.SourceLinenumber]));
  1615. end;
  1616. Procedure THTMLWriter.AppendSeeAlsoSection(AElement : TPasElement;DocNode : TDocNode);
  1617. var
  1618. Node: TDOMNode;
  1619. TableEl, El, TREl, TDEl, ParaEl, NewEl, DescrEl: TDOMElement;
  1620. l,s: String;
  1621. f: Text;
  1622. IsFirstSeeAlso : Boolean;
  1623. begin
  1624. if Not (Assigned(DocNode) and Assigned(DocNode.SeeAlso)) then
  1625. Exit;
  1626. IsFirstSeeAlso := True;
  1627. Node:=DocNode.SeeAlso.FirstChild;
  1628. While Assigned(Node) do
  1629. begin
  1630. if (Node.NodeType=ELEMENT_NODE) and (Node.NodeName='link') then
  1631. begin
  1632. if IsFirstSeeAlso then
  1633. begin
  1634. IsFirstSeeAlso := False;
  1635. AppendText(CreateH2(BodyElement), SDocSeeAlso);
  1636. TableEl := CreateTable(BodyElement);
  1637. end;
  1638. El:=TDOMElement(Node);
  1639. TREl:=CreateTR(TableEl);
  1640. ParaEl:=CreatePara(CreateTD_vtop(TREl));
  1641. l:=El['id'];
  1642. s:= ResolveLinkID(l);
  1643. if Length(s)=0 then
  1644. begin
  1645. WriteLn(Format(SErrUnknownLinkID, [l]));
  1646. NewEl := CreateEl(ParaEl,'b')
  1647. end
  1648. else
  1649. NewEl := CreateLink(ParaEl,s);
  1650. if Not IsDescrNodeEmpty(El) then
  1651. begin
  1652. PushOutputNode(NewEl);
  1653. Try
  1654. ConvertBaseShortList(AElement, El, True)
  1655. Finally
  1656. PopOutputNode;
  1657. end;
  1658. end
  1659. else
  1660. AppendText(NewEl,El['id']);
  1661. l:=El['id'];
  1662. DescrEl := Engine.FindShortDescr(AElement.GetModule,L);
  1663. if Assigned(DescrEl) then
  1664. begin
  1665. AppendNbSp(CreatePara(CreateTD(TREl)), 2);
  1666. ParaEl := CreatePara(CreateTD(TREl));
  1667. ParaEl['class'] := 'cmt';
  1668. PushOutputNode(ParaEl);
  1669. try
  1670. ConvertShort(AElement, DescrEl);
  1671. finally
  1672. PopOutputNode;
  1673. end;
  1674. end;
  1675. end; // Link node
  1676. Node := Node.NextSibling;
  1677. end; // While
  1678. end;
  1679. Procedure THTMLWriter.AppendExampleSection(AElement : TPasElement;DocNode : TDocNode);
  1680. var
  1681. Node: TDOMNode;
  1682. // TableEl, El, TREl, TDEl, ParaEl, NewEl, DescrEl: TDOMElement;
  1683. fn,s: String;
  1684. f: Text;
  1685. begin
  1686. if not (Assigned(DocNode) and Assigned(DocNode.FirstExample)) then
  1687. Exit;
  1688. Node := DocNode.FirstExample;
  1689. while Assigned(Node) do
  1690. begin
  1691. if (Node.NodeType = ELEMENT_NODE) and (Node.NodeName = 'example') then
  1692. begin
  1693. fn:=Engine.GetExampleFilename(TDOMElement(Node));
  1694. If (fn<>'') then
  1695. begin
  1696. AppendText(CreateH2(BodyElement), SDocExample);
  1697. try
  1698. Assign(f, FN);
  1699. Reset(f);
  1700. try
  1701. PushOutputNode(BodyElement);
  1702. DescrBeginCode(False, TDOMElement(Node)['highlighter']);
  1703. while not EOF(f) do
  1704. begin
  1705. ReadLn(f, s);
  1706. DescrWriteCodeLine(s);
  1707. end;
  1708. DescrEndCode;
  1709. PopOutputNode;
  1710. finally
  1711. Close(f);
  1712. end;
  1713. except
  1714. on e: Exception do
  1715. begin
  1716. e.Message := '[example] ' + e.Message;
  1717. raise;
  1718. end;
  1719. end;
  1720. end;
  1721. end;
  1722. Node := Node.NextSibling;
  1723. end;
  1724. end;
  1725. procedure THTMLWriter.AppendFooter;
  1726. begin
  1727. if FooterFile<>'' then
  1728. ReadXMLFragment(BodyElement, FooterFile);
  1729. end;
  1730. procedure THTMLWriter.FinishElementPage(AElement: TPasElement);
  1731. var
  1732. DocNode: TDocNode;
  1733. begin
  1734. DocNode := Engine.FindDocNode(AElement);
  1735. If Assigned(DocNode) then
  1736. begin
  1737. // Description
  1738. if Assigned(DocNode.Descr) then
  1739. AppendDescrSection(AElement, BodyElement, DocNode.Descr, SDocDescription);
  1740. // Append "Errors" section
  1741. if Assigned(DocNode.ErrorsDoc) then
  1742. AppendDescrSection(AElement, BodyElement, DocNode.ErrorsDoc, SDocErrors);
  1743. // Append "See also" section
  1744. AppendSeeAlsoSection(AElement,DocNode);
  1745. // Append examples, if present
  1746. AppendExampleSection(AElement,DocNode);
  1747. end;
  1748. end;
  1749. Procedure THTMLWriter.CreateTopicPageBody(AElement : TTopicElement);
  1750. var
  1751. DocNode: TDocNode;
  1752. TableEl, TREl: TDOMElement;
  1753. I : Integer;
  1754. S : String;
  1755. begin
  1756. AppendTopicMenuBar(AElement);
  1757. DocNode:=AElement.TopicNode;
  1758. if Assigned(DocNode) then // should always be true, but we're being careful.
  1759. begin
  1760. AppendShortDescr(AElement,TitleElement, DocNode);
  1761. AppendShortDescr(AElement,CreateH2(BodyElement), DocNode);
  1762. if Assigned(DocNode.Descr) then
  1763. AppendDescrSection(AElement, BodyElement, DocNode.Descr, '');
  1764. AppendSeeAlsoSection(AElement,DocNode);
  1765. CreateTopicLinks(DocNode,AElement);
  1766. AppendExampleSection(AElement,DocNode);
  1767. end;
  1768. end;
  1769. procedure THTMLWriter.CreatePageBody(AElement: TPasElement;
  1770. ASubpageIndex: Integer);
  1771. var
  1772. i: Integer;
  1773. Element: TPasElement;
  1774. begin
  1775. CurDirectory := Allocator.GetFilename(AElement, ASubpageIndex);
  1776. i := Length(CurDirectory);
  1777. while (i > 0) and not (CurDirectory[i] in DirSeparators) do
  1778. Dec(i);
  1779. CurDirectory := Copy(CurDirectory, 1, i);
  1780. BaseDirectory := Allocator.GetRelativePathToTop(AElement);
  1781. if AElement.ClassType = TPasPackage then
  1782. CreatePackagePageBody
  1783. else
  1784. begin
  1785. Element := AElement;
  1786. while (Element<>Nil) and (Element.ClassType<>TPasModule) do
  1787. Element := Element.Parent;
  1788. Module := TPasModule(Element);
  1789. if AElement.ClassType = TPasModule then
  1790. CreateModulePageBody(TPasModule(AElement), ASubpageIndex)
  1791. else if AElement.Parent.InheritsFrom(TPasClassType) then
  1792. CreateClassMemberPageBody(AElement)
  1793. else if AElement.ClassType = TPasConst then
  1794. CreateConstPageBody(TPasConst(AElement))
  1795. else if AElement.InheritsFrom(TPasClassType) then
  1796. CreateClassPageBody(TPasClassType(AElement), ASubpageIndex)
  1797. else if AElement.InheritsFrom(TPasType) then
  1798. CreateTypePageBody(TPasType(AElement))
  1799. else if AElement.ClassType = TPasVariable then
  1800. CreateVarPageBody(TPasVariable(AElement))
  1801. else if AElement.InheritsFrom(TPasProcedureBase) then
  1802. CreateProcPageBody(TPasProcedure(AElement))
  1803. else if AElement.ClassType = TTopicELement then
  1804. CreateTopicPageBody(TTopicElement(AElement))
  1805. end;
  1806. end;
  1807. procedure THTMLWriter.CreatePackagePageBody;
  1808. var
  1809. DocNode: TDocNode;
  1810. TableEl, TREl: TDOMElement;
  1811. i: Integer;
  1812. ThisModule: TPasModule;
  1813. L : TStringList;
  1814. begin
  1815. AppendMenuBar(0);
  1816. AppendTitle(Format(SDocPackageTitle, [Copy(Package.Name, 2, 256)]));
  1817. AppendShortDescr(CreatePara(BodyElement), Package);
  1818. AppendText(CreateH2(BodyElement), SDocUnits);
  1819. TableEl := CreateTable(BodyElement);
  1820. L:=TStringList.Create;
  1821. Try
  1822. L.Sorted:=True;
  1823. // Sort modules.
  1824. For I:=0 to Package.Modules.Count-1 do
  1825. L.AddObject(TPasModule(Package.Modules[i]).Name,TPasModule(Package.Modules[i]));
  1826. // Now create table.
  1827. for i:=0 to L.Count - 1 do
  1828. begin
  1829. ThisModule := TPasModule(L.Objects[i]);
  1830. TREl := CreateTR(TableEl);
  1831. AppendHyperlink(CreateCode(CreatePara(CreateTD_vtop(TREl))), ThisModule);
  1832. AppendShortDescrCell(TREl, ThisModule);
  1833. end;
  1834. Finally
  1835. L.Free;
  1836. end;
  1837. DocNode := Engine.FindDocNode(Package);
  1838. if Assigned(DocNode) then
  1839. begin
  1840. if Assigned(DocNode.Descr) then
  1841. AppendDescrSection(nil, BodyElement, DocNode.Descr, SDocDescription);
  1842. CreateTopicLinks(DocNode,Package);
  1843. end;
  1844. end;
  1845. Procedure THTMLWriter.CreateTopicLinks(Node : TDocNode; PasElement : TPasElement);
  1846. var
  1847. DocNode: TDocNode;
  1848. TableEl, TREl: TDOMElement;
  1849. First : Boolean;
  1850. ThisTopic: TPasElement;
  1851. begin
  1852. DocNode:=Node.FirstChild;
  1853. First:=True;
  1854. While Assigned(DocNode) do
  1855. begin
  1856. If DocNode.TopicNode then
  1857. begin
  1858. if first then
  1859. begin
  1860. First:=False;
  1861. AppendText(CreateH2(BodyElement), SDocRelatedTopics);
  1862. TableEl := CreateTable(BodyElement);
  1863. end;
  1864. TREl := CreateTR(TableEl);
  1865. ThisTopic:=FindTopicElement(DocNode);
  1866. if Assigned(ThisTopic) then
  1867. AppendHyperlink(CreateCode(CreatePara(CreateTD_vtop(TREl))), ThisTopic);
  1868. AppendShortDescrCell(TREl, ThisTopic);
  1869. end;
  1870. DocNode:=DocNode.NextSibling;
  1871. end;
  1872. end;
  1873. procedure THTMLWriter.CreateModulePageBody(AModule: TPasModule;
  1874. ASubpageIndex: Integer);
  1875. procedure CreateMainPage;
  1876. var
  1877. TableEl, TREl, TDEl, CodeEl: TDOMElement;
  1878. i: Integer;
  1879. UnitRef: TPasType;
  1880. DocNode: TDocNode;
  1881. begin
  1882. AppendMenuBar(0);
  1883. AppendTitle(Format(SDocUnitTitle, [AModule.Name]));
  1884. AppendShortDescr(CreatePara(BodyElement), AModule);
  1885. if AModule.InterfaceSection.UsesList.Count > 0 then
  1886. begin
  1887. TableEl := CreateTable(BodyElement);
  1888. AppendKw(CreateCode(CreatePara(CreateTD(CreateTR(TableEl)))), 'uses');
  1889. for i := 0 to AModule.InterfaceSection.UsesList.Count - 1 do
  1890. begin
  1891. UnitRef := TPasType(AModule.InterfaceSection.UsesList[i]);
  1892. DocNode := Engine.FindDocNode(UnitRef);
  1893. if Assigned(DocNode) and DocNode.IsSkipped then
  1894. continue;
  1895. TREl := CreateTR(TableEl);
  1896. TDEl := CreateTD_vtop(TREl);
  1897. CodeEl := CreateCode(CreatePara(TDEl));
  1898. AppendNbSp(CodeEl, 2);
  1899. AppendHyperlink(CodeEl, UnitRef);
  1900. if i < AModule.InterfaceSection.UsesList.Count - 1 then
  1901. AppendSym(CodeEl, ',')
  1902. else
  1903. AppendSym(CodeEl, ';');
  1904. AppendText(CodeEl, ' '); // Space for descriptions
  1905. AppendShortDescrCell(TREl, UnitRef);
  1906. end;
  1907. end;
  1908. DocNode := Engine.FindDocNode(AModule);
  1909. if Assigned(DocNode) then
  1910. begin
  1911. if Assigned(DocNode.Descr) then
  1912. AppendDescrSection(AModule, BodyElement, DocNode.Descr, SDocOverview);
  1913. CreateTopicLinks(DocNode,AModule);
  1914. end;
  1915. end;
  1916. procedure CreateSimpleSubpage(const ATitle: DOMString; AList: TList);
  1917. var
  1918. TableEl, TREl, TDEl, CodeEl: TDOMElement;
  1919. i, j: Integer;
  1920. Decl: TPasElement;
  1921. SortedList: TList;
  1922. DocNode: TDocNode;
  1923. S : String;
  1924. begin
  1925. AppendMenuBar(ASubpageIndex);
  1926. S:=ATitle;
  1927. AppendTitle(Format(SDocUnitTitle + ': %s', [AModule.Name, S]));
  1928. SortedList := TList.Create;
  1929. try
  1930. for i := 0 to AList.Count - 1 do
  1931. begin
  1932. Decl := TPasElement(AList[i]);
  1933. DocNode := Engine.FindDocNode(Decl);
  1934. if (not Assigned(DocNode)) or (not DocNode.IsSkipped) then
  1935. begin
  1936. j := 0;
  1937. while (j < SortedList.Count) and (CompareText(
  1938. TPasElement(SortedList[j]).PathName, Decl.PathName) < 0) do
  1939. Inc(j);
  1940. SortedList.Insert(j, Decl);
  1941. end;
  1942. end;
  1943. TableEl := CreateTable(BodyElement);
  1944. for i := 0 to SortedList.Count - 1 do
  1945. begin
  1946. Decl := TPasElement(SortedList[i]);
  1947. TREl := CreateTR(TableEl);
  1948. CodeEl := CreateCode(CreatePara(CreateTD_vtop(TREl)));
  1949. AppendHyperlink(CodeEl, Decl);
  1950. AppendShortDescrCell(TREl, Decl);
  1951. end;
  1952. finally
  1953. SortedList.Free;
  1954. end;
  1955. end;
  1956. procedure CreateResStringsPage;
  1957. var
  1958. ParaEl: TDOMElement;
  1959. i, j: Integer;
  1960. Decl: TPasResString;
  1961. DocNode: TDocNode;
  1962. begin
  1963. AppendMenuBar(ResstrSubindex);
  1964. AppendTitle(Format(SDocUnitTitle + ': %s', [AModule.Name, SDocResStrings]));
  1965. for i := 0 to AModule.InterfaceSection.ResStrings.Count - 1 do
  1966. begin
  1967. Decl := TPasResString(AModule.InterfaceSection.ResStrings[i]);
  1968. CreateEl(BodyElement, 'a')['name'] := LowerCase(Decl.Name);
  1969. ParaEl := CreatePara(BodyElement);
  1970. AppendText(CreateCode(ParaEl), Decl.Name);
  1971. CreateEl(ParaEl, 'br');
  1972. AppendText(ParaEl, Decl.Value);
  1973. end;
  1974. end;
  1975. begin
  1976. case ASubpageIndex of
  1977. 0:
  1978. CreateMainPage;
  1979. ResstrSubindex:
  1980. CreateResStringsPage;
  1981. ConstsSubindex:
  1982. CreateSimpleSubpage(SDocConstants, AModule.InterfaceSection.Consts);
  1983. TypesSubindex:
  1984. CreateSimpleSubpage(SDocTypes, AModule.InterfaceSection.Types);
  1985. ClassesSubindex:
  1986. CreateSimpleSubpage(SDocClasses, AModule.InterfaceSection.Classes);
  1987. ProcsSubindex:
  1988. CreateSimpleSubpage(SDocProceduresAndFunctions, AModule.InterfaceSection.Functions);
  1989. VarsSubindex:
  1990. CreateSimpleSubpage(SDocVariables, AModule.InterfaceSection.Variables);
  1991. end;
  1992. end;
  1993. procedure THTMLWriter.CreateConstPageBody(AConst: TPasConst);
  1994. var
  1995. TableEl, CodeEl: TDOMElement;
  1996. begin
  1997. AppendMenuBar(-1);
  1998. AppendTitle(AConst.Name);
  1999. AppendShortDescr(CreatePara(BodyElement), AConst);
  2000. AppendText(CreateH2(BodyElement), SDocDeclaration);
  2001. AppendSourceRef(AConst);
  2002. TableEl := CreateTable(BodyElement);
  2003. CodeEl := CreateCode(CreatePara(CreateTD(CreateTR(TableEl))));
  2004. AppendKw(CodeEl, 'const');
  2005. AppendText(CodeEl, ' ' + AConst.Name);
  2006. if Assigned(AConst.VarType) then
  2007. begin
  2008. AppendSym(CodeEl, ': ');
  2009. AppendType(CodeEl, TableEl, AConst.VarType, False);
  2010. end;
  2011. AppendPasSHFragment(CodeEl, ' = ' + AConst.Value + ';', 0);
  2012. FinishElementPage(AConst);
  2013. end;
  2014. procedure THTMLWriter.CreateTypePageBody(AType: TPasType);
  2015. var
  2016. TableEl, TREl, TDEl, CodeEl: TDOMElement;
  2017. DocNode: TDocNode;
  2018. i: Integer;
  2019. s: String;
  2020. EnumType: TPasEnumType;
  2021. EnumValue: TPasEnumValue;
  2022. Variable: TPasVariable;
  2023. begin
  2024. AppendMenuBar(-1);
  2025. AppendTitle(AType.Name);
  2026. AppendShortDescr(CreatePara(BodyElement), AType);
  2027. AppendText(CreateH2(BodyElement), SDocDeclaration);
  2028. AppendSourceRef(AType);
  2029. TableEl := CreateTable(BodyElement);
  2030. TREl := CreateTR(TableEl);
  2031. TDEl := CreateTD(TREl);
  2032. CodeEl := CreateCode(CreatePara(TDEl));
  2033. DocNode := Engine.FindDocNode(AType);
  2034. AppendKw(CodeEl, 'type ');
  2035. AppendText(CodeEl, AType.Name);
  2036. AppendSym(CodeEl, ' = ');
  2037. If Assigned(DocNode) and
  2038. Assigned(DocNode.Node) and
  2039. (Docnode.Node['opaque']='1') then
  2040. AppendText(CodeEl,SDocOpaque)
  2041. else
  2042. begin
  2043. // Alias
  2044. if AType.ClassType = TPasAliasType then
  2045. begin
  2046. if Assigned(TPasAliasType(AType).DestType) then
  2047. AppendHyperlink(CodeEl, TPasAliasType(AType).DestType)
  2048. else
  2049. AppendText(CreateWarning(CodeEl), '<Destination type is NIL>');
  2050. AppendSym(CodeEl, ';');
  2051. end else
  2052. // Class of
  2053. if AType.ClassType = TPasClassOfType then
  2054. begin
  2055. AppendKw(CodeEl, 'class of ');
  2056. AppendHyperlink(CodeEl, TPasClassOfType(AType).DestType);
  2057. AppendSym(CodeEl, ';');
  2058. end else
  2059. // Enumeration
  2060. if AType.ClassType = TPasEnumType then
  2061. begin
  2062. AppendSym(CodeEl, '(');
  2063. for i := 0 to TPasEnumType(AType).Values.Count - 1 do
  2064. begin
  2065. EnumValue := TPasEnumValue(TPasEnumType(AType).Values[i]);
  2066. TREl := CreateTR(TableEl);
  2067. CodeEl := CreateCode(CreatePara(CreateTD_vtop(TREl)));
  2068. AppendShortDescrCell(TREl, EnumValue);
  2069. AppendNbSp(CodeEl, 2);
  2070. s := EnumValue.Name;
  2071. if EnumValue.IsValueUsed then
  2072. s := s + ' = ' + IntToStr(EnumValue.Value);
  2073. if i < TPasEnumType(AType).Values.Count - 1 then
  2074. s := s + ',';
  2075. AppendPasSHFragment(CodeEl, s, 0);
  2076. end;
  2077. AppendSym(CreateCode(CreatePara(CreateTD(CreateTR(TableEl)))), ');');
  2078. end else
  2079. // Pointer type
  2080. if AType.ClassType = TPasPointerType then
  2081. begin
  2082. AppendSym(CodeEl, '^');
  2083. if Assigned(TPasPointerType(AType).DestType) then
  2084. AppendHyperlink(CodeEl, TPasPointerType(AType).DestType)
  2085. else
  2086. AppendText(CreateWarning(CodeEl), '<Destination type is NIL>');
  2087. AppendSym(CodeEl, ';');
  2088. end else
  2089. if AType.InheritsFrom(TPasProcedureType) then
  2090. begin
  2091. AppendSym(AppendType(CodeEl, TableEl, TPasType(AType), True), ';');
  2092. AppendProcArgsSection(BodyElement, TPasProcedureType(AType));
  2093. end else
  2094. // Record
  2095. if AType.ClassType = TPasRecordType then
  2096. begin
  2097. CodeEl := AppendRecordType(CodeEl, TableEl, TPasRecordType(AType), 0);
  2098. AppendSym(CodeEl, ';');
  2099. end else
  2100. // Set
  2101. if AType.ClassType = TPasSetType then
  2102. begin
  2103. AppendKw(CodeEl, 'set of ');
  2104. if TPasSetType(AType).EnumType.ClassType = TPasEnumType then
  2105. begin
  2106. AppendSym(CodeEl, '(');
  2107. EnumType := TPasEnumType(TPasSetType(AType).EnumType);
  2108. for i := 0 to EnumType.Values.Count - 1 do
  2109. begin
  2110. EnumValue := TPasEnumValue(EnumType.Values[i]);
  2111. TREl := CreateTR(TableEl);
  2112. CodeEl := CreateCode(CreatePara(CreateTD_vtop(TREl)));
  2113. AppendShortDescrCell(TREl, EnumValue);
  2114. AppendNbSp(CodeEl, 2);
  2115. s := EnumValue.Name;
  2116. if EnumValue.IsValueUsed then
  2117. s := s + ' = ' + IntToStr(EnumValue.Value);
  2118. if i < EnumType.Values.Count - 1 then
  2119. s := s + ',';
  2120. AppendPasSHFragment(CodeEl, s, 0);
  2121. end;
  2122. AppendSym(CreateCode(CreatePara(CreateTD(CreateTR(TableEl)))), ');');
  2123. end else
  2124. begin
  2125. AppendHyperlink(CodeEl, TPasSetType(AType).EnumType);
  2126. AppendSym(CodeEl, ';');
  2127. end;
  2128. end else
  2129. // Type alias
  2130. if AType.ClassType = TPasTypeAliasType then
  2131. begin
  2132. AppendKw(CodeEl, 'type ');
  2133. AppendHyperlink(CodeEl, TPasTypeAliasType(AType).DestType);
  2134. AppendSym(CodeEl, ';');
  2135. end else
  2136. // Probably one of the simple types, which allowed in other places as wel...
  2137. AppendSym(AppendType(CodeEl, TableEl, TPasType(AType), True), ';');
  2138. end;
  2139. FinishElementPage(AType);
  2140. end;
  2141. function PropertyFilter(AMember: TPasElement): Boolean;
  2142. begin
  2143. Result := (AMember.ClassType = TPasProperty) and
  2144. (Copy(AMember.Name, 1, 2) <> 'On');
  2145. end;
  2146. function MethodFilter(AMember: TPasElement): Boolean;
  2147. begin
  2148. Result := AMember.InheritsFrom(TPasProcedureBase);
  2149. end;
  2150. function EventFilter(AMember: TPasElement): Boolean;
  2151. begin
  2152. Result := (AMember.ClassType = TPasProperty) and
  2153. (Copy(AMember.Name, 1, 2) = 'On');
  2154. end;
  2155. procedure THTMLWriter.CreateClassPageBody(AClass: TPasClassType;
  2156. ASubpageIndex: Integer);
  2157. type
  2158. TMemberFilter = function(AMember: TPasElement): Boolean;
  2159. var
  2160. ParaEl: TDOMElement;
  2161. procedure AppendMemberListLink(AListSubpageIndex: Integer;
  2162. const AText: DOMString);
  2163. var
  2164. LinkEl: TDOMElement;
  2165. begin
  2166. AppendText(ParaEl, '[');
  2167. LinkEl := CreateEl(ParaEl, 'a');
  2168. LinkEl['href'] :=
  2169. FixHtmlPath(ResolveLinkWithinPackage(AClass, AListSubpageIndex));
  2170. LinkEl['onClick'] := 'window.open(''' + LinkEl['href'] + ''', ''list'', ' +
  2171. '''dependent=yes,resizable=yes,scrollbars=yes,height=400,width=300''); return false;';
  2172. AppendText(LinkEl, AText);
  2173. AppendText(ParaEl, ' (');
  2174. LinkEl := CreateEl(ParaEl, 'a');
  2175. LinkEl['href'] :=
  2176. FixHtmlPath(ResolveLinkWithinPackage(AClass, AListSubpageIndex + 1));
  2177. LinkEl['onClick'] := 'window.open(''' + LinkEl['href'] + ''', ''list'', ' +
  2178. '''dependent=yes,resizable=yes,scrollbars=yes,height=400,width=300''); return false;';
  2179. AppendText(LinkEl, SDocByName);
  2180. AppendText(ParaEl, ')');
  2181. AppendText(ParaEl, '] ');
  2182. end;
  2183. procedure CreateMainPage;
  2184. var
  2185. TableEl, TREl, TDEl, CodeEl: TDOMElement;
  2186. DocNode: TDocNode;
  2187. Member: TPasElement;
  2188. CurVisibility: TPasMemberVisibility;
  2189. i: Integer;
  2190. s: String;
  2191. ThisClass: TPasClassType;
  2192. HaveSeenTObject: Boolean;
  2193. begin
  2194. AppendMenuBar(-1);
  2195. AppendTitle(AClass.Name);
  2196. ParaEl := CreatePara(BodyElement);
  2197. AppendMemberListLink(PropertiesByInheritanceSubindex, SDocProperties);
  2198. AppendMemberListLink(MethodsByInheritanceSubindex, SDocMethods);
  2199. AppendMemberListLink(EventsByInheritanceSubindex, SDocEvents);
  2200. AppendShortDescr(CreatePara(BodyElement), AClass);
  2201. AppendText(CreateH2(BodyElement), SDocDeclaration);
  2202. AppendSourceRef(AClass);
  2203. TableEl := CreateTable(BodyElement);
  2204. TREl := CreateTR(TableEl);
  2205. TDEl := CreateTD(TREl);
  2206. CodeEl := CreateCode(CreatePara(TDEl));
  2207. AppendKw(CodeEl, 'type');
  2208. AppendText(CodeEl, ' ' + AClass.Name + ' ');
  2209. AppendSym(CodeEl, '=');
  2210. AppendText(CodeEl, ' ');
  2211. AppendKw(CodeEl, ObjKindNames[AClass.ObjKind]);
  2212. if Assigned(AClass.AncestorType) then
  2213. begin
  2214. AppendSym(CodeEl, '(');
  2215. AppendHyperlink(CodeEl, AClass.AncestorType);
  2216. AppendSym(CodeEl, ')');
  2217. end;
  2218. if AClass.Members.Count > 0 then
  2219. begin
  2220. CurVisibility := visDefault;
  2221. for i := 0 to AClass.Members.Count - 1 do
  2222. begin
  2223. Member := TPasElement(AClass.Members[i]);
  2224. if CurVisibility <> Member.Visibility then
  2225. begin
  2226. CurVisibility := Member.Visibility;
  2227. if ((CurVisibility = visPrivate) and Engine.HidePrivate) or
  2228. ((CurVisibility = visProtected) and Engine.HideProtected) then
  2229. continue;
  2230. case CurVisibility of
  2231. visPrivate: s := 'private';
  2232. visProtected: s := 'protected';
  2233. visPublic: s := 'public';
  2234. visPublished: s := 'published';
  2235. visAutomated: s := 'automated';
  2236. end;
  2237. AppendKw(CreateCode(CreatePara(CreateTD(CreateTR(TableEl)))), s);
  2238. end else
  2239. if ((CurVisibility = visPrivate) and Engine.HidePrivate) or
  2240. ((CurVisibility = visProtected) and Engine.HideProtected) then
  2241. continue;
  2242. TREl := CreateTR(TableEl);
  2243. CodeEl := CreateCode(CreatePara(CreateTD_vtop(TREl)));
  2244. AppendNbSp(CodeEl, 2);
  2245. AppendShortDescrCell(TREl, Member);
  2246. if Member.InheritsFrom(TPasProcedureBase) then
  2247. begin
  2248. AppendKw(CodeEl, TPasProcedureBase(Member).TypeName + ' ');
  2249. AppendHyperlink(CodeEl, Member);
  2250. if (Member.ClassType = TPasOverloadedProc) or
  2251. (TPasProcedure(Member).ProcType.Args.Count > 0) then
  2252. AppendSym(CodeEl, '();')
  2253. else
  2254. AppendSym(CodeEl, ';');
  2255. if Member.ClassType <> TPasOverloadedProc then
  2256. AppendProcExt(CodeEl, TPasProcedure(Member));
  2257. end else
  2258. if Member.ClassType = TPasVariable then
  2259. begin
  2260. AppendHyperlink(CodeEl, Member);
  2261. AppendSym(CodeEl, ': ');
  2262. AppendHyperlink(CodeEl, TPasVariable(Member).VarType);
  2263. AppendSym(CodeEl, ';');
  2264. end else
  2265. if Member.ClassType = TPasProperty then
  2266. begin
  2267. AppendKw(CodeEl, 'property ');
  2268. AppendHyperlink(CodeEl, Member);
  2269. if Assigned(TPasProperty(Member).VarType) then
  2270. begin
  2271. AppendSym(CodeEl, ': ');
  2272. AppendHyperlink(CodeEl, TPasProperty(Member).VarType);
  2273. end;
  2274. AppendSym(CodeEl, ';');
  2275. if TPasProperty(Member).IsDefault then
  2276. begin
  2277. AppendKw(CodeEl, ' default');
  2278. AppendSym(CodeEl, ';');
  2279. end;
  2280. SetLength(s, 0);
  2281. if Length(TPasProperty(Member).ReadAccessorName) > 0 then
  2282. s := s + 'r';
  2283. if Length(TPasProperty(Member).WriteAccessorName) > 0 then
  2284. s := s + 'w';
  2285. if Length(TPasProperty(Member).StoredAccessorName) > 0 then
  2286. s := s + 's';
  2287. if Length(s) > 0 then
  2288. AppendText(CodeEl, ' [' + s + ']');
  2289. end else
  2290. AppendText(CreateWarning(CodeEl), '<' + Member.ClassName + '>');
  2291. end;
  2292. CodeEl := CreateCode(CreatePara(CreateTD(CreateTR(TableEl))));
  2293. end;
  2294. AppendText(CodeEl, ' '); // !!!: Dirty trick, necessary for current XML writer
  2295. AppendKw(CodeEl, 'end');
  2296. AppendSym(CodeEl, ';');
  2297. AppendText(CreateH2(BodyElement), SDocInheritance);
  2298. TableEl := CreateTable(BodyElement);
  2299. HaveSeenTObject := AClass.ObjKind <> okClass;
  2300. ThisClass := AClass;
  2301. while True do
  2302. begin
  2303. TREl := CreateTR(TableEl);
  2304. TDEl := CreateTD_vtop(TREl);
  2305. TDEl['align'] := 'center';
  2306. CodeEl := CreateCode(CreatePara(TDEl));
  2307. AppendHyperlink(CodeEl, ThisClass);
  2308. AppendShortDescrCell(TREl, ThisClass);
  2309. if HaveSeenTObject or (CompareText(ThisClass.Name, 'TObject') = 0) then
  2310. HaveSeenTObject := True
  2311. else
  2312. begin
  2313. TDEl := CreateTD(CreateTR(TableEl));
  2314. TDEl['align'] := 'center';
  2315. AppendText(TDEl, '|');
  2316. end;
  2317. if Assigned(ThisClass.AncestorType) then
  2318. begin
  2319. if ThisClass.AncestorType.InheritsFrom(TPasClassType) then
  2320. ThisClass := TPasClassType(ThisClass.AncestorType)
  2321. else
  2322. begin
  2323. TDEl := CreateTD(CreateTR(TableEl));
  2324. TDEl['align'] := 'center';
  2325. AppendText(CreateCode(CreatePara(TDEl)), ThisClass.AncestorType.Name);
  2326. if CompareText(ThisClass.AncestorType.Name, 'TObject') = 0 then
  2327. HaveSeenTObject := True
  2328. else
  2329. begin
  2330. TDEl := CreateTD(CreateTR(TableEl));
  2331. TDEl['align'] := 'center';
  2332. AppendText(TDEl, '?');
  2333. end;
  2334. break;
  2335. end
  2336. end else
  2337. break;
  2338. end;
  2339. if not HaveSeenTObject then
  2340. begin
  2341. TDEl := CreateTD(CreateTR(TableEl));
  2342. TDEl['align'] := 'center';
  2343. AppendText(CreateCode(CreatePara(TDEl)), 'TObject');
  2344. end;
  2345. FinishElementPage(AClass);
  2346. end;
  2347. procedure CreateInheritanceSubpage(AFilter: TMemberFilter);
  2348. var
  2349. ThisClass: TPasClassType;
  2350. i: Integer;
  2351. Member: TPasElement;
  2352. TableEl, TREl, TDEl, ParaEl, LinkEl: TDOMElement;
  2353. begin
  2354. TableEl := CreateTable(BodyElement);
  2355. ThisClass := AClass;
  2356. while True do
  2357. begin
  2358. TREl := CreateTR(TableEl);
  2359. TDEl := CreateTD(TREl);
  2360. TDEl['colspan'] := '3';
  2361. CreateTD(TREl);
  2362. LinkEl := AppendHyperlink(CreateEl(CreateCode(CreatePara(TDEl)), 'b'), ThisClass);
  2363. if Assigned(LinkEl) then
  2364. LinkEl['onClick'] := 'opener.location.href = ''' + LinkEl['href'] +
  2365. '''; return false;';
  2366. for i := 0 to ThisClass.Members.Count - 1 do
  2367. begin
  2368. Member := TPasElement(ThisClass.Members[i]);
  2369. if ((Member.Visibility = visPrivate) and Engine.HidePrivate) or
  2370. ((Member.Visibility = visProtected) and Engine.HideProtected) or
  2371. not AFilter(Member) then
  2372. continue;
  2373. TREl := CreateTR(TableEl);
  2374. ParaEl := CreatePara(CreateTD(TREl));
  2375. case Member.Visibility of
  2376. visPrivate:
  2377. AppendText(ParaEl, 'pv');
  2378. visProtected:
  2379. AppendText(ParaEl, 'pt');
  2380. visPublished:
  2381. AppendText(ParaEl, 'pl');
  2382. end;
  2383. AppendNbSp(ParaEl, 1);
  2384. ParaEl := CreateTD(TREl);
  2385. if (Member.ClassType = TPasProperty) and
  2386. (Length(TPasProperty(Member).WriteAccessorName) = 0) then
  2387. begin
  2388. AppendText(ParaEl, 'ro');
  2389. AppendNbSp(ParaEl, 1);
  2390. end;
  2391. LinkEl := AppendHyperlink(CreatePara(CreateTD(TREl)), Member);
  2392. if Assigned(LinkEl) then
  2393. LinkEl['onClick'] := 'opener.location.href = ''' + LinkEl['href'] +
  2394. '''; return false;';
  2395. end;
  2396. if (not Assigned(ThisClass.AncestorType)) or
  2397. (not (ThisClass.AncestorType.ClassType = TPasClassType)) then
  2398. break;
  2399. ThisClass := TPasClassType(ThisClass.AncestorType);
  2400. AppendNbSp(CreatePara(CreateTD(CreateTR(TableEl))), 1);
  2401. end;
  2402. end;
  2403. procedure CreateSortedSubpage(AFilter: TMemberFilter);
  2404. var
  2405. List: TList;
  2406. ThisClass: TPasClassType;
  2407. i, j: Integer;
  2408. Member: TPasElement;
  2409. TableEl, TREl, TDEl, ParaEl, LinkEl: TDOMElement;
  2410. begin
  2411. List := TList.Create;
  2412. try
  2413. ThisClass := AClass;
  2414. while True do
  2415. begin
  2416. for i := 0 to ThisClass.Members.Count - 1 do
  2417. begin
  2418. Member := TPasElement(ThisClass.Members[i]);
  2419. if (not (((Member.Visibility = visPrivate) and Engine.HidePrivate) or
  2420. ((Member.Visibility = visProtected) and Engine.HideProtected))) and
  2421. AFilter(Member) then
  2422. begin
  2423. j := 0;
  2424. while (j < List.Count) and
  2425. (CompareText(TPasElement(List[j]).Name, Member.Name) < 0) do
  2426. Inc(j);
  2427. List.Insert(j, Member);
  2428. end;
  2429. end;
  2430. if (not Assigned(ThisClass.AncestorType)) or
  2431. (not (ThisClass.AncestorType.ClassType = TPasClassType)) then
  2432. break;
  2433. ThisClass := TPasClassType(ThisClass.AncestorType);
  2434. end;
  2435. TableEl := CreateTable(BodyElement);
  2436. for i := 0 to List.Count - 1 do
  2437. begin
  2438. Member := TPasElement(List[i]);
  2439. TREl := CreateTR(TableEl);
  2440. ParaEl := CreatePara(CreateTD(TREl));
  2441. case Member.Visibility of
  2442. visPrivate:
  2443. AppendText(ParaEl, 'pv');
  2444. visProtected:
  2445. AppendText(ParaEl, 'pt');
  2446. visPublished:
  2447. AppendText(ParaEl, 'pl');
  2448. end;
  2449. AppendNbSp(ParaEl, 1);
  2450. ParaEl := CreatePara(CreateTD(TREl));
  2451. if (Member.ClassType = TPasProperty) and
  2452. (Length(TPasProperty(Member).WriteAccessorName) = 0) then
  2453. begin
  2454. AppendText(ParaEl, 'ro');
  2455. AppendNbSp(ParaEl, 1);
  2456. end;
  2457. TDEl := CreateTD(TREl);
  2458. TDEl['nowrap'] := 'nowrap';
  2459. ParaEl := CreatePara(TDEl);
  2460. LinkEl := AppendHyperlink(ParaEl, Member);
  2461. if Assigned(LinkEl) then
  2462. LinkEl['onClick'] := 'opener.location.href = ''' + LinkEl['href'] +
  2463. '''; return false;';
  2464. AppendText(ParaEl, ' (');
  2465. LinkEl := AppendHyperlink(ParaEl, Member.Parent);
  2466. if Assigned(LinkEl) then
  2467. LinkEl['onClick'] := 'opener.location.href = ''' + LinkEl['href'] +
  2468. '''; return false;';
  2469. AppendText(ParaEl, ')');
  2470. end;
  2471. finally
  2472. List.Free;
  2473. end;
  2474. end;
  2475. begin
  2476. case ASubpageIndex of
  2477. 0:
  2478. CreateMainPage;
  2479. PropertiesByInheritanceSubindex:
  2480. CreateInheritanceSubpage(@PropertyFilter);
  2481. PropertiesByNameSubindex:
  2482. CreateSortedSubpage(@PropertyFilter);
  2483. MethodsByInheritanceSubindex:
  2484. CreateInheritanceSubpage(@MethodFilter);
  2485. MethodsByNameSubindex:
  2486. CreateSortedSubpage(@MethodFilter);
  2487. EventsByInheritanceSubindex:
  2488. CreateInheritanceSubpage(@EventFilter);
  2489. EventsByNameSubindex:
  2490. CreateSortedSubpage(@EventFilter);
  2491. end;
  2492. end;
  2493. procedure THTMLWriter.CreateClassMemberPageBody(AElement: TPasElement);
  2494. var
  2495. TableEl, TREl, CodeEl: TDOMElement;
  2496. procedure CreateVarPage(Element: TPasVariable);
  2497. begin
  2498. AppendHyperlink(CodeEl, Element.Parent);
  2499. AppendSym(CodeEl, '.');
  2500. AppendText(CodeEl, Element.Name);
  2501. if Assigned(Element.VarType) then
  2502. begin
  2503. AppendSym(CodeEl, ': ');
  2504. AppendSym(AppendType(CodeEl, TableEl, Element.VarType, False), ';');
  2505. end;
  2506. end;
  2507. procedure CreatePropertyPage(Element: TPasProperty);
  2508. var
  2509. NeedBreak: Boolean;
  2510. begin
  2511. AppendKw(CodeEl, 'property ');
  2512. AppendHyperlink(CodeEl, Element.Parent);
  2513. AppendSym(CodeEl, '.');
  2514. AppendText(CodeEl, Element.Name);
  2515. if Assigned(Element.VarType) then
  2516. begin
  2517. AppendSym(CodeEl, ': ');
  2518. AppendType(CodeEl, TableEl, Element.VarType, False);
  2519. end;
  2520. NeedBreak := False;
  2521. if Length(TPasProperty(Element).IndexValue) <> 0 then
  2522. begin
  2523. CreateEl(CodeEl, 'br');
  2524. AppendNbsp(CodeEl, 2);
  2525. AppendKw(CodeEl, 'index ');
  2526. AppendPasSHFragment(CodeEl, TPasProperty(Element).IndexValue, 0);
  2527. NeedBreak := True;
  2528. end;
  2529. if Length(TPasProperty(Element).ReadAccessorName) <> 0 then
  2530. begin
  2531. CreateEl(CodeEl, 'br');
  2532. AppendNbsp(CodeEl, 2);
  2533. AppendKw(CodeEl, 'read ');
  2534. AppendText(CodeEl, TPasProperty(Element).ReadAccessorName);
  2535. NeedBreak := True;
  2536. end;
  2537. if Length(TPasProperty(Element).WriteAccessorName) <> 0 then
  2538. begin
  2539. CreateEl(CodeEl, 'br');
  2540. AppendNbsp(CodeEl, 2);
  2541. AppendKw(CodeEl, 'write ');
  2542. AppendText(CodeEl, TPasProperty(Element).WriteAccessorName);
  2543. NeedBreak := True;
  2544. end;
  2545. if Length(TPasProperty(Element).StoredAccessorName) <> 0 then
  2546. begin
  2547. CreateEl(CodeEl, 'br');
  2548. AppendNbsp(CodeEl, 2);
  2549. AppendKw(CodeEl, 'stored ');
  2550. AppendText(CodeEl, TPasProperty(Element).StoredAccessorName);
  2551. NeedBreak := True;
  2552. end;
  2553. if Length(TPasProperty(Element).DefaultValue) <> 0 then
  2554. begin
  2555. CreateEl(CodeEl, 'br');
  2556. AppendNbsp(CodeEl, 2);
  2557. AppendKw(CodeEl, 'default ');
  2558. AppendPasSHFragment(CodeEl, TPasProperty(Element).DefaultValue, 0);
  2559. NeedBreak := True;
  2560. end;
  2561. AppendSym(CodeEl, ';');
  2562. if TPasProperty(Element).IsDefault or TPasProperty(Element).IsNodefault then
  2563. begin
  2564. if NeedBreak then
  2565. begin
  2566. CreateEl(CodeEl, 'br');
  2567. AppendNbsp(CodeEl, 2);
  2568. end;
  2569. if TPasProperty(Element).IsDefault then
  2570. AppendKw(CodeEl, 'default')
  2571. else
  2572. AppendKw(CodeEl, 'nodefault');
  2573. AppendSym(CodeEl, ';');
  2574. end;
  2575. end;
  2576. var
  2577. s: String;
  2578. DocNode: TDocNode;
  2579. begin
  2580. AppendMenuBar(-1);
  2581. AppendTitle(AElement.FullName);
  2582. AppendShortDescr(CreatePara(BodyElement), AElement);
  2583. AppendText(CreateH2(BodyElement), SDocDeclaration);
  2584. AppendSourceRef(AElement);
  2585. TableEl := CreateTable(BodyElement);
  2586. TREl := CreateTR(TableEl);
  2587. CodeEl := CreateCode(CreatePara(CreateTD(TREl)));
  2588. AppendText(CodeEl, ' '); // !!!: Workaround for current HTML writer
  2589. case AElement.Visibility of
  2590. visPrivate: s := 'private';
  2591. visProtected: s := 'protected';
  2592. visPublic: s := 'public';
  2593. visPublished: s := 'published';
  2594. visAutomated: s := 'automated';
  2595. else s := '';
  2596. end;
  2597. if Length(s) > 0 then
  2598. AppendKw(CodeEl, s);
  2599. AppendText(CodeEl, ' ');
  2600. if AElement.ClassType = TPasVariable then
  2601. CreateVarPage(TPasVariable(AElement))
  2602. else if AElement.InheritsFrom(TPasProcedureBase) then
  2603. AppendProcDecl(CodeEl, TableEl, TPasProcedureBase(AElement))
  2604. else if AElement.ClassType = TPasProperty then
  2605. CreatePropertyPage(TPasProperty(AElement))
  2606. else
  2607. AppendText(CreateWarning(BodyElement), '<' + AElement.ClassName + '>');
  2608. FinishElementPage(AElement);
  2609. end;
  2610. procedure THTMLWriter.CreateVarPageBody(AVar: TPasVariable);
  2611. var
  2612. TableEl, TREl, TDEl, CodeEl, El: TDOMElement;
  2613. DocNode: TDocNode;
  2614. begin
  2615. AppendMenuBar(-1);
  2616. AppendTitle(AVar.FullName);
  2617. AppendShortDescr(CreatePara(BodyElement), AVar);
  2618. AppendText(CreateH2(BodyElement), SDocDeclaration);
  2619. AppendSourceRef(AVar);
  2620. TableEl := CreateTable(BodyElement);
  2621. TREl := CreateTR(TableEl);
  2622. TDEl := CreateTD(TREl);
  2623. CodeEl := CreateCode(CreatePara(TDEl));
  2624. AppendKw(CodeEl, 'var');
  2625. AppendText(CodeEl, ' ' + AVar.Name);
  2626. if Assigned(AVar.VarType) then
  2627. begin
  2628. AppendSym(CodeEl, ': ');
  2629. El := AppendType(CodeEl, TableEl, AVar.VarType, False);
  2630. end else
  2631. El := CodeEl;
  2632. if Length(AVar.Value) > 0 then
  2633. AppendPasSHFragment(El, ' = ' + AVar.Value + ';', 0)
  2634. else
  2635. AppendSym(El, ';');
  2636. FinishElementPage(AVar);
  2637. end;
  2638. procedure THTMLWriter.CreateProcPageBody(AProc: TPasProcedureBase);
  2639. var
  2640. TableEl, TREl, TDEl, CodeEl: TDOMElement;
  2641. begin
  2642. AppendMenuBar(-1);
  2643. AppendTitle(AProc.Name);
  2644. AppendShortDescr(CreatePara(BodyElement), AProc);
  2645. AppendText(CreateH2(BodyElement), SDocDeclaration);
  2646. AppendSourceRef(AProc);
  2647. TableEl := CreateTable(BodyElement);
  2648. TREl := CreateTR(TableEl);
  2649. TDEl := CreateTD(TREl);
  2650. CodeEl := CreateCode(CreatePara(TDEl));
  2651. AppendProcDecl(CodeEl, TableEl, AProc);
  2652. FinishElementPage(AProc);
  2653. end;
  2654. Function THTMLWriter.InterPretOption(Const Cmd,Arg : String) : boolean;
  2655. begin
  2656. Result:=True;
  2657. if Cmd = '--html-search' then
  2658. SearchPage := Arg
  2659. else if Cmd = '--footer' then
  2660. FooterFile := Arg
  2661. else
  2662. Result:=False;
  2663. end;
  2664. procedure THTMLWriter.WriteDoc;
  2665. begin
  2666. WriteLn(Format(SWritingPages, [PageCount]));
  2667. WriteHTMLPages;
  2668. end;
  2669. class procedure THTMLWriter.Usage(List: TStrings);
  2670. begin
  2671. List.add('--footer');
  2672. List.Add(SHTMLUsageFooter);
  2673. end;
  2674. // private methods
  2675. function THTMLWriter.GetPageCount: Integer;
  2676. begin
  2677. Result := PageInfos.Count;
  2678. end;
  2679. procedure THTMLWriter.SetOnTest(const AValue: TNotifyEvent);
  2680. begin
  2681. if FOnTest=AValue then exit;
  2682. FOnTest:=AValue;
  2683. end;
  2684. procedure THTMLWriter.CreateAllocator;
  2685. begin
  2686. FAllocator:=TLongNameFileAllocator.Create('.html');
  2687. end;
  2688. procedure THTMWriter.CreateAllocator;
  2689. begin
  2690. FAllocator:=TShortNameFileAllocator.Create('.htm');
  2691. end;
  2692. initialization
  2693. // Do not localize.
  2694. RegisterWriter(THTMLWriter,'html','HTML output using fpdoc.css stylesheet.');
  2695. RegisterWriter(THTMWriter,'htm','HTM (8.3 filenames) output using fpdoc.css stylesheet.');
  2696. RegisterWriter(TCHMHTMLWriter,'chm','Compressed HTML file output using fpdoc.css stylesheet.');
  2697. finalization
  2698. UnRegisterWriter('html');
  2699. UnRegisterWriter('htm');
  2700. UnRegisterWriter('chm');
  2701. end.