dw_html.pp 99 KB

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