dw_html.pp 85 KB

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