dw_html.pp 85 KB

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