dw_html.pp 85 KB

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