whtml.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit WHTML;
  12. {$I globdir.inc}
  13. interface
  14. uses Objects;
  15. type
  16. PTextFile = ^TTextFile;
  17. TTextFile = object(TObject)
  18. function GetLine(Idx: sw_integer; var S: string): boolean; virtual;
  19. end;
  20. PMemoryTextFile = ^TMemoryTextFile;
  21. TMemoryTextFile = object(TTextFile)
  22. constructor Init;
  23. procedure AddLine(const S: string); virtual;
  24. function GetLine(Idx: sw_integer; var S: string): boolean; virtual;
  25. destructor Done; virtual;
  26. private
  27. Lines : PUnsortedStrCollection;
  28. end;
  29. PDOSTextFile = ^TDOSTextFile;
  30. TDOSTextFile = object(TMemoryTextFile)
  31. constructor Init(AFileName: string);
  32. end;
  33. PSGMLParser = ^TSGMLParser;
  34. TSGMLParser = object(TObject)
  35. constructor Init;
  36. function Process(HTMLFile: PTextFile): boolean; virtual;
  37. function ProcessLine(LineText: string): boolean; virtual;
  38. destructor Done; virtual;
  39. public
  40. Line,LinePos: sw_integer;
  41. procedure DocSoftBreak; virtual;
  42. function DocAddTextChar(C: char): boolean; virtual;
  43. procedure DocAddText(S: string); virtual;
  44. procedure DocProcessTag(Tag: string); virtual;
  45. procedure DocProcessComment(Comment: string); virtual;
  46. function DocDecodeNamedEntity(Name: string; var Entity: string): boolean; virtual;
  47. private
  48. CurTag: string;
  49. InTag,InComment,InString: boolean;
  50. end;
  51. PHTMLParser = ^THTMLParser;
  52. THTMLParser = object(TSGMLParser)
  53. procedure DocSoftBreak; virtual;
  54. function DocAddTextChar(C: char): boolean; virtual;
  55. procedure DocProcessTag(Tag: string); virtual;
  56. function DocGetTagParam(Name: string; var Value: string): boolean; virtual;
  57. procedure DocProcessComment(Comment: string); virtual;
  58. function DocDecodeNamedEntity(Name: string; var E: string): boolean; virtual;
  59. public
  60. TagName,TagParams: string;
  61. procedure DocUnknownTag; virtual;
  62. procedure DocTYPE; virtual;
  63. procedure DocHTML(Entered: boolean); virtual;
  64. procedure DocHEAD(Entered: boolean); virtual;
  65. procedure DocMETA; virtual;
  66. procedure DocTITLE(Entered: boolean); virtual;
  67. procedure DocBODY(Entered: boolean); virtual;
  68. procedure DocAnchor(Entered: boolean); virtual;
  69. procedure DocHeading(Level: integer; Entered: boolean); virtual;
  70. procedure DocParagraph(Entered: boolean); virtual;
  71. procedure DocBreak; virtual;
  72. procedure DocImage; virtual;
  73. procedure DocBold(Entered: boolean); virtual;
  74. procedure DocCite(Entered: boolean); virtual;
  75. procedure DocCode(Entered: boolean); virtual;
  76. procedure DocEmphasized(Entered: boolean); virtual;
  77. procedure DocItalic(Entered: boolean); virtual;
  78. procedure DocKbd(Entered: boolean); virtual;
  79. procedure DocPreformatted(Entered: boolean); virtual;
  80. procedure DocSample(Entered: boolean); virtual;
  81. procedure DocStrong(Entered: boolean); virtual;
  82. procedure DocTeleType(Entered: boolean); virtual;
  83. procedure DocVariable(Entered: boolean); virtual;
  84. procedure DocList(Entered: boolean); virtual;
  85. procedure DocOrderedList(Entered: boolean); virtual;
  86. procedure DocListItem; virtual;
  87. procedure DocDefList(Entered: boolean); virtual;
  88. procedure DocDefTerm; virtual;
  89. procedure DocDefExp; virtual;
  90. procedure DocTable(Entered: boolean); virtual;
  91. procedure DocTableRow(Entered: boolean); virtual;
  92. procedure DocTableHeaderItem(Entered: boolean); virtual;
  93. procedure DocTableItem(Entered: boolean); virtual;
  94. procedure DocHorizontalRuler; virtual;
  95. end;
  96. implementation
  97. uses WUtils;
  98. function TTextFile.GetLine(Idx: sw_integer; var S: string): boolean;
  99. begin
  100. Abstract;
  101. GetLine:=false;
  102. end;
  103. constructor TMemoryTextFile.Init;
  104. begin
  105. inherited Init;
  106. New(Lines, Init(500,500));
  107. end;
  108. procedure TMemoryTextFile.AddLine(const S: string);
  109. begin
  110. Lines^.Insert(NewStr(S));
  111. end;
  112. function TMemoryTextFile.GetLine(Idx: sw_integer; var S: string): boolean;
  113. var OK: boolean;
  114. PS: PString;
  115. begin
  116. OK:=(Lines<>nil) and (Idx<Lines^.Count);
  117. if OK then
  118. begin
  119. PS:=Lines^.At(Idx);
  120. if PS=nil then S:='' else S:=PS^;
  121. end;
  122. GetLine:=OK;
  123. end;
  124. destructor TMemoryTextFile.Done;
  125. begin
  126. inherited Done;
  127. if Lines<>nil then Dispose(Lines, Done); Lines:=nil;
  128. end;
  129. constructor TDOSTextFile.Init(AFileName: string);
  130. (*{$ifdef TPUNIXLF}
  131. procedure readln(var t:text;var s:string);
  132. var
  133. c : char;
  134. i : longint;
  135. begin
  136. c:=#0;
  137. i:=0;
  138. while (not eof(t)) and (c<>#10) and (i<255) do
  139. begin
  140. read(t,c);
  141. if (i<255) and (c<>#10) then
  142. begin
  143. inc(i);
  144. s[i]:=c;
  145. end;
  146. end;
  147. if (i>0) and (s[i]=#13) then
  148. dec(i);
  149. s[0]:=chr(i);
  150. end;
  151. {$endif}*)
  152. var f: text;
  153. S: string;
  154. begin
  155. inherited Init;
  156. if AFileName='' then Fail;
  157. {$I-}
  158. Assign(f,AFileName);
  159. Reset(f);
  160. if IOResult<>0 then Fail;
  161. New(Lines, Init(500,2000));
  162. while (Eof(f)=false) and (IOResult=0) do
  163. begin
  164. readln(f,S); { this is the one in WUTILS.PAS }
  165. AddLine(S);
  166. end;
  167. Close(f);
  168. {$I+}
  169. end;
  170. constructor TSGMLParser.Init;
  171. begin
  172. inherited Init;
  173. end;
  174. function TSGMLParser.Process(HTMLFile: PTextFile): boolean;
  175. var S: string;
  176. OK,LineOK: boolean;
  177. begin
  178. if HTMLFile=nil then Exit;
  179. InTag:=false; InComment:=false; InString:=false; CurTag:='';
  180. Line:=0; OK:=true;
  181. repeat
  182. LineOK:=HTMLFile^.GetLine(Line,S);
  183. if LineOK then
  184. begin
  185. OK:=ProcessLine(S);
  186. Inc(Line);
  187. end;
  188. until (LineOK=false) or (OK=false);
  189. Process:=OK;
  190. end;
  191. function TSGMLParser.ProcessLine(LineText: string): boolean;
  192. var OK: boolean;
  193. C: char;
  194. NewInString: boolean;
  195. OldInComment: boolean;
  196. WasThereAnyText: boolean;
  197. Pos2: integer;
  198. Name,Entity: string;
  199. LiteralCode: boolean;
  200. LiteralStart,LiteralEnd,P: integer;
  201. const TabSize : integer = 8;
  202. Tab = #9;
  203. begin
  204. WasThereAnyText:=false;
  205. OK:=true; LinePos:=1;
  206. LiteralStart:=0; LiteralEnd:=0;
  207. repeat
  208. P:=Pos(TAB,LineText);
  209. if P>0 then
  210. LineText:=copy(LineText,1,P-1)+CharStr(' ',TabSize)+copy(LineText,P+1,255);
  211. until P=0;
  212. while (LinePos<=length(LineText)) and OK do
  213. begin
  214. LiteralCode:=false;
  215. NewInString:=InString; OldInComment:=InComment;
  216. C:=LineText[LinePos];
  217. LiteralCode:=(LiteralStart<=LinePos) and (LinePos<=LiteralEnd);
  218. if (LiteralCode=false) and (C='&') then
  219. begin
  220. LiteralStart:=0; LiteralEnd:=0;
  221. Name:=''; Pos2:=LinePos+1;
  222. while (Pos2<=length(LineText)) and (LineText[Pos2]<>';') do
  223. begin
  224. Name:=Name+LineText[Pos2];
  225. Inc(Pos2);
  226. end;
  227. Inc(Pos2);
  228. if DocDecodeNamedEntity(Name,Entity) then
  229. begin
  230. LineText:=copy(LineText,1,LinePos-1)+Entity+copy(LineText,Pos2,255);
  231. LiteralStart:=LinePos; LiteralEnd:=LiteralStart+length(Entity)-1;
  232. C:=LineText[LinePos];
  233. end;
  234. end;
  235. LiteralCode:=(LiteralStart<=LinePos) and (LinePos<=LiteralEnd);
  236. if (LiteralCode=false) and (C='"') and (InTag=true) and (InString=false) then
  237. NewInString:=true;
  238. if (LiteralCode=false) and (C='<') and (InTag=false) then
  239. InTag:=true;
  240. if InTag then CurTag:=CurTag+C else
  241. WasThereAnyText:=DocAddTextChar(C);
  242. if (LiteralCode=false) and InTag and (InString=false) and (CurTag='<!--') then
  243. InComment:=true;
  244. { A comment can be longer than 255 chars
  245. move the test to LineText string,
  246. This is why the Previous, Next and Up Tags where not working ... PM
  247. if (LiteralCode=false) and InTag and InComment and (InString=false) and (length(CurTag)>=3) and
  248. (copy(CurTag,length(CurTag)-2,3)='-->') then
  249. InComment:=false; }
  250. if (LiteralCode=false) and InTag and InComment and (InString=false) and (LinePos>=3) and
  251. (copy(LineText,LinePos-2,3)='-->') then
  252. InComment:=false;
  253. if (LiteralCode=false) and (C='"') and (InTag=true) and (InString=true) then
  254. NewInString:=false;
  255. if (LiteralCode=false) and (C='>') and (InTag=true) then
  256. begin
  257. InTag:=false;
  258. if OldInComment then
  259. DocProcessComment(CurTag)
  260. else
  261. DocProcessTag(CurTag);
  262. CurTag:='';
  263. end;
  264. InString:=NewInString;
  265. Inc(LinePos);
  266. end;
  267. { whtml does not depend on whelp,
  268. so I can not use hscLineBreak here. PM }
  269. if InTag and InString then
  270. CurTag:=CurTag+#0
  271. else if WasThereAnyText then DocSoftBreak;
  272. ProcessLine:=true;
  273. end;
  274. procedure TSGMLParser.DocSoftBreak;
  275. begin
  276. Abstract;
  277. end;
  278. function TSGMLParser.DocAddTextChar(C: char): boolean;
  279. begin
  280. Abstract;
  281. DocAddTextChar:=false;
  282. end;
  283. procedure TSGMLParser.DocAddText(S: string);
  284. var I: sw_integer;
  285. begin
  286. for I:=1 to length(S) do
  287. DocAddTextChar(S[I]);
  288. end;
  289. function TSGMLParser.DocDecodeNamedEntity(Name: string; var Entity: string): boolean;
  290. begin
  291. DocDecodeNamedEntity:=false;
  292. end;
  293. procedure TSGMLParser.DocProcessTag(Tag: string);
  294. begin
  295. Abstract;
  296. end;
  297. procedure TSGMLParser.DocProcessComment(Comment: string);
  298. begin
  299. Abstract;
  300. end;
  301. destructor TSGMLParser.Done;
  302. begin
  303. inherited Done;
  304. end;
  305. procedure THTMLParser.DocSoftBreak;
  306. begin
  307. end;
  308. function THTMLParser.DocAddTextChar(C: char): boolean;
  309. begin
  310. { Abstract }
  311. DocAddTextChar:=false;
  312. end;
  313. function THTMLParser.DocDecodeNamedEntity(Name: string; var E: string): boolean;
  314. var Found: boolean;
  315. Code: integer;
  316. CC: integer;
  317. begin
  318. Found:=true; Code:=-1;
  319. Name:=LowCaseStr(Name);
  320. if copy(Name,1,1)='#' then
  321. begin
  322. Val(copy(Name,2,255),Code,CC);
  323. if CC<>0 then Code:=-1;
  324. end;
  325. if (Name='lt') then E:='<' else { less-than sign }
  326. if (Name='gt') then E:='>' else { greater-than sign }
  327. if (Name='amp') then E:='&' else { ampersand }
  328. if (Name='quot') then E:='"' else { double quote sign }
  329. if (Code=160) or (Name='nbsp') then E:=#255 else { no-break space }
  330. if (Code=161) or (Name='iexcl') then E:='­' else { inverted excalamation mark }
  331. if (Code=162) or (Name='cent') then E:='›' else { cent sign }
  332. if (Code=163) or (Name='pound') then E:='œ' else { pound sterling sign }
  333. if (Code=164) or (Name='curren') then E:='$' else { general currency sign }
  334. if (Code=165) or (Name='yen') then E:='�' else { yen sign }
  335. if (Code=166) or (Name='brvbar') then E:='|' else { broken vertical bar }
  336. (* if (Code=167) or (Name='sect') then E:=#255 else { section sign }*)
  337. (* if (Code=168) or (Name='uml') then E:=#255 else { umlaut (dieresis) }*)
  338. if (Code=169) or (Name='copy') then E:='(C)' else { copyright sign }
  339. (* if (Code=170) or (Name='ordf') then E:=#255 else { ordinal indicator, feminine }*)
  340. if (Code=171) or (Name='laquo') then E:='"' else { angle quotation mark -left }
  341. if (Code=172) or (Name='not') then E:='!' else { not sign }
  342. if (Code=173) or (Name='shy') then E:='-' else { soft hypen }
  343. if (Code=174) or (Name='reg') then E:='(R)' else { registered sign }
  344. (* if (Code=175) or (Name='macr') then E:='?' else { macron }*)
  345. if (Code=176) or (Name='deg') then E:='ø' else { degree sign }
  346. if (Code=177) or (Name='plusmn') then E:='ñ' else { plus-or-minus sign }
  347. if (Code=178) or (Name='sup2') then E:='ý' else { superscript 2 }
  348. if (Code=179) or (Name='sup3') then E:='^3' else { superscript 3 }
  349. if (Code=180) or (Name='acute') then E:='''' else { acute accent }
  350. if (Code=181) or (Name='micro') then E:='æ' else { micro sign }
  351. (* if (Code=182) or (Name='para') then E:='?' else { paragraph sign }*)
  352. if (Code=183) or (Name='middot') then E:='ù' else { middle dot }
  353. (* if (Code=184) or (Name='cedil') then E:='?' else { cedilla }*)
  354. if (Code=185) or (Name='sup1') then E:='^1' else { superscript 1 }
  355. (* if (Code=186) or (Name='ordm') then E:='?' else { ordinal indicator, masculine }*)
  356. if (Code=187) or (Name='raquo') then E:='"' else { angle quoatation mark -right }
  357. if (Code=188) or (Name='frac14') then E:='¬' else { fraction one-quarter }
  358. if (Code=189) or (Name='frac12') then E:='«' else { fraction one-half }
  359. if (Code=190) or (Name='frac34') then E:='3/4' else { fraction three-quarters }
  360. if (Code=191) or (Name='iquest') then E:='¨' else { inverted question mark }
  361. if (Code=192) or (Name='Agrave') then E:='A' else { capital A, grave accent }
  362. if (Code=193) or (Name='Aacute') then E:='A' else { capital A, acute accent }
  363. if (Code=194) or (Name='Acirc') then E:='A' else { capital A, circumflex accent }
  364. if (Code=195) or (Name='Atilde') then E:='A' else { capital A, tilde accent }
  365. if (Code=196) or (Name='Auml') then E:='Ž' else { capital A, dieresis or umlaut }
  366. if (Code=197) or (Name='Aring') then E:='�' else { capital A, ring }
  367. if (Code=198) or (Name='AElig') then E:='AE' else { capital AE diphthong }
  368. (* if (Code=199) or (Name='Ccedil') then E:='?' else { capital C, cedilla }*)
  369. if (Code=200) or (Name='Egrave') then E:='�' else { capital E, grave accent }
  370. if (Code=201) or (Name='Eacute') then E:='�' else { capital E, acute accent }
  371. if (Code=202) or (Name='Ecirc') then E:='E' else { capital E, circumflex accent }
  372. if (Code=203) or (Name='Euml') then E:='E' else { capital E, dieresis or umlaut }
  373. if (Code=204) or (Name='Igrave') then E:='I' else { capital I, grave accent }
  374. if (Code=205) or (Name='Iacute') then E:='I' else { capital I, acute accent }
  375. if (Code=206) or (Name='Icirc') then E:='I' else { capital I, circumflex accent }
  376. if (Code=207) or (Name='Iuml') then E:='I' else { capital I, dieresis or umlaut }
  377. (* if (Code=208) or (Name='ETH') then E:='?' else { capital Eth, Icelandic }*)
  378. if (Code=209) or (Name='Ntidle') then E:='¥' else { capital N, tilde }
  379. if (Code=210) or (Name='Ograve') then E:='O' else { capital O, grave accent }
  380. if (Code=211) or (Name='Oacute') then E:='O' else { capital O, acute accent }
  381. if (Code=212) or (Name='Ocirc') then E:='O' else { capital O, circumflex accent }
  382. if (Code=213) or (Name='Otilde') then E:='O' else { capital O, tilde }
  383. if (Code=214) or (Name='Ouml') then E:='™' else { capital O, dieresis or umlaut }
  384. if (Code=215) or (Name='times') then E:='*' else { multiply sign }
  385. if (Code=216) or (Name='Oslash') then E:='O' else { capital O, slash }
  386. if (Code=217) or (Name='Ugrave') then E:='U' else { capital U, grave accent }
  387. if (Code=218) or (Name='Uacute') then E:='U' else { capital U, acute accent }
  388. if (Code=219) or (Name='Ucirc') then E:='U' else { capital U, circumflex accent }
  389. if (Code=220) or (Name='Uuml') then E:='š' else { capital U, dieresis or umlaut }
  390. if (Code=221) or (Name='Yacute') then E:='Y' else { capital Y, acute accent }
  391. (* if (Code=222) or (Name='THORN') then E:='?' else { capital THORN, Icelandic }*)
  392. if (Code=223) or (Name='szlig') then E:='á' else { small sharp S, German }
  393. if (Code=224) or (Name='agrave') then E:='…' else { small a, grave accent }
  394. if (Code=225) or (Name='aacute') then E:=' ' else { small a, acute accent }
  395. if (Code=226) or (Name='acirc') then E:='ƒ' else { small a, circumflex accent }
  396. if (Code=227) or (Name='atilde') then E:='ƒ' else { small a, tilde }
  397. if (Code=228) or (Name='auml') then E:='„' else { small a, dieresis or umlaut }
  398. if (Code=229) or (Name='aring') then E:='†' else { small a, ring }
  399. if (Code=230) or (Name='aelig') then E:='ae' else { small ae, diphthong }
  400. (* if (Code=231) or (Name='ccedil') then E:='?' else { small c, cedilla }*)
  401. if (Code=232) or (Name='egrave') then E:='Š' else { small e, grave accent }
  402. if (Code=233) or (Name='eacute') then E:='‚' else { small e, acute accent }
  403. if (Code=234) or (Name='ecirc') then E:='ˆ' else { small e, circumflex accent }
  404. if (Code=235) or (Name='euml') then E:='‰' else { small e, dieresis or umlaut }
  405. if (Code=236) or (Name='igrave') then E:='�' else { small i, grave accent }
  406. if (Code=237) or (Name='iacute') then E:='¡' else { small i, acute accent }
  407. if (Code=238) or (Name='icirc') then E:='Œ' else { small i, circumflex accent }
  408. if (Code=239) or (Name='iuml') then E:='‹' else { small i, dieresis or umlaut }
  409. (* if (Code=240) or (Name='eth') then E:='?' else { small eth, Icelandic }*)
  410. if (Code=241) or (Name='ntilde') then E:='¤' else { small n, tilde }
  411. if (Code=242) or (Name='ograve') then E:='•' else { small o, grave accent }
  412. if (Code=243) or (Name='oacute') then E:='¢' else { small o, acute accent }
  413. if (Code=244) or (Name='ocirc') then E:='“' else { small o, circumflex accent }
  414. if (Code=245) or (Name='otilde') then E:='“' else { small o, tilde }
  415. if (Code=246) or (Name='ouml') then E:='”' else { small o, dieresis or umlaut }
  416. if (Code=247) or (Name='divide') then E:='/' else { divide sign }
  417. if (Code=248) or (Name='oslash') then E:='"' else { small o, slash }
  418. if (Code=249) or (Name='ugrave') then E:='—' else { small u, grave accent }
  419. if (Code=250) or (Name='uacute') then E:='£' else { small u, acute accent }
  420. if (Code=251) or (Name='ucirc') then E:='–' else { small u, circumflex accent }
  421. if (Code=252) or (Name='uuml') then E:='�' else { small u, dieresis or umlaut }
  422. if (Code=253) or (Name='yacute') then E:='y' else { small y, acute accent }
  423. (* if (Code=254) or (Name='thorn') then E:='?' else { small thorn, Icelandic }*)
  424. if (Code=255) or (Name='yuml') then E:='y' else { small y, dieresis or umlaut }
  425. if (Code=8217) then E:='''' else { acute accent as generated by TeXH }
  426. Found:=false;
  427. DocDecodeNamedEntity:=Found;
  428. end;
  429. procedure THTMLParser.DocProcessTag(Tag: string);
  430. var UTagName,ETagName: string[30];
  431. P: byte;
  432. NotEndTag: boolean;
  433. begin
  434. if copy(Tag,1,1)='<' then Delete(Tag,1,1);
  435. if copy(Tag,length(Tag),1)='>' then Delete(Tag,length(Tag),1);
  436. Tag:=Trim(Tag);
  437. P:=Pos(' ',Tag); if P=0 then P:=length(Tag)+1;
  438. TagName:=copy(Tag,1,P-1); TagParams:=copy(Tag,P+1,255);
  439. UTagName:=UpcaseStr(TagName);
  440. NotEndTag:=copy(TagName,1,1)<>'/';
  441. if NotEndTag then ETagName:=UTagName else ETagName:=copy(UTagName,2,255);
  442. if (UTagName='!DOCTYPE') then DocTYPE else
  443. { Section tags }
  444. if (ETagName='HTML') then DocHTML(NotEndTag) else
  445. if (ETagName='HEAD') then DocHEAD(NotEndTag) else
  446. if (ETagName='TITLE') then DocTITLE(NotEndTag) else
  447. if (ETagName='BODY') then DocBODY(NotEndTag) else
  448. { Anchor tags }
  449. if (ETagName='A') then DocAnchor(NotEndTag) else
  450. { Direct formatting directives }
  451. if (ETagName='H1') then DocHeading(1,NotEndTag) else
  452. if (ETagName='H2') then DocHeading(2,NotEndTag) else
  453. if (ETagName='H3') then DocHeading(3,NotEndTag) else
  454. if (ETagName='H4') then DocHeading(4,NotEndTag) else
  455. if (ETagName='H5') then DocHeading(5,NotEndTag) else
  456. if (ETagName='H6') then DocHeading(6,NotEndTag) else
  457. if (ETagName='P') then DocParagraph(NotEndTag) else
  458. if (ETagName='BR') then DocBreak else
  459. if (ETagName='B') then DocBold(NotEndTag) else
  460. if (ETagName='CITE') then DocCite(NotEndTag) else
  461. if (ETagName='CODE') then DocCode(NotEndTag) else
  462. if (ETagName='EM') then DocEmphasized(NotEndTag) else
  463. if (ETagName='I') then DocItalic(NotEndTag) else
  464. if (ETagName='KBD') then DocKbd(NotEndTag) else
  465. if (ETagName='PRE') then DocPreformatted(NotEndTag) else
  466. if (ETagName='SAMP') then DocSample(NotEndTag) else
  467. if (ETagName='STRONG') then DocStrong(NotEndTag) else
  468. if (ETagName='TT') then DocTeleType(NotEndTag) else
  469. if (ETagName='VAR') then DocVariable(NotEndTag) else
  470. { Unordered & ordered lists }
  471. if (ETagName='UL') then DocList(NotEndTag) else
  472. if (ETagName='OL') then DocOrderedList(NotEndTag) else
  473. if (UTagName='LI') then DocListItem else
  474. { Definition list }
  475. if (ETagName='DL') then DocDefList(NotEndTag) else
  476. if (UTagName='DT') then DocDefTerm else
  477. if (UTagName='DD') then DocDefExp else
  478. { Table }
  479. if (ETagName='TABLE') then DocTable(NotEndTag) else
  480. if (ETagName='TR') then DocTableRow(NotEndTag) else
  481. if (ETagName='TH') then DocTableHeaderItem(NotEndTag) else
  482. if (ETagName='TD') then DocTableItem(NotEndTag) else
  483. { Misc. tags }
  484. if (UTagName='META') then DocMETA else
  485. if (UTagName='IMG') then DocImage else
  486. if (UTagName='HR') then DocHorizontalRuler else
  487. DocUnknownTag;
  488. end;
  489. function THTMLParser.DocGetTagParam(Name: string; var Value: string): boolean;
  490. var Found: boolean;
  491. S: string;
  492. ParamName,ParamValue: string;
  493. InStr: boolean;
  494. I: sw_integer;
  495. begin
  496. Found:=false; Name:=UpcaseStr(Name);
  497. S:=TagParams;
  498. repeat
  499. InStr:=false;
  500. ParamName:=''; ParamValue:='';
  501. S:=Trim(S); I:=1;
  502. while (I<=length(S)) and (S[I]<>'=') do
  503. begin
  504. ParamName:=ParamName+S[I];
  505. Inc(I);
  506. end;
  507. ParamName:=Trim(ParamName);
  508. if S[I]='=' then
  509. begin
  510. Inc(I); InStr:=false;
  511. while (I<=length(S)) and (S[I]=' ') do
  512. Inc(I);
  513. if (I<=length(S)) and (S[I]='"') then
  514. begin
  515. InStr:=true;
  516. Inc(I);
  517. end;
  518. while (I<=length(S)) and ((InStr=true) or (S[I]<>' ')) do
  519. begin
  520. if S[I]='"' then
  521. begin
  522. InStr:=not InStr;
  523. if InStr=false then Break;
  524. end
  525. else
  526. ParamValue:=ParamValue+S[I];
  527. Inc(I);
  528. end;
  529. end;
  530. Found:=(Name=UpcaseStr(ParamName));
  531. if Found then Value:=ParamValue;
  532. Delete(S,1,I);
  533. until Found or (S='');
  534. DocGetTagParam:=Found;
  535. end;
  536. procedure THTMLParser.DocProcessComment(Comment: string);
  537. begin
  538. end;
  539. procedure THTMLParser.DocUnknownTag;
  540. begin
  541. end;
  542. procedure THTMLParser.DocTYPE;
  543. begin
  544. end;
  545. procedure THTMLParser.DocHTML(Entered: boolean);
  546. begin
  547. end;
  548. procedure THTMLParser.DocHEAD(Entered: boolean);
  549. begin
  550. end;
  551. procedure THTMLParser.DocMETA;
  552. begin
  553. end;
  554. procedure THTMLParser.DocTITLE(Entered: boolean);
  555. begin
  556. end;
  557. procedure THTMLParser.DocBODY(Entered: boolean);
  558. begin
  559. end;
  560. procedure THTMLParser.DocAnchor(Entered: boolean);
  561. begin
  562. end;
  563. procedure THTMLParser.DocHeading(Level: integer; Entered: boolean);
  564. begin
  565. end;
  566. procedure THTMLParser.DocParagraph(Entered: boolean);
  567. begin
  568. end;
  569. procedure THTMLParser.DocBreak;
  570. begin
  571. end;
  572. procedure THTMLParser.DocImage;
  573. begin
  574. end;
  575. procedure THTMLParser.DocBold(Entered: boolean);
  576. begin
  577. end;
  578. procedure THTMLParser.DocCite(Entered: boolean);
  579. begin
  580. end;
  581. procedure THTMLParser.DocCode(Entered: boolean);
  582. begin
  583. end;
  584. procedure THTMLParser.DocEmphasized(Entered: boolean);
  585. begin
  586. end;
  587. procedure THTMLParser.DocItalic(Entered: boolean);
  588. begin
  589. end;
  590. procedure THTMLParser.DocKbd(Entered: boolean);
  591. begin
  592. end;
  593. procedure THTMLParser.DocPreformatted(Entered: boolean);
  594. begin
  595. end;
  596. procedure THTMLParser.DocSample(Entered: boolean);
  597. begin
  598. end;
  599. procedure THTMLParser.DocStrong(Entered: boolean);
  600. begin
  601. end;
  602. procedure THTMLParser.DocTeleType(Entered: boolean);
  603. begin
  604. end;
  605. procedure THTMLParser.DocVariable(Entered: boolean);
  606. begin
  607. end;
  608. procedure THTMLParser.DocList(Entered: boolean);
  609. begin
  610. end;
  611. procedure THTMLParser.DocOrderedList(Entered: boolean);
  612. begin
  613. end;
  614. procedure THTMLParser.DocListItem;
  615. begin
  616. end;
  617. procedure THTMLParser.DocDefList(Entered: boolean);
  618. begin
  619. end;
  620. procedure THTMLParser.DocDefTerm;
  621. begin
  622. end;
  623. procedure THTMLParser.DocDefExp;
  624. begin
  625. end;
  626. procedure THTMLParser.DocTable(Entered: boolean);
  627. begin
  628. end;
  629. procedure THTMLParser.DocTableRow(Entered: boolean);
  630. begin
  631. end;
  632. procedure THTMLParser.DocTableHeaderItem(Entered: boolean);
  633. begin
  634. end;
  635. procedure THTMLParser.DocTableItem(Entered: boolean);
  636. begin
  637. end;
  638. procedure THTMLParser.DocHorizontalRuler;
  639. begin
  640. end;
  641. END.
  642. {
  643. $Log$
  644. Revision 1.5 2003-03-27 14:37:24 pierre
  645. * try to enhance dispaly of new html docs
  646. Revision 1.4 2002/09/07 15:40:49 peter
  647. * old logs removed and tabs fixed
  648. Revision 1.3 2002/03/25 14:42:23 pierre
  649. * also call DocTableXXX at end tag
  650. }